check if the incoming message is already in database before persisting

This commit is contained in:
Ryan Zhao 2022-03-15 14:00:36 +11:00
parent c9b9104e8a
commit b920dbcc10
2 changed files with 2 additions and 1 deletions

View File

@ -42,6 +42,7 @@ extension Storage {
}
tsMessage = tsOutgoingMessage
} else {
if let _ = TSIncomingMessage.find(withAuthorId: message.sender!, timestamp: message.sentTimestamp!, transaction: transaction) { return nil }
tsMessage = TSIncomingMessage.from(message, quotedMessage: quotedMessage, linkPreview: linkPreview, associatedWith: thread)
}
tsMessage.save(with: transaction)

View File

@ -365,7 +365,7 @@ extension MessageReceiver {
}
// Persist the message
guard let tsMessageID = storage.persist(message, quotedMessage: tsQuotedMessage, linkPreview: owsLinkPreview,
groupPublicKey: message.groupPublicKey, openGroupID: openGroupID, using: transaction) else { throw Error.noThread }
groupPublicKey: message.groupPublicKey, openGroupID: openGroupID, using: transaction) else { throw Error.duplicateMessage }
message.threadID = threadID
// Start attachment downloads if needed
let isContactTrusted = Storage.shared.getContact(with: message.sender!)?.isTrusted ?? false