-
Notifications
You must be signed in to change notification settings - Fork 10
/
presence_members.go
59 lines (44 loc) · 1.08 KB
/
presence_members.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
package pusher
import (
"encoding/json"
)
type rawMembers struct {
Presence rawPresence `json:"presence"`
}
type rawPresence struct {
Count int `json:"count"`
Ids []string `json:"ids"`
Hash map[string]map[string]string `json:"hash"`
}
type Members struct {
Count int
Members []Member
Me Member
}
type Member struct {
UserId string `json:"user_id"`
UserInfo map[string]string `json:"user_info,omitempty"`
}
func unmarshalledMember(data string) (member *Member, err error) {
err = json.Unmarshal([]byte(data), &member)
return
}
func unmarshalledMembers(data string, myID string) (members *Members, err error) {
var rawData rawMembers
err = json.Unmarshal([]byte(data), &rawData)
var _members []Member
var me Member
for _, id := range rawData.Presence.Ids {
_member := Member{UserId: id, UserInfo: rawData.Presence.Hash[id]}
_members = append(_members, _member)
if id == myID {
me = _member
}
}
members = &Members{
Count: rawData.Presence.Count,
Members: _members,
Me: me,
}
return
}