From 8f2e9f5261b0c05951d96e7f52d25730f97df432 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Mon, 16 Jan 2023 14:52:12 +0800 Subject: [PATCH 1/4] sg recv opt --- internal/push/logic/push_to_client.go | 8 +++++- internal/rpc/conversation/conversaion.go | 8 ++++-- internal/rpc/user/user.go | 36 ++++++++++++++++++++---- pkg/common/db/RedisModel.go | 6 ++-- pkg/utils/utils.go | 16 +++++++++++ 5 files changed, 62 insertions(+), 12 deletions(-) diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index 1a0076289..763b5d6f3 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -249,7 +249,13 @@ func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) { } else { needOfflinePushUserIDList = onlineFailedUserIDList } - + if pushMsg.MsgData.ContentType != constant.SignalingNotification { + notNotificationUserIDList, err := db.DB.GetSuperGroupUserReceiveNotNotifyMessageIDList(pushMsg.MsgData.GroupID) + if err != nil { + log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "GetSuperGroupUserReceiveNotNotifyMessageIDList failed", pushMsg.MsgData.GroupID) + } + needOfflinePushUserIDList = utils.RemoveFromSlice(needOfflinePushUserIDList, notNotificationUserIDList) + } if offlinePusher == nil { return } diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index d977ef4f8..77051daaf 100644 --- a/internal/rpc/conversation/conversaion.go +++ b/internal/rpc/conversation/conversaion.go @@ -63,12 +63,16 @@ func (rpc *rpcConversation) ModifyConversationField(c context.Context, req *pbCo } if req.Conversation.ConversationType == constant.SuperGroupChatType { if req.Conversation.RecvMsgOpt == constant.ReceiveNotNotifyMessage { - if err = db.DB.SetSuperGroupUserNotRecvOfflineMsgOpt(req.Conversation.GroupID, v); err != nil { + if err = db.DB.SetSuperGroupUserReceiveNotNotifyMessage(req.Conversation.GroupID, v); err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error(), req.Conversation.GroupID, v) + resp.CommonResp = &pbConversation.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg} + return resp, nil } } else { - if err = db.DB.ReduceSuperGroupUserNotRecvOfflineMsgOpt(req.Conversation.GroupID, v); err != nil { + if err = db.DB.SetSuperGroupUserReceiveNotifyMessage(req.Conversation.GroupID, v); err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error(), req.Conversation.GroupID, v) + resp.CommonResp = &pbConversation.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg} + return resp, nil } } } diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index d89707c08..8ff71d383 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -163,6 +163,22 @@ func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.Batc return resp, nil } + if v.ConversationType == constant.SuperGroupChatType { + if v.RecvMsgOpt == constant.ReceiveNotNotifyMessage { + if err := db.DB.SetSuperGroupUserReceiveNotNotifyMessage(v.GroupID, v.OwnerUserID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error(), v.GroupID, v.OwnerUserID) + resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()} + return resp, nil + } + } else { + if err := db.DB.SetSuperGroupUserReceiveNotifyMessage(v.GroupID, v.OwnerUserID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error(), v.GroupID, err.Error()) + resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()} + return resp, nil + } + } + } + isUpdate, err := imdb.SetConversation(conversation) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error()) @@ -266,12 +282,16 @@ func (s *userServer) SetConversation(ctx context.Context, req *pbUser.SetConvers } if req.Conversation.ConversationType == constant.SuperGroupChatType { if req.Conversation.RecvMsgOpt == constant.ReceiveNotNotifyMessage { - if err = db.DB.SetSuperGroupUserNotRecvOfflineMsgOpt(req.Conversation.GroupID, v); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error(), req.Conversation.GroupID, v) + if err = db.DB.SetSuperGroupUserReceiveNotNotifyMessage(req.Conversation.GroupID, req.Conversation.OwnerUserID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error(), req.Conversation.GroupID, req.Conversation.OwnerUserID) + resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()} + return resp, nil } } else { - if err = db.DB.ReduceSuperGroupUserNotRecvOfflineMsgOpt(req.Conversation.GroupID, v); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error(), req.Conversation.GroupID, v) + if err = db.DB.SetSuperGroupUserReceiveNotifyMessage(req.Conversation.GroupID, req.Conversation.OwnerUserID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error(), req.Conversation.GroupID, err.Error()) + resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()} + return resp, nil } } } @@ -341,12 +361,16 @@ func (s *userServer) SetRecvMsgOpt(ctx context.Context, req *pbUser.SetRecvMsgOp case "super_group": conversation.GroupID = stringList[1] if req.RecvMsgOpt == constant.ReceiveNotNotifyMessage { - if err := db.DB.SetSuperGroupUserNotRecvOfflineMsgOpt(conversation.GroupID, req.OwnerUserID); err != nil { + if err := db.DB.SetSuperGroupUserReceiveNotNotifyMessage(conversation.GroupID, req.OwnerUserID); err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error(), conversation.GroupID, req.OwnerUserID) + resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg} + return resp, nil } } else { - if err := db.DB.ReduceSuperGroupUserNotRecvOfflineMsgOpt(conversation.GroupID, req.OwnerUserID); err != nil { + if err := db.DB.SetSuperGroupUserReceiveNotifyMessage(conversation.GroupID, req.OwnerUserID); err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error(), conversation.GroupID, req.OwnerUserID) + resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg} + return resp, nil } } } diff --git a/pkg/common/db/RedisModel.go b/pkg/common/db/RedisModel.go index b98533e87..54d724b45 100644 --- a/pkg/common/db/RedisModel.go +++ b/pkg/common/db/RedisModel.go @@ -168,17 +168,17 @@ func (d *DataBases) GetSingleConversationRecvMsgOpt(userID, conversationID strin return utils.StringToInt(result), err } -func (d *DataBases) SetSuperGroupUserNotRecvOfflineMsgOpt(groupID, userID string) error { +func (d *DataBases) SetSuperGroupUserReceiveNotNotifyMessage(groupID, userID string) error { key := superGroupUserNotRecvOfflineMsgOptTemp + groupID return d.RDB.SAdd(context.Background(), key, userID).Err() } -func (d *DataBases) ReduceSuperGroupUserNotRecvOfflineMsgOpt(groupID, userID string) error { +func (d *DataBases) SetSuperGroupUserReceiveNotifyMessage(groupID, userID string) error { key := superGroupUserNotRecvOfflineMsgOptTemp + groupID return d.RDB.SRem(context.Background(), key, userID).Err() } -func (d *DataBases) GetSuperGroupUserNotRecvOfflineMsgIDList(groupID string) ([]string, error) { +func (d *DataBases) GetSuperGroupUserReceiveNotNotifyMessageIDList(groupID string) ([]string, error) { key := superGroupUserNotRecvOfflineMsgOptTemp + groupID userIDs, _ := d.RDB.SMembers(context.Background(), key).Result() return userIDs, nil diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index e925ab994..a05b7182e 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -119,6 +119,22 @@ func DifferenceString(slice1, slice2 []string) []string { } return n } + +func RemoveFromSlice(slice1, slice2 []string) []string { + for _, v1 := range slice1 { + for i2, v2 := range slice2 { + if v2 == v1 { + if i2 != len(slice2)-1 { + slice2 = append(slice2[:i2], slice2[i2+1:]...) + } else { + slice2 = append(slice2[:i2]) + } + } + } + } + return slice2 +} + func OperationIDGenerator() string { return strconv.FormatInt(time.Now().UnixNano()+int64(rand.Uint32()), 10) } From 442c838bda8b120f3343c74587557561de9bbd99 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Mon, 16 Jan 2023 15:05:07 +0800 Subject: [PATCH 2/4] Merge branch 'v2.3.0release' of github.com:OpenIMSDK/Open-IM-Server into v2.3.0release # Conflicts: # internal/rpc/user/user.go --- internal/push/logic/push_to_client.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index 763b5d6f3..74c478ff2 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -253,6 +253,8 @@ func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) { notNotificationUserIDList, err := db.DB.GetSuperGroupUserReceiveNotNotifyMessageIDList(pushMsg.MsgData.GroupID) if err != nil { log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "GetSuperGroupUserReceiveNotNotifyMessageIDList failed", pushMsg.MsgData.GroupID) + } else { + log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), notNotificationUserIDList) } needOfflinePushUserIDList = utils.RemoveFromSlice(needOfflinePushUserIDList, notNotificationUserIDList) } From 1393e40eb99beda90b91b835b39dbf0ef974482d Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Mon, 16 Jan 2023 15:17:42 +0800 Subject: [PATCH 3/4] Merge branch 'v2.3.0release' of github.com:OpenIMSDK/Open-IM-Server into v2.3.0release # Conflicts: # internal/rpc/user/user.go --- internal/push/logic/push_to_client.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index 74c478ff2..d8006f12c 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -257,6 +257,8 @@ func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) { log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), notNotificationUserIDList) } needOfflinePushUserIDList = utils.RemoveFromSlice(needOfflinePushUserIDList, notNotificationUserIDList) + log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), needOfflinePushUserIDList) + } if offlinePusher == nil { return From 1235715c229ef6bbdfcb47ea933a82bb5db389a3 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Mon, 16 Jan 2023 15:49:10 +0800 Subject: [PATCH 4/4] push --- internal/push/logic/push_to_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index d8006f12c..9190d934b 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -256,7 +256,7 @@ func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) { } else { log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), notNotificationUserIDList) } - needOfflinePushUserIDList = utils.RemoveFromSlice(needOfflinePushUserIDList, notNotificationUserIDList) + needOfflinePushUserIDList = utils.RemoveFromSlice(notNotificationUserIDList, needOfflinePushUserIDList) log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), needOfflinePushUserIDList) }