diff --git a/internal/api/msg.go b/internal/api/msg.go index 2bbae9765..726889d56 100644 --- a/internal/api/msg.go +++ b/internal/api/msg.go @@ -170,12 +170,7 @@ func (m *MessageApi) getSendMsgReq(c *gin.Context, req apistruct.SendMsg) (sendM log.ZDebug(c, "getSendMsgReq", "req", req.Content) switch req.ContentType { case constant.Text: - text, ok := req.Content["text"].(string) - if !ok { - return nil, errs.ErrArgs.WithDetail("text is not string") - } - data = apistruct.TextContentElem{Content: text} - log.ZDebug(c, "getSendMsgReq", "data", data) + data = apistruct.TextElem{} case constant.Picture: data = apistruct.PictureElem{} case constant.Voice: diff --git a/internal/push/push_to_client.go b/internal/push/push_to_client.go index 4161e04da..690cd37f8 100644 --- a/internal/push/push_to_client.go +++ b/internal/push/push_to_client.go @@ -285,7 +285,7 @@ func (p *Pusher) offlinePushMsg(ctx context.Context, conversationID string, msg } func (p *Pusher) GetOfflinePushOpts(msg *sdkws.MsgData) (opts *offlinepush.Opts, err error) { - opts = &offlinepush.Opts{} + opts = &offlinepush.Opts{Signal: &offlinepush.Signal{}} // if msg.ContentType > constant.SignalingNotificationBegin && msg.ContentType < constant.SignalingNotificationEnd { // req := &sdkws.SignalReq{} // if err := proto.Unmarshal(msg.Content, req); err != nil { diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index d1f4a7fc6..093bddc35 100644 --- a/internal/rpc/conversation/conversaion.go +++ b/internal/rpc/conversation/conversaion.go @@ -133,42 +133,67 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver // } // } } - cs, err := c.conversationDatabase.FindConversations(ctx, req.Conversation.UserID, []string{req.Conversation.ConversationID}) - if err != nil { - return nil, err - } - if len(cs) == 0 { - return nil, errs.ErrRecordNotFound.Wrap("conversation not found") + var unequal int + var conv tablerelation.ConversationModel + if len(req.UserIDs) == 1 { + cs, err := c.conversationDatabase.FindConversations(ctx, req.UserIDs[0], []string{req.Conversation.ConversationID}) + if err != nil { + return nil, err + } + if len(cs) == 0 { + return nil, errs.ErrRecordNotFound.Wrap("conversation not found") + } + conv = *cs[0] } - conv := cs[0] var conversation tablerelation.ConversationModel conversation.ConversationID = req.Conversation.ConversationID conversation.ConversationType = req.Conversation.ConversationType conversation.UserID = req.Conversation.UserID conversation.GroupID = req.Conversation.GroupID m := make(map[string]interface{}) - if req.Conversation.RecvMsgOpt != nil && req.Conversation.RecvMsgOpt.Value != conv.RecvMsgOpt { + if req.Conversation.RecvMsgOpt != nil { m["recv_msg_opt"] = req.Conversation.RecvMsgOpt.Value + if req.Conversation.RecvMsgOpt.Value != conv.RecvMsgOpt { + unequal++ + } } - if req.Conversation.AttachedInfo != nil && req.Conversation.AttachedInfo.Value != conv.AttachedInfo { + if req.Conversation.AttachedInfo != nil { m["attached_info"] = req.Conversation.AttachedInfo.Value + if req.Conversation.AttachedInfo.Value != conv.AttachedInfo { + unequal++ + } } - if req.Conversation.Ex != nil && req.Conversation.Ex.Value != conv.Ex { + if req.Conversation.Ex != nil { m["ex"] = req.Conversation.Ex.Value + if req.Conversation.Ex.Value != conv.Ex { + unequal++ + } } - if req.Conversation.IsPinned != nil && req.Conversation.IsPinned.Value != conv.IsPinned { + if req.Conversation.IsPinned != nil { m["is_pinned"] = req.Conversation.IsPinned.Value + if req.Conversation.IsPinned.Value != conv.IsPinned { + unequal++ + } } - if req.Conversation.GroupAtType != nil && req.Conversation.GroupAtType.Value != conv.GroupAtType { + if req.Conversation.GroupAtType != nil { m["group_at_type"] = req.Conversation.GroupAtType.Value + if req.Conversation.GroupAtType.Value != conv.GroupAtType { + unequal++ + } } - if req.Conversation.MsgDestructTime != nil && req.Conversation.MsgDestructTime.Value != conv.MsgDestructTime { + if req.Conversation.MsgDestructTime != nil { m["msg_destruct_time"] = req.Conversation.MsgDestructTime.Value + if req.Conversation.MsgDestructTime.Value != conv.MsgDestructTime { + unequal++ + } } - if req.Conversation.IsMsgDestruct != nil && req.Conversation.IsMsgDestruct.Value != conv.IsMsgDestruct { + if req.Conversation.IsMsgDestruct != nil { m["is_msg_destruct"] = req.Conversation.IsMsgDestruct.Value + if req.Conversation.IsMsgDestruct.Value != conv.IsMsgDestruct { + unequal++ + } } - if req.Conversation.IsPrivateChat != nil && req.Conversation.ConversationType != constant.SuperGroupChatType && len(m) > 0 { + if req.Conversation.IsPrivateChat != nil && req.Conversation.ConversationType != constant.SuperGroupChatType { var conversations []*tablerelation.ConversationModel for _, ownerUserID := range req.UserIDs { conversation2 := conversation @@ -179,17 +204,22 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver if err := c.conversationDatabase.SyncPeerUserPrivateConversationTx(ctx, conversations); err != nil { return nil, err } - for _, userID := range req.UserIDs { - c.conversationNotificationSender.ConversationSetPrivateNotification(ctx, userID, req.Conversation.UserID, req.Conversation.IsPrivateChat.Value, req.Conversation.ConversationID) + if len(req.UserIDs) != 1 || unequal > 0 { + for _, userID := range req.UserIDs { + c.conversationNotificationSender.ConversationSetPrivateNotification(ctx, userID, req.Conversation.UserID, req.Conversation.IsPrivateChat.Value, req.Conversation.ConversationID) + } } } - if req.Conversation.BurnDuration != nil && req.Conversation.BurnDuration.Value != conv.BurnDuration { + if req.Conversation.BurnDuration != nil { m["burn_duration"] = req.Conversation.BurnDuration.Value - } - if len(m) > 0 { - if err := c.conversationDatabase.SetUsersConversationFiledTx(ctx, req.UserIDs, &conversation, m); err != nil { - return nil, err + if req.Conversation.BurnDuration.Value != conv.BurnDuration { + unequal++ } + } + if err := c.conversationDatabase.SetUsersConversationFiledTx(ctx, req.UserIDs, &conversation, m); err != nil { + return nil, err + } + if len(req.UserIDs) != 1 || unequal > 0 { for _, v := range req.UserIDs { c.conversationNotificationSender.ConversationChangeNotification(ctx, v, []string{req.Conversation.ConversationID}) } diff --git a/internal/rpc/msg/verify.go b/internal/rpc/msg/verify.go index 7297dc83b..de85775d8 100644 --- a/internal/rpc/msg/verify.go +++ b/internal/rpc/msg/verify.go @@ -128,7 +128,9 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe func (m *msgServer) encapsulateMsgData(msg *sdkws.MsgData) { msg.ServerMsgID = GetMsgID(msg.SendID) - msg.SendTime = utils.GetCurrentTimestampByMill() + if msg.SendTime == 0 { + msg.SendTime = utils.GetCurrentTimestampByMill() + } switch msg.ContentType { case constant.Text: fallthrough diff --git a/pkg/apistruct/msg.go b/pkg/apistruct/msg.go index d31752f38..12cf253a0 100644 --- a/pkg/apistruct/msg.go +++ b/pkg/apistruct/msg.go @@ -72,11 +72,8 @@ type CustomElem struct { Description string `mapstructure:"description"` Extension string `mapstructure:"extension"` } -type TextElem struct { - Text string `mapstructure:"text" validate:"required"` -} -type TextContentElem struct { +type TextElem struct { Content string `json:"content" validate:"required"` } diff --git a/pkg/common/db/cache/user.go b/pkg/common/db/cache/user.go index 61b4df9d8..2db5e2190 100644 --- a/pkg/common/db/cache/user.go +++ b/pkg/common/db/cache/user.go @@ -244,7 +244,7 @@ func (u *UserCacheRedis) SetUserStatus(ctx context.Context, list []*user.OnlineS } if newPlatformIDs == nil { onlineStatus.Status = constant.Offline - onlineStatus.PlatformIDs = nil + onlineStatus.PlatformIDs = []int32{} newjsonData, err := json.Marshal(&onlineStatus) if err != nil { return errs.Wrap(err) diff --git a/pkg/rpcclient/msg.go b/pkg/rpcclient/msg.go index 09e198de4..54577b679 100644 --- a/pkg/rpcclient/msg.go +++ b/pkg/rpcclient/msg.go @@ -250,7 +250,11 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s } msg.CreateTime = utils.GetCurrentTimestampByMill() msg.ClientMsgID = utils.GetMsgID(sendID) - options := config.GetOptionsByNotification(s.contentTypeConf[contentType]) + optionsConfig := s.contentTypeConf[contentType] + if sesstionType == constant.SuperGroupChatType && contentType == constant.HasReadReceipt { + optionsConfig.ReliabilityLevel = constant.UnreliableNotification + } + options := config.GetOptionsByNotification(optionsConfig) msg.Options = options offlineInfo.Title = title offlineInfo.Desc = desc