-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
update.go
56 lines (46 loc) · 915 Bytes
/
update.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
package updates
import (
"context"
"github.com/gotd/td/tg"
)
type update struct {
Value interface{}
State int
Count int
Ents entities
Ctx context.Context
}
func (u update) start() int { return u.State - u.Count }
func (u update) end() int { return u.State }
// Entities contains update entities.
type entities struct {
Users []tg.UserClass
Chats []tg.ChatClass
}
// Merge merges entities.
func (e *entities) Merge(from entities) {
for _, candidate := range from.Users {
merge := true
for _, exist := range e.Users {
if exist.GetID() == candidate.GetID() {
merge = false
break
}
}
if merge {
e.Users = append(e.Users, candidate)
}
}
for _, candidate := range from.Chats {
merge := true
for _, exist := range e.Chats {
if exist.GetID() == candidate.GetID() {
merge = false
break
}
}
if merge {
e.Chats = append(e.Chats, candidate)
}
}
}