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/pkg/rpcclient/notification/extend_msg.go

104 lines
4.1 KiB

2 years ago
package notification
import (
"context"
2 years ago
"encoding/json"
2 years ago
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
2 years ago
"google.golang.org/protobuf/proto"
)
2 years ago
type ExtendMsgNotificationSender struct {
1 year ago
*rpcclient.MessageRpcClient
2 years ago
}
func NewExtendMsgNotificationSender(client discoveryregistry.SvcDiscoveryRegistry) *ExtendMsgNotificationSender {
1 year ago
return &ExtendMsgNotificationSender{}
2 years ago
}
func (e *ExtendMsgNotificationSender) ExtendMessageUpdatedNotification(ctx context.Context, sendID string, conversationID string, sessionType int32,
req *msg.SetMessageReactionExtensionsReq, resp *msg.SetMessageReactionExtensionsResp, isHistory bool, isReactionFromCache bool) {
2 years ago
var content sdkws.ReactionMessageModifierNotification
content.ConversationID = req.ConversationID
2 years ago
content.OpUserID = mcontext.GetOpUserID(ctx)
content.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
content.SuccessReactionExtensions = keyMap
content.ClientMsgID = req.ClientMsgID
content.IsReact = resp.IsReact
content.IsExternalExtensions = req.IsExternalExtensions
content.MsgFirstModifyTime = resp.MsgFirstModifyTime
e.messageReactionSender(ctx, sendID, conversationID, sessionType, constant.ReactionMessageModifier, &content, isHistory, isReactionFromCache)
}
func (e *ExtendMsgNotificationSender) ExtendMessageDeleteNotification(ctx context.Context, sendID string, conversationID string, sessionType int32,
2 years ago
req *msg.DeleteMessagesReactionExtensionsReq, resp *msg.DeleteMessagesReactionExtensionsResp, isHistory bool, isReactionFromCache bool) {
2 years ago
var content sdkws.ReactionMessageDeleteNotification
content.ConversationID = req.ConversationID
2 years ago
content.OpUserID = req.OpUserID
content.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
content.SuccessReactionExtensions = keyMap
content.ClientMsgID = req.ClientMsgID
content.MsgFirstModifyTime = req.MsgFirstModifyTime
e.messageReactionSender(ctx, sendID, conversationID, sessionType, constant.ReactionMessageDeleter, &content, isHistory, isReactionFromCache)
}
func (e *ExtendMsgNotificationSender) messageReactionSender(ctx context.Context, sendID string, conversationID string, sessionType, contentType int32, m proto.Message, isHistory bool, isReactionFromCache bool) error {
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)
}
2 years ago
bytes, err := json.Marshal(m)
if err != nil {
return errs.ErrData.Wrap(err.Error())
}
pbData := msg.SendMsgReq{
MsgData: &sdkws.MsgData{
SendID: sendID,
ClientMsgID: utils.GetMsgID(sendID),
SessionType: sessionType,
MsgFrom: constant.SysMsgType,
ContentType: contentType,
2 years ago
Content: bytes,
CreateTime: utils.GetCurrentTimestampByMill(),
Options: options,
},
}
switch sessionType {
case constant.SingleChatType, constant.NotificationChatType:
pbData.MsgData.RecvID = conversationID
case constant.GroupChatType, constant.SuperGroupChatType:
pbData.MsgData.GroupID = conversationID
}
2 years ago
_, err = e.SendMsg(ctx, &pbData)
2 years ago
return err
}