forked from openimsdk/open-im-server
/
conversation_notification.go
83 lines (78 loc) · 3.02 KB
/
conversation_notification.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
77
78
79
80
81
82
83
package msg
import (
"github.com/erbaner/be/pkg/common/config"
"github.com/erbaner/be/pkg/common/constant"
"github.com/erbaner/be/pkg/common/log"
open_im_sdk "github.com/erbaner/be/pkg/proto/sdk_ws"
"github.com/erbaner/be/pkg/utils"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
)
func SetConversationNotification(operationID, sendID, recvID string, contentType int, m proto.Message, tips open_im_sdk.TipsComm) {
log.NewInfo(operationID, "args: ", sendID, recvID, contentType, m.String(), tips.String())
var err error
tips.Detail, err = proto.Marshal(m)
if err != nil {
log.NewError(operationID, "Marshal failed ", err.Error(), m.String())
return
}
marshaler := jsonpb.Marshaler{
OrigName: true,
EnumsAsInts: false,
EmitDefaults: false,
}
tips.JsonDetail, _ = marshaler.MarshalToString(m)
var n NotificationMsg
n.SendID = sendID
n.RecvID = recvID
n.ContentType = int32(contentType)
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = operationID
n.Content, err = proto.Marshal(&tips)
if err != nil {
log.Error(operationID, utils.GetSelfFuncName(), "Marshal failed ", err.Error(), tips.String())
return
}
Notification(&n)
}
// SetPrivate调用
func ConversationSetPrivateNotification(operationID, sendID, recvID string, isPrivateChat bool) {
log.NewInfo(operationID, utils.GetSelfFuncName())
conversationSetPrivateTips := &open_im_sdk.ConversationSetPrivateTips{
RecvID: recvID,
SendID: sendID,
IsPrivate: isPrivateChat,
}
var tips open_im_sdk.TipsComm
var tipsMsg string
if isPrivateChat == true {
tipsMsg = config.Config.Notification.ConversationSetPrivate.DefaultTips.OpenTips
} else {
tipsMsg = config.Config.Notification.ConversationSetPrivate.DefaultTips.CloseTips
}
tips.DefaultTips = tipsMsg
SetConversationNotification(operationID, sendID, recvID, constant.ConversationPrivateChatNotification, conversationSetPrivateTips, tips)
}
// 会话改变
func ConversationChangeNotification(operationID, userID string) {
log.NewInfo(operationID, utils.GetSelfFuncName())
ConversationChangedTips := &open_im_sdk.ConversationUpdateTips{
UserID: userID,
}
var tips open_im_sdk.TipsComm
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
SetConversationNotification(operationID, userID, userID, constant.ConversationOptChangeNotification, ConversationChangedTips, tips)
}
// 会话未读数同步
func ConversationUnreadChangeNotification(operationID, userID, conversationID string, updateUnreadCountTime int64) {
log.NewInfo(operationID, utils.GetSelfFuncName())
ConversationChangedTips := &open_im_sdk.ConversationUpdateTips{
UserID: userID,
ConversationIDList: []string{conversationID},
UpdateUnreadCountTime: updateUnreadCountTime,
}
var tips open_im_sdk.TipsComm
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
SetConversationNotification(operationID, userID, userID, constant.ConversationUnreadNotification, ConversationChangedTips, tips)
}