From 5d2f2adccf41ada45cd1660e55315c31e91b0bf0 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Fri, 1 Sep 2023 17:00:33 +0800 Subject: [PATCH 1/4] fix: repeated modification session notification --- internal/rpc/conversation/conversaion.go | 74 +++++++++++++++++------- 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index d1f4a7fc6..3d34e7345 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.Conversation.UserID, []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}) } From a5455c38561673ea79e5491ae9c52c427899d75d Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Fri, 1 Sep 2023 17:21:47 +0800 Subject: [PATCH 2/4] fix: repeated modification session notification --- internal/rpc/conversation/conversaion.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index 3d34e7345..093bddc35 100644 --- a/internal/rpc/conversation/conversaion.go +++ b/internal/rpc/conversation/conversaion.go @@ -136,7 +136,7 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver var unequal int var conv tablerelation.ConversationModel if len(req.UserIDs) == 1 { - cs, err := c.conversationDatabase.FindConversations(ctx, req.Conversation.UserID, []string{req.Conversation.ConversationID}) + cs, err := c.conversationDatabase.FindConversations(ctx, req.UserIDs[0], []string{req.Conversation.ConversationID}) if err != nil { return nil, err } From 123f08191ab30edf622cf9c60a0957dc18991cf5 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Mon, 4 Sep 2023 19:30:37 +0800 Subject: [PATCH 3/4] fix: jpush return a nil pointer panic --- internal/push/push_to_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/push/push_to_client.go b/internal/push/push_to_client.go index 50010ca84..de0ecc192 100644 --- a/internal/push/push_to_client.go +++ b/internal/push/push_to_client.go @@ -288,7 +288,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 { From 0a9b3de6e2d1d09ca42296e1e443c8393e7efbdf Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Thu, 7 Sep 2023 15:40:22 +0800 Subject: [PATCH 4/4] fix: OANotification --- internal/api/msg.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/internal/api/msg.go b/internal/api/msg.go index 726889d56..e5a49199f 100644 --- a/internal/api/msg.go +++ b/internal/api/msg.go @@ -15,14 +15,12 @@ package api import ( + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/tools/mcontext" "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" "github.com/mitchellh/mapstructure" - "google.golang.org/protobuf/proto" - - "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/msg" @@ -56,7 +54,6 @@ func (MessageApi) SetOptions(options map[string]bool, value bool) { func (m MessageApi) newUserSendMsgReq(c *gin.Context, params *apistruct.SendMsg) *msg.SendMsgReq { var newContent string - var err error options := make(map[string]bool, 5) switch params.ContentType { case constant.Text: @@ -106,14 +103,14 @@ func (m MessageApi) newUserSendMsgReq(c *gin.Context, params *apistruct.SendMsg) OfflinePushInfo: params.OfflinePushInfo, }, } - if params.ContentType == constant.OANotification { - var tips sdkws.TipsComm - tips.JsonDetail = utils.StructToJsonString(params.Content) - pbData.MsgData.Content, err = proto.Marshal(&tips) - if err != nil { - log.ZError(c, "Marshal failed ", err, "tips", tips.String()) - } - } + //if params.ContentType == constant.OANotification { + // var tips sdkws.TipsComm + // tips.JsonDetail = utils.StructToJsonString(params.Content) + // pbData.MsgData.Content, err = proto.Marshal(&tips) + // if err != nil { + // log.ZError(c, "Marshal failed ", err, "tips", tips.String()) + // } + //} return &pbData }