You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.5 KiB
79 lines
2.5 KiB
package notification
|
|
|
|
import (
|
|
"Open_IM/pkg/common/config"
|
|
"Open_IM/pkg/common/constant"
|
|
sdkws "Open_IM/pkg/proto/sdkws"
|
|
"context"
|
|
"github.com/golang/protobuf/jsonpb"
|
|
"github.com/golang/protobuf/proto"
|
|
)
|
|
|
|
func (c *Check) SetConversationNotification(ctx context.Context, sendID, recvID string, contentType int, m proto.Message, tips sdkws.TipsComm) {
|
|
var err error
|
|
tips.Detail, err = proto.Marshal(m)
|
|
if err != nil {
|
|
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.Content, err = proto.Marshal(&tips)
|
|
if err != nil {
|
|
return
|
|
}
|
|
c.Notification(ctx, &n)
|
|
}
|
|
|
|
// SetPrivate调用
|
|
func (c *Check) ConversationSetPrivateNotification(ctx context.Context, sendID, recvID string, isPrivateChat bool) {
|
|
|
|
conversationSetPrivateTips := &sdkws.ConversationSetPrivateTips{
|
|
RecvID: recvID,
|
|
SendID: sendID,
|
|
IsPrivate: isPrivateChat,
|
|
}
|
|
var tips sdkws.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
|
|
c.SetConversationNotification(ctx, sendID, recvID, constant.ConversationPrivateChatNotification, conversationSetPrivateTips, tips)
|
|
}
|
|
|
|
// 会话改变
|
|
func (c *Check) ConversationChangeNotification(ctx context.Context, userID string) {
|
|
|
|
ConversationChangedTips := &sdkws.ConversationUpdateTips{
|
|
UserID: userID,
|
|
}
|
|
var tips sdkws.TipsComm
|
|
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
|
|
c.SetConversationNotification(ctx, userID, userID, constant.ConversationOptChangeNotification, ConversationChangedTips, tips)
|
|
}
|
|
|
|
// 会话未读数同步
|
|
func (c *Check) ConversationUnreadChangeNotification(ctx context.Context, userID, conversationID string, updateUnreadCountTime int64) {
|
|
|
|
ConversationChangedTips := &sdkws.ConversationUpdateTips{
|
|
UserID: userID,
|
|
ConversationIDList: []string{conversationID},
|
|
UpdateUnreadCountTime: updateUnreadCountTime,
|
|
}
|
|
var tips sdkws.TipsComm
|
|
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
|
|
c.SetConversationNotification(ctx, userID, userID, constant.ConversationUnreadNotification, ConversationChangedTips, tips)
|
|
}
|