From b707cd3523807da4e317d228925c59499eb823a4 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Fri, 5 Jun 2026 10:49:47 +0800 Subject: [PATCH 1/2] refactor(msg): update regex pattern for conversationID to include a trailing colon (cherry picked from commit 82f87551d6067983f4e31f8dacb905c740d58639) --- pkg/common/storage/database/mgo/msg.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/common/storage/database/mgo/msg.go b/pkg/common/storage/database/mgo/msg.go index f0665b03d..c70718f73 100644 --- a/pkg/common/storage/database/mgo/msg.go +++ b/pkg/common/storage/database/mgo/msg.go @@ -951,7 +951,7 @@ func (m *MsgMgo) GetLastMessageSeqByTime(ctx context.Context, conversationID str { "$match": bson.M{ "doc_id": bson.M{ - "$regex": fmt.Sprintf("^%s", conversationID), + "$regex": fmt.Sprintf("^%s:", conversationID), }, }, }, @@ -1003,7 +1003,7 @@ func (m *MsgMgo) GetLastMessage(ctx context.Context, conversationID string) (*mo { "$match": bson.M{ "doc_id": bson.M{ - "$regex": fmt.Sprintf("^%s", conversationID), + "$regex": fmt.Sprintf("^%s:", conversationID), }, }, }, From 9016d7722b4095148d56bd3d80a2eaa93fc47b9c Mon Sep 17 00:00:00 2001 From: chao <48119764+withchao@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:16:36 +0800 Subject: [PATCH 2/2] feat: SendBusinessNotification supported configuration parameters (#3048) * pb * fix: Modifying other fields while setting IsPrivateChat does not take effect * fix: quote message error revoke * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * upgrading pkg tools * fix * fix * optimize log output * feat: support GetLastMessage * feat: support GetLastMessage * feat: s3 switch * feat: s3 switch * fix: GetUsersOnline * feat: SendBusinessNotification supported configuration parameters * feat: SendBusinessNotification supported configuration parameters * feat: SendBusinessNotification supported configuration parameters (cherry picked from commit 2c747c95a035512d6c5a583e32ec1e6bb298776b) --- internal/api/msg.go | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/internal/api/msg.go b/internal/api/msg.go index 4fe950ffa..9976ea1eb 100644 --- a/internal/api/msg.go +++ b/internal/api/msg.go @@ -248,24 +248,44 @@ func (m *MessageApi) SendMessage(c *gin.Context) { func (m *MessageApi) SendBusinessNotification(c *gin.Context) { req := struct { - Key string `json:"key"` - Data string `json:"data"` - SendUserID string `json:"sendUserID" binding:"required"` - RecvUserID string `json:"recvUserID" binding:"required"` + Key string `json:"key"` + Data string `json:"data"` + SendUserID string `json:"sendUserID" binding:"required"` + RecvUserID string `json:"recvUserID"` + RecvGroupID string `json:"recvGroupID"` + SendMsg bool `json:"sendMsg"` + ReliabilityLevel *int `json:"reliabilityLevel"` }{} if err := c.BindJSON(&req); err != nil { apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap()) return } - + if req.RecvUserID == "" && req.RecvGroupID == "" { + apiresp.GinError(c, errs.ErrArgs.WrapMsg("recvUserID and recvGroupID cannot be empty at the same time")) + return + } + if req.RecvUserID != "" && req.RecvGroupID != "" { + apiresp.GinError(c, errs.ErrArgs.WrapMsg("recvUserID and recvGroupID cannot be set at the same time")) + return + } + var sessionType int32 + if req.RecvUserID != "" { + sessionType = constant.SingleChatType + } else { + sessionType = constant.ReadGroupChatType + } + if req.ReliabilityLevel == nil { + req.ReliabilityLevel = datautil.ToPtr(1) + } if !authverify.IsAppManagerUid(c, m.imAdminUserID) { apiresp.GinError(c, errs.ErrNoPermission.WrapMsg("only app manager can send message")) return } sendMsgReq := msg.SendMsgReq{ MsgData: &sdkws.MsgData{ - SendID: req.SendUserID, - RecvID: req.RecvUserID, + SendID: req.SendUserID, + RecvID: req.RecvUserID, + GroupID: req.RecvGroupID, Content: []byte(jsonutil.StructToJsonString(&sdkws.NotificationElem{ Detail: jsonutil.StructToJsonString(&struct { Key string `json:"key"` @@ -274,12 +294,12 @@ func (m *MessageApi) SendBusinessNotification(c *gin.Context) { })), MsgFrom: constant.SysMsgType, ContentType: constant.BusinessNotification, - SessionType: constant.SingleChatType, + SessionType: sessionType, CreateTime: timeutil.GetCurrentTimestampByMill(), ClientMsgID: idutil.GetMsgIDByMD5(mcontext.GetOpUserID(c)), Options: config.GetOptionsByNotification(config.NotificationConfig{ - IsSendMsg: false, - ReliabilityLevel: 1, + IsSendMsg: req.SendMsg, + ReliabilityLevel: *req.ReliabilityLevel, UnreadCount: false, }, nil), },