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:
parent
5a4ca88631
commit
cedc1a5fd1
|
@ -39,6 +39,8 @@ type QuotedMessage struct {
|
||||||
CommunityID string `json:"communityId,omitempty"`
|
CommunityID string `json:"communityId,omitempty"`
|
||||||
|
|
||||||
Deleted bool `json:"deleted,omitempty"`
|
Deleted bool `json:"deleted,omitempty"`
|
||||||
|
|
||||||
|
DiscordMessage *protobuf.DiscordMessage `json:"discordMessage,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommandState int
|
type CommandState int
|
||||||
|
|
|
@ -25,6 +25,10 @@ LEFT JOIN discord_message_authors dm_author
|
||||||
ON dm.author_id = dm_author.id
|
ON dm.author_id = dm_author.id
|
||||||
LEFT JOIN discord_message_attachments dm_attachment
|
LEFT JOIN discord_message_attachments dm_attachment
|
||||||
ON dm.id = dm_attachment.discord_message_id
|
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 (?,?,?,?,?,?)`
|
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.content_type,
|
||||||
m2.deleted,
|
m2.deleted,
|
||||||
c.alias,
|
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 {
|
func (db sqlitePersistence) tableUserMessagesAllFieldsCount() int {
|
||||||
|
@ -218,6 +226,10 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message
|
||||||
Attachments: []*protobuf.DiscordMessageAttachment{},
|
Attachments: []*protobuf.DiscordMessageAttachment{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quotedDiscordMessage := &protobuf.DiscordMessage{
|
||||||
|
Author: &protobuf.DiscordMessageAuthor{},
|
||||||
|
}
|
||||||
|
|
||||||
attachment := &protobuf.DiscordMessageAttachment{}
|
attachment := &protobuf.DiscordMessageAttachment{}
|
||||||
|
|
||||||
args := []interface{}{
|
args := []interface{}{
|
||||||
|
@ -294,6 +306,10 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message
|
||||||
"edDeleted,
|
"edDeleted,
|
||||||
&alias,
|
&alias,
|
||||||
&identicon,
|
&identicon,
|
||||||
|
"edDiscordMessage.Id,
|
||||||
|
"edDiscordMessage.Author.Name,
|
||||||
|
"edDiscordMessage.Author.Nickname,
|
||||||
|
"edDiscordMessage.Author.AvatarUrl,
|
||||||
}
|
}
|
||||||
err := row.Scan(append(args, others...)...)
|
err := row.Scan(append(args, others...)...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -336,6 +352,9 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message
|
||||||
CommunityID: quotedCommunityID.String,
|
CommunityID: quotedCommunityID.String,
|
||||||
Deleted: quotedDeleted.Bool,
|
Deleted: quotedDeleted.Bool,
|
||||||
}
|
}
|
||||||
|
if message.QuotedMessage.ContentType == int64(protobuf.ChatMessage_DISCORD_MESSAGE) {
|
||||||
|
message.QuotedMessage.DiscordMessage = quotedDiscordMessage
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
message.Alias = alias.String
|
message.Alias = alias.String
|
||||||
|
@ -1019,10 +1038,20 @@ func (db sqlitePersistence) PinnedMessageByChatIDs(chatIDs []string, currCursor
|
||||||
ON
|
ON
|
||||||
dm.author_id = dm_author.id
|
dm.author_id = dm_author.id
|
||||||
|
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
discord_message_attachments dm_attachment
|
discord_message_attachments dm_attachment
|
||||||
ON
|
ON
|
||||||
dm.id = dm_attachment.discord_message_id
|
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
|
WHERE
|
||||||
pm.pinned = 1
|
pm.pinned = 1
|
||||||
|
|
|
@ -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) {
|
if msg.QuotedMessage != nil && msg.QuotedMessage.ContentType == int64(protobuf.ChatMessage_STICKER) {
|
||||||
msg.QuotedMessage.HasSticker = true
|
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 {
|
if msg.ContentType == protobuf.ChatMessage_IMAGE {
|
||||||
msg.ImageLocalURL = s.MakeImageURL(msg.ID)
|
msg.ImageLocalURL = s.MakeImageURL(msg.ID)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue