forked from eatmoreapple/openwechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_check.go
44 lines (36 loc) · 934 Bytes
/
sync_check.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
package openwechat
import (
"errors"
"strconv"
)
type Selector string
const (
SelectorNormal Selector = "0" // 正常
SelectorNewMsg Selector = "2" // 有新消息
SelectorModContact Selector = "4" // 联系人信息变更
SelectorAddOrDelContact Selector = "6" // 添加或删除联系人
SelectorModChatRoom Selector = "7" // 进入或退出聊天室
)
type SyncCheckResponse struct {
RetCode string
Selector Selector
}
func (s SyncCheckResponse) Success() bool {
return s.RetCode == "0"
}
func (s SyncCheckResponse) NorMal() bool {
return s.Success() && s.Selector == SelectorNormal
}
func (s SyncCheckResponse) HasNewMessage() bool {
return s.Success() && s.Selector == SelectorNewMsg
}
func (s SyncCheckResponse) Err() error {
if s.Success() {
return nil
}
i, err := strconv.Atoi(s.RetCode)
if err != nil {
return errors.New("sync check unknown error")
}
return Ret(i)
}