fix: added AtUserIDList to the @ message for API sending. (#3472)

This commit is contained in:
OpenIM-Gordon 2025-07-28 11:18:49 +08:00 committed by GitHub
parent 839d7d90ac
commit f9475bdd87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 32 deletions

View File

@ -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(&notification)
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 {

View File

@ -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"`
}