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.
Open-IM-Server/internal/common/notification/conversation.go

86 lines
2.9 KiB

2 years ago
package notification
3 years ago
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/tracelog"
2 years ago
sdkws "Open_IM/pkg/proto/sdkws"
3 years ago
"Open_IM/pkg/utils"
"context"
3 years ago
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
)
func (c *Check) SetConversationNotification(operationID, sendID, recvID string, contentType int, m proto.Message, tips sdkws.TipsComm) {
log.NewInfo(operationID, "args: ", sendID, recvID, contentType, m.String(), tips.String())
3 years ago
var err error
tips.Detail, err = proto.Marshal(m)
if err != nil {
log.NewError(operationID, "Marshal failed ", err.Error(), m.String())
3 years ago
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)
3 years ago
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
}
c.Notification(&n)
3 years ago
}
// SetPrivate调用
func (c *Check) ConversationSetPrivateNotification(ctx context.Context, sendID, recvID string, isPrivateChat bool) {
2 years ago
conversationSetPrivateTips := &sdkws.ConversationSetPrivateTips{
RecvID: recvID,
SendID: sendID,
IsPrivate: isPrivateChat,
}
2 years ago
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(tracelog.GetOperationID(ctx), sendID, recvID, constant.ConversationPrivateChatNotification, conversationSetPrivateTips, tips)
}
// 会话改变
func (c *Check) ConversationChangeNotification(ctx context.Context, userID string) {
2 years ago
ConversationChangedTips := &sdkws.ConversationUpdateTips{
3 years ago
UserID: userID,
}
2 years ago
var tips sdkws.TipsComm
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
c.SetConversationNotification(tracelog.GetOperationID(ctx), userID, userID, constant.ConversationOptChangeNotification, ConversationChangedTips, tips)
3 years ago
}
2 years ago
2 years ago
// 会话未读数同步
func (c *Check) ConversationUnreadChangeNotification(context context.Context, userID, conversationID string, updateUnreadCountTime int64) {
2 years ago
ConversationChangedTips := &sdkws.ConversationUpdateTips{
UserID: userID,
ConversationIDList: []string{conversationID},
UpdateUnreadCountTime: updateUnreadCountTime,
2 years ago
}
2 years ago
var tips sdkws.TipsComm
2 years ago
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
c.SetConversationNotification(tracelog.GetOperationID(ctx), userID, userID, constant.ConversationUnreadNotification, ConversationChangedTips, tips)
2 years ago
}