Skip to content

Commit

Permalink
fix: improve setConversationAtInfo logic. (#2782)
Browse files Browse the repository at this point in the history
* fix: improve ConversationATInfo logic.

* fix logic err.
  • Loading branch information
mo3et authored Oct 25, 2024
1 parent bbac036 commit 0207f1d
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions internal/rpc/msg/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/openimsdk/tools/log"
"github.com/openimsdk/tools/mcontext"
"github.com/openimsdk/tools/utils/datautil"
"github.com/openimsdk/tools/utils/stringutil"
)

func (m *msgServer) SendMsg(ctx context.Context, req *pbmsg.SendMsgReq) (*pbmsg.SendMsgResp, error) {
Expand Down Expand Up @@ -80,39 +79,53 @@ func (m *msgServer) sendMsgGroupChat(ctx context.Context, req *pbmsg.SendMsgReq)

func (m *msgServer) setConversationAtInfo(nctx context.Context, msg *sdkws.MsgData) {
log.ZDebug(nctx, "setConversationAtInfo", "msg", msg)

ctx := mcontext.NewCtx("@@@" + mcontext.GetOperationID(nctx))

var atUserID []string

conversation := &pbconversation.ConversationReq{
ConversationID: msgprocessor.GetConversationIDByMsg(msg),
ConversationType: msg.SessionType,
GroupID: msg.GroupID,
}

tagAll := datautil.Contain(constant.AtAllString, msg.AtUserIDList...)
if tagAll {
memberUserIDList, err := m.GroupLocalCache.GetGroupMemberIDs(ctx, msg.GroupID)
if err != nil {
log.ZWarn(ctx, "GetGroupMemberIDs", err)
return
}
atUserID = stringutil.DifferenceString([]string{constant.AtAllString}, msg.AtUserIDList)

memberUserIDList = datautil.DeleteElems(memberUserIDList, msg.SendID)

atUserID = datautil.Single([]string{constant.AtAllString}, msg.AtUserIDList)

if len(atUserID) == 0 { // just @everyone
conversation.GroupAtType = &wrapperspb.Int32Value{Value: constant.AtAll}
} else { // @Everyone and @other people
conversation.GroupAtType = &wrapperspb.Int32Value{Value: constant.AtAllAtMe}

err = m.Conversation.SetConversations(ctx, atUserID, conversation)
if err != nil {
log.ZWarn(ctx, "SetConversations", err, "userID", atUserID, "conversation", conversation)
}
memberUserIDList = stringutil.DifferenceString(atUserID, memberUserIDList)

memberUserIDList = datautil.Single(atUserID, memberUserIDList)
}

conversation.GroupAtType = &wrapperspb.Int32Value{Value: constant.AtAll}

err = m.Conversation.SetConversations(ctx, memberUserIDList, conversation)
if err != nil {
log.ZWarn(ctx, "SetConversations", err, "userID", memberUserIDList, "conversation", conversation)
}

return
}
conversation.GroupAtType = &wrapperspb.Int32Value{Value: constant.AtMe}

err := m.Conversation.SetConversations(ctx, msg.AtUserIDList, conversation)
if err != nil {
log.ZWarn(ctx, "SetConversations", err, msg.AtUserIDList, conversation)
Expand Down

0 comments on commit 0207f1d

Please sign in to comment.