From f9475bdd87a3116c88f869f673bd91036eae2254 Mon Sep 17 00:00:00 2001 From: OpenIM-Gordon <1432970085@qq.com> Date: Mon, 28 Jul 2025 11:18:49 +0800 Subject: [PATCH] fix: added AtUserIDList to the @ message for API sending. (#3472) --- internal/api/msg.go | 64 ++++++++++++++++++++++++-------------------- pkg/apistruct/msg.go | 13 ++++++--- 2 files changed, 45 insertions(+), 32 deletions(-) diff --git a/internal/api/msg.go b/internal/api/msg.go index d832bfdcd..a134dfdb3 100644 --- a/internal/api/msg.go +++ b/internal/api/msg.go @@ -94,7 +94,22 @@ func (*MessageApi) SetOptions(options map[string]bool, value bool) { datautil.SetSwitchFromOptions(options, constant.IsConversationUpdate, value) } -func (m *MessageApi) newUserSendMsgReq(_ *gin.Context, params *apistruct.SendMsg) *msg.SendMsgReq { +func (m *MessageApi) newUserSendMsgReq(_ *gin.Context, params *apistruct.SendMsg, data any) *msg.SendMsgReq { + msgData := &sdkws.MsgData{ + SendID: params.SendID, + GroupID: params.GroupID, + ClientMsgID: idutil.GetMsgIDByMD5(params.SendID), + SenderPlatformID: params.SenderPlatformID, + SenderNickname: params.SenderNickname, + SenderFaceURL: params.SenderFaceURL, + SessionType: params.SessionType, + MsgFrom: constant.SysMsgType, + ContentType: params.ContentType, + CreateTime: timeutil.GetCurrentTimestampByMill(), + SendTime: params.SendTime, + OfflinePushInfo: params.OfflinePushInfo, + Ex: params.Ex, + } var newContent string options := make(map[string]bool, 5) switch params.ContentType { @@ -104,6 +119,11 @@ func (m *MessageApi) newUserSendMsgReq(_ *gin.Context, params *apistruct.SendMsg newContent = jsonutil.StructToJsonString(¬ification) case constant.Text: fallthrough + case constant.AtText: + if atElem, ok := data.(*apistruct.AtElem); ok { + msgData.AtUserIDList = atElem.AtUserList + } + fallthrough case constant.Picture: fallthrough case constant.Custom: @@ -123,24 +143,10 @@ func (m *MessageApi) newUserSendMsgReq(_ *gin.Context, params *apistruct.SendMsg if params.NotOfflinePush { datautil.SetSwitchFromOptions(options, constant.IsOfflinePush, false) } + msgData.Content = []byte(newContent) + msgData.Options = options pbData := msg.SendMsgReq{ - MsgData: &sdkws.MsgData{ - SendID: params.SendID, - GroupID: params.GroupID, - ClientMsgID: idutil.GetMsgIDByMD5(params.SendID), - SenderPlatformID: params.SenderPlatformID, - SenderNickname: params.SenderNickname, - SenderFaceURL: params.SenderFaceURL, - SessionType: params.SessionType, - MsgFrom: constant.SysMsgType, - ContentType: params.ContentType, - Content: []byte(newContent), - CreateTime: timeutil.GetCurrentTimestampByMill(), - SendTime: params.SendTime, - Options: options, - OfflinePushInfo: params.OfflinePushInfo, - Ex: params.Ex, - }, + MsgData: msgData, } return &pbData } @@ -198,23 +204,23 @@ func (m *MessageApi) getSendMsgReq(c *gin.Context, req apistruct.SendMsg) (sendM log.ZDebug(c, "getSendMsgReq", "req", req.Content) switch req.ContentType { case constant.Text: - data = apistruct.TextElem{} + data = &apistruct.TextElem{} case constant.Picture: - data = apistruct.PictureElem{} + data = &apistruct.PictureElem{} case constant.Voice: - data = apistruct.SoundElem{} + data = &apistruct.SoundElem{} case constant.Video: - data = apistruct.VideoElem{} + data = &apistruct.VideoElem{} case constant.File: - data = apistruct.FileElem{} + data = &apistruct.FileElem{} case constant.AtText: - data = apistruct.AtElem{} + data = &apistruct.AtElem{} case constant.Custom: - data = apistruct.CustomElem{} + data = &apistruct.CustomElem{} case constant.MarkdownText: - data = apistruct.MarkdownTextElem{} + data = &apistruct.MarkdownTextElem{} case constant.OANotification: - data = apistruct.OANotificationElem{} + data = &apistruct.OANotificationElem{} req.SessionType = constant.NotificationChatType if err = m.userClient.GetNotificationByID(c, req.SendID); err != nil { return nil, err @@ -222,14 +228,14 @@ func (m *MessageApi) getSendMsgReq(c *gin.Context, req apistruct.SendMsg) (sendM default: return nil, errs.WrapMsg(errs.ErrArgs, "unsupported content type", "contentType", req.ContentType) } - if err := mapstructure.WeakDecode(req.Content, &data); err != nil { + if err := mapstructure.WeakDecode(req.Content, data); err != nil { return nil, errs.WrapMsg(err, "failed to decode message content") } log.ZDebug(c, "getSendMsgReq", "decodedContent", data) if err := m.validate.Struct(data); err != nil { return nil, errs.WrapMsg(err, "validation error") } - return m.newUserSendMsgReq(c, &req), nil + return m.newUserSendMsgReq(c, &req, data), nil } func (m *MessageApi) getModifyFields(req, respModify *sdkws.MsgData) map[string]any { diff --git a/pkg/apistruct/msg.go b/pkg/apistruct/msg.go index d818e769c..0e1b356a1 100644 --- a/pkg/apistruct/msg.go +++ b/pkg/apistruct/msg.go @@ -63,9 +63,11 @@ type FileElem struct { FileSize int64 `mapstructure:"fileSize" validate:"required"` } type AtElem struct { - Text string `mapstructure:"text"` - AtUserList []string `mapstructure:"atUserList" validate:"required,max=1000"` - IsAtSelf bool `mapstructure:"isAtSelf"` + Text string `mapstructure:"text"` + AtUserList []string `mapstructure:"atUserList" validate:"required,max=1000"` + AtUsersInfo []*AtInfo `json:"atUsersInfo"` + QuoteMessage *MsgStruct `json:"quoteMessage"` + IsAtSelf bool `mapstructure:"isAtSelf"` } type LocationElem struct { Description string `mapstructure:"description"` @@ -158,3 +160,8 @@ type MsgStruct struct { CustomElem *CustomElem `json:"customElem,omitempty"` QuoteElem *QuoteElem `json:"quoteElem,omitempty"` } + +type AtInfo struct { + AtUserID string `json:"atUserID,omitempty"` + GroupNickname string `json:"groupNickname,omitempty"` +}