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.
88 lines
3.5 KiB
88 lines
3.5 KiB
2 years ago
|
package notification
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
2 years ago
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct"
|
||
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tracelog"
|
||
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
||
|
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||
2 years ago
|
)
|
||
|
|
||
2 years ago
|
func (c *Check) ExtendMessageUpdatedNotification(ctx context.Context, sendID string, sourceID string, sessionType int32,
|
||
2 years ago
|
req *msg.SetMessageReactionExtensionsReq, resp *msg.SetMessageReactionExtensionsResp, isHistory bool, isReactionFromCache bool) {
|
||
|
var m apistruct.ReactionMessageModifierNotification
|
||
|
m.SourceID = req.SourceID
|
||
2 years ago
|
m.OpUserID = tracelog.GetOpUserID(ctx)
|
||
2 years ago
|
m.SessionType = req.SessionType
|
||
|
keyMap := make(map[string]*sdkws.KeyValue)
|
||
|
for _, valueResp := range resp.Result {
|
||
|
if valueResp.ErrCode == 0 {
|
||
|
keyMap[valueResp.KeyValue.TypeKey] = valueResp.KeyValue
|
||
|
}
|
||
|
}
|
||
|
if len(keyMap) == 0 {
|
||
|
return
|
||
|
}
|
||
2 years ago
|
m.SuccessReactionExtensions = keyMap
|
||
2 years ago
|
m.ClientMsgID = req.ClientMsgID
|
||
|
m.IsReact = resp.IsReact
|
||
|
m.IsExternalExtensions = req.IsExternalExtensions
|
||
|
m.MsgFirstModifyTime = resp.MsgFirstModifyTime
|
||
2 years ago
|
c.messageReactionSender(ctx, sendID, sourceID, sessionType, constant.ReactionMessageModifier, utils.StructToJsonString(m), isHistory, isReactionFromCache)
|
||
2 years ago
|
}
|
||
2 years ago
|
func (c *Check) ExtendMessageDeleteNotification(ctx context.Context, sendID string, sourceID string, sessionType int32,
|
||
2 years ago
|
req *msg.DeleteMessagesReactionExtensionsReq, resp *msg.DeleteMessagesReactionExtensionsResp, isHistory bool, isReactionFromCache bool) {
|
||
2 years ago
|
var m apistruct.ReactionMessageDeleteNotification
|
||
|
m.SourceID = req.SourceID
|
||
|
m.OpUserID = req.OpUserID
|
||
|
m.SessionType = req.SessionType
|
||
|
keyMap := make(map[string]*sdkws.KeyValue)
|
||
|
for _, valueResp := range resp.Result {
|
||
|
if valueResp.ErrCode == 0 {
|
||
|
keyMap[valueResp.KeyValue.TypeKey] = valueResp.KeyValue
|
||
|
}
|
||
|
}
|
||
|
if len(keyMap) == 0 {
|
||
|
return
|
||
|
}
|
||
2 years ago
|
m.SuccessReactionExtensions = keyMap
|
||
2 years ago
|
m.ClientMsgID = req.ClientMsgID
|
||
|
m.MsgFirstModifyTime = req.MsgFirstModifyTime
|
||
|
|
||
2 years ago
|
c.messageReactionSender(ctx, sendID, sourceID, sessionType, constant.ReactionMessageDeleter, utils.StructToJsonString(m), isHistory, isReactionFromCache)
|
||
2 years ago
|
}
|
||
2 years ago
|
func (c *Check) messageReactionSender(ctx context.Context, sendID string, sourceID string, sessionType, contentType int32, content string, isHistory bool, isReactionFromCache bool) error {
|
||
2 years ago
|
options := make(map[string]bool, 5)
|
||
|
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false)
|
||
|
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
|
||
|
utils.SetSwitchFromOptions(options, constant.IsSenderConversationUpdate, false)
|
||
|
utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
|
||
|
utils.SetSwitchFromOptions(options, constant.IsReactionFromCache, isReactionFromCache)
|
||
|
if !isHistory {
|
||
|
utils.SetSwitchFromOptions(options, constant.IsHistory, false)
|
||
|
utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
|
||
|
}
|
||
|
pbData := msg.SendMsgReq{
|
||
|
MsgData: &sdkws.MsgData{
|
||
|
SendID: sendID,
|
||
|
ClientMsgID: utils.GetMsgID(sendID),
|
||
|
SessionType: sessionType,
|
||
|
MsgFrom: constant.SysMsgType,
|
||
|
ContentType: contentType,
|
||
|
Content: []byte(content),
|
||
2 years ago
|
CreateTime: utils.GetCurrentTimestampByMill(),
|
||
|
Options: options,
|
||
2 years ago
|
},
|
||
|
}
|
||
|
switch sessionType {
|
||
|
case constant.SingleChatType, constant.NotificationChatType:
|
||
|
pbData.MsgData.RecvID = sourceID
|
||
|
case constant.GroupChatType, constant.SuperGroupChatType:
|
||
|
pbData.MsgData.GroupID = sourceID
|
||
|
}
|
||
2 years ago
|
_, err := c.Msg.SendMsg(ctx, &pbData)
|
||
|
return err
|
||
2 years ago
|
}
|