fix: add discord message data to quoted messages

Because `QuotedMessage` doesn't include imported message data,
some of the author information in imported messages is lost in
frontends.

This commit adds a `discordMessage` (soon replaced by `importedMessage`)
to `Quotedmessage`, although only hydrated with a subset of data,
namely author display name and avatar URL, as those are the only ones
needed by front-end atm.
This commit is contained in:
Pascal Precht 2023-01-13 16:28:49 +01:00 committed by r4bbit
parent 5a4ca88631
commit cedc1a5fd1
3 changed files with 47 additions and 4 deletions

View File

@ -39,6 +39,8 @@ type QuotedMessage struct {
CommunityID string `json:"communityId,omitempty"`
Deleted bool `json:"deleted,omitempty"`
DiscordMessage *protobuf.DiscordMessage `json:"discordMessage,omitempty"`
}
type CommandState int

View File

@ -25,6 +25,10 @@ LEFT JOIN discord_message_authors dm_author
ON dm.author_id = dm_author.id
LEFT JOIN discord_message_attachments dm_attachment
ON dm.id = dm_attachment.discord_message_id
LEFT JOIN discord_messages m2_dm
ON m2.discord_message_id = m2_dm.id
LEFT JOIN discord_message_authors m2_dm_author
ON m2_dm.author_id = m2_dm_author.id
`
var basicInsertDiscordMessageAuthorQuery = `INSERT OR REPLACE INTO discord_message_authors(id,name,discriminator,nickname,avatar_url, avatar_image_payload) VALUES (?,?,?,?,?,?)`
@ -172,7 +176,11 @@ func (db sqlitePersistence) tableUserMessagesAllFieldsJoin() string {
m2.content_type,
m2.deleted,
c.alias,
c.identicon`
c.identicon,
COALESCE(m2.discord_message_id, ""),
COALESCE(m2_dm_author.name, ""),
COALESCE(m2_dm_author.nickname, ""),
COALESCE(m2_dm_author.avatar_url, "")`
}
func (db sqlitePersistence) tableUserMessagesAllFieldsCount() int {
@ -218,6 +226,10 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message
Attachments: []*protobuf.DiscordMessageAttachment{},
}
quotedDiscordMessage := &protobuf.DiscordMessage{
Author: &protobuf.DiscordMessageAuthor{},
}
attachment := &protobuf.DiscordMessageAttachment{}
args := []interface{}{
@ -294,6 +306,10 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message
&quotedDeleted,
&alias,
&identicon,
&quotedDiscordMessage.Id,
&quotedDiscordMessage.Author.Name,
&quotedDiscordMessage.Author.Nickname,
&quotedDiscordMessage.Author.AvatarUrl,
}
err := row.Scan(append(args, others...)...)
if err != nil {
@ -336,6 +352,9 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message
CommunityID: quotedCommunityID.String,
Deleted: quotedDeleted.Bool,
}
if message.QuotedMessage.ContentType == int64(protobuf.ChatMessage_DISCORD_MESSAGE) {
message.QuotedMessage.DiscordMessage = quotedDiscordMessage
}
}
}
message.Alias = alias.String
@ -1024,6 +1043,16 @@ func (db sqlitePersistence) PinnedMessageByChatIDs(chatIDs []string, currCursor
ON
dm.id = dm_attachment.discord_message_id
LEFT JOIN
discord_messages m2_dm
ON
m2.discord_message_id = m2_dm.id
LEFT JOIN
discord_message_authors m2_dm_author
ON
m2_dm.author_id = m2_dm_author.id
WHERE
pm.pinned = 1
AND NOT(m1.hide) AND m1.local_chat_id IN %s %s

View File

@ -4483,6 +4483,18 @@ func (m *Messenger) prepareMessage(msg *common.Message, s *server.MediaServer) {
if msg.QuotedMessage != nil && msg.QuotedMessage.ContentType == int64(protobuf.ChatMessage_STICKER) {
msg.QuotedMessage.HasSticker = true
}
if msg.QuotedMessage != nil && msg.QuotedMessage.ContentType == int64(protobuf.ChatMessage_DISCORD_MESSAGE) {
dm := msg.QuotedMessage.DiscordMessage
exists, err := m.persistence.HasDiscordMessageAuthorImagePayload(dm.Author.Id)
if err != nil {
return
}
if exists {
msg.QuotedMessage.DiscordMessage.Author.LocalUrl = s.MakeDiscordAuthorAvatarURL(dm.Author.Id)
}
}
if msg.ContentType == protobuf.ChatMessage_IMAGE {
msg.ImageLocalURL = s.MakeImageURL(msg.ID)
}