forked from openimsdk/openim-sdk-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.go
70 lines (64 loc) · 2.3 KB
/
sync.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
package super_group
import (
"github.com/erbaner/be-core/pkg/common"
"github.com/erbaner/be-core/pkg/log"
"github.com/erbaner/be-core/pkg/utils"
)
//func (s *SuperGroup) SyncJoinedGroupList(operationID string) {
// groupList, err := s.getJoinedGroupListFromSvr(operationID)
// log.Debug(operationID, "getJoinedGroupListFromSvr result ", groupList)
// localGroupList := common.TransferToLocalGroupInfo(groupList)
// if err == nil {
// s.db.DeleteAllSuperGroup()
// for _, v := range localGroupList {
// err = s.db.InsertSuperGroup(v)
// if err != nil {
// log.Error(operationID, "InsertSuperGroup failed ", err.Error(), v)
// } else {
// log.Debug(operationID, "InsertSuperGroup ok ", v)
// }
// }
// }
//}
func (s *SuperGroup) SyncJoinedGroupList(operationID string) {
log.NewInfo(operationID, utils.GetSelfFuncName(), "args: ")
svrList, err := s.getJoinedGroupListFromSvr(operationID)
log.Info(operationID, "getJoinedGroupListFromSvr", svrList, s.loginUserID)
if err != nil {
log.NewError(operationID, "getJoinedGroupListFromSvr failed ", err.Error())
return
}
onServer := common.TransferToLocalGroupInfo(svrList)
onLocal, err := s.db.GetJoinedSuperGroupList()
if err != nil {
log.NewError(operationID, "GetJoinedSuperGroupList failed ", err.Error())
return
}
log.NewInfo(operationID, " onLocal ", onLocal, s.loginUserID)
aInBNot, bInANot, sameA, sameB := common.CheckGroupInfoDiff(onServer, onLocal)
log.Info(operationID, "diff ", aInBNot, bInANot, sameA, sameB, s.loginUserID)
for _, index := range aInBNot {
log.Info(operationID, "InsertSuperGroup ", *onServer[index])
err := s.db.InsertSuperGroup(onServer[index])
if err != nil {
log.NewError(operationID, "InsertGroup failed ", err.Error(), *onServer[index])
continue
}
}
for _, index := range sameA {
log.Info(operationID, "UpdateSuperGroup ", *onServer[index])
err := s.db.UpdateSuperGroup(onServer[index])
if err != nil {
log.NewError(operationID, "UpdateGroup failed ", err.Error(), onServer[index])
continue
}
}
for _, index := range bInANot {
log.Info(operationID, "DeleteSuperGroup: ", onLocal[index].GroupID, s.loginUserID)
err := s.db.DeleteSuperGroup(onLocal[index].GroupID)
if err != nil {
log.NewError(operationID, "DeleteSuperGroup failed ", err.Error(), onLocal[index].GroupID)
continue
}
}
}