-
Notifications
You must be signed in to change notification settings - Fork 165
/
news.go
76 lines (65 loc) · 1.79 KB
/
news.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package messages
import (
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/power"
)
type News struct {
*Message
}
func NewNews(items []*object.HashMap) *News {
m := &News{
NewMessage(&power.HashMap{"items": items}),
}
m.Type = "news"
m.OverrideToXmlArray()
m.OverridePropertiesToArray()
return m
}
func (msg *News) OverridePropertiesToArray() {
msg.PropertiesToArray = func(data *object.HashMap, aliases *object.HashMap) (*object.HashMap, error) {
arrayItems := msg.Get("items", nil).([]*object.HashMap)
title := msg.Get("title", nil).(string)
description := msg.Get("description", nil).(string)
picUrl := msg.Get("picUrl", nil).(string)
url := msg.Get("url", nil).(string)
arrayMapItems := []*object.HashMap{}
for _, item := range arrayItems {
arrayMapItems = append(arrayMapItems, item)
}
return &object.HashMap{
"articles": arrayMapItems,
"title": title,
"description": description,
"picUrl": picUrl,
"url": url,
}, nil
}
}
// Override ToXmlArray
func (msg *News) OverrideToXmlArray() {
msg.ToXmlArray = func() *object.HashMap {
items := []*object.HashMap{}
getItem := msg.Get("items", nil)
title := msg.Get("title", nil).(string)
description := msg.Get("description", nil).(string)
picUrl := msg.Get("picUrl", nil).(string)
url := msg.Get("url", nil).(string)
if getItem != nil {
arrayItems := getItem.([]*object.HashMap)
for _, item := range arrayItems {
//newItems := NewNewsItem(item)
items = append(items, &object.HashMap{
"item": item,
})
}
}
return &object.HashMap{
"ArticleCount": len(items),
"Articles": items,
"Title": title,
"Description": description,
"PicUrl": picUrl,
"Url": url,
}
}
}