fix: ensure discord attachment existence is checked with message ID

This commit is contained in:
Pascal Precht 2022-10-05 12:39:55 +02:00 committed by r4bbit.eth
parent f7faebe775
commit 9bb1e75939
2 changed files with 3 additions and 3 deletions

View File

@ -1806,8 +1806,8 @@ func (db sqlitePersistence) SaveDiscordMessages(messages []*protobuf.DiscordMess
return
}
func (db sqlitePersistence) HasDiscordMessageAttachmentPayload(id string) (hasPayload bool, err error) {
err = db.db.QueryRow(`SELECT EXISTS(SELECT 1 FROM discord_message_attachments WHERE id = ? AND payload NOT NULL)`, id).Scan(&hasPayload)
func (db sqlitePersistence) HasDiscordMessageAttachmentPayload(id string, messageID string) (hasPayload bool, err error) {
err = db.db.QueryRow(`SELECT EXISTS(SELECT 1 FROM discord_message_attachments WHERE id = ? AND discord_message_id = ? AND payload NOT NULL)`, id, messageID).Scan(&hasPayload)
return hasPayload, err
}

View File

@ -4179,7 +4179,7 @@ func (m *Messenger) prepareMessage(msg *common.Message, s *server.MediaServer) {
for idx, attachment := range dm.Attachments {
if strings.Contains(attachment.ContentType, "image") {
hasPayload, err := m.persistence.HasDiscordMessageAttachmentPayload(attachment.Id)
hasPayload, err := m.persistence.HasDiscordMessageAttachmentPayload(attachment.Id, dm.Id)
if err != nil {
m.logger.Error("failed to check if message attachment exist", zap.Error(err))
continue