Skip to content

Commit

Permalink
fix: 修复单聊/群聊发送消息时不能正确处理响应的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
WindowsSov8forUs committed Sep 13, 2024
1 parent c375d76 commit 6f2d91e
Showing 1 changed file with 1 addition and 64 deletions.
65 changes: 1 addition & 64 deletions server/httpapi/message_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func HandleMessageCreate(api, apiv2 openapi.OpenAPI, message *ActionMessage) (an
if err != nil {
return gin.H{}, &InternalServerError{err}
}
messageResponse, err := convertDtoMessageToMessage(dtoC2CMessageResponse.Message)
messageResponse, err := convertDtoMessageV2ToMessage(dtoC2CMessageResponse.Message)
if err != nil {
return gin.H{}, &InternalServerError{err}
}
Expand Down Expand Up @@ -680,69 +680,6 @@ func convertDtoMessageV2ToMessage(dtoMessage *dto.Message) (*satoriMessage.Messa
message.Content = content
}

// 判断是否为单聊
if dtoMessage.GroupID != "" {
// 是群聊
channel := &channel.Channel{
Id: dtoMessage.GroupID,
Type: channel.ChannelTypeText,
}
guild := &guild.Guild{
Id: dtoMessage.GroupID,
}
var guildMember *guildmember.GuildMember
if dtoMessage.Member == nil {
guildMember = &guildmember.GuildMember{}
if dtoMessage.Member != nil {
guildMember.Nick = dtoMessage.Member.Nick
}
if dtoMessage.Author != nil {
guildMember.Avatar = dtoMessage.Author.Avatar
}
}
var u *user.User
if dtoMessage.Author != nil {
u = &user.User{
Id: dtoMessage.Author.ID,
Name: dtoMessage.Author.Username,
Avatar: dtoMessage.Author.Avatar,
IsBot: dtoMessage.Author.Bot,
}
}

// 获取时间
if dtoMessage.Member != nil {
time, err := dtoMessage.Member.JoinedAt.Time()
if err != nil {
return nil, err
}
guildMember.JoinedAt = time.UnixMilli()
}

message.Channel = channel
message.Guild = guild
message.Member = guildMember
message.User = u
} else {
// 判断是否存在需要的数据
if dtoMessage.Author != nil {
// 是单聊
// TODO: 目前没有实际运用场景,很可能需要更改
channel := &channel.Channel{
Id: dtoMessage.Author.ID,
Type: channel.ChannelTypeDirect,
}
user := &user.User{
Id: dtoMessage.Author.ID,
Name: dtoMessage.Author.Username,
Avatar: dtoMessage.Author.Avatar,
IsBot: dtoMessage.Author.Bot,
}
message.Channel = channel
message.User = user
}
}

time, err := dtoMessage.Timestamp.Time()
if err != nil {
return nil, err
Expand Down

0 comments on commit 6f2d91e

Please sign in to comment.