Reupload webhook avatars to fill custom metadata

This commit is contained in:
Tulir Asokan
2023-05-27 13:35:37 +03:00
parent 4393772ccc
commit 52fa4da8b2
5 changed files with 58 additions and 71 deletions

View File

@@ -898,7 +898,7 @@ func (portal *Portal) handleDiscordMessageUpdate(user *User, msg *discordgo.Mess
return
}
if msg.WebhookID != "" {
addWebhookMeta(converted, msg)
portal.addWebhookMeta(converted, msg)
}
converted.Content.Mentions = portal.convertDiscordMentions(msg, "", false)
converted.Content.SetEdit(existing[0].MXID)
@@ -2152,13 +2152,15 @@ func (portal *Portal) UpdateGroupDMAvatar(iconID string) bool {
portal.AvatarSet = false
portal.AvatarURL = id.ContentURI{}
if portal.Avatar != "" {
uri, err := uploadAvatar(portal.MainIntent(), discordgo.EndpointGroupIcon(portal.Key.ChannelID, portal.Avatar))
// TODO direct media support
copied, err := portal.bridge.copyAttachmentToMatrix(portal.MainIntent(), discordgo.EndpointGroupIcon(portal.Key.ChannelID, portal.Avatar), false, AttachmentMeta{
AttachmentID: fmt.Sprintf("private_channel_avatar/%s/%s", portal.Key.ChannelID, iconID),
})
if err != nil {
portal.log.Err(err).Str("avatar_id", portal.Avatar).Msg("Failed to reupload channel avatar")
portal.log.Err(err).Str("avatar_id", iconID).Msg("Failed to reupload channel avatar")
return true
} else {
portal.AvatarURL = uri
}
portal.AvatarURL = copied.MXC
}
portal.updateRoomAvatar()
return true