send unsend request as sync message

This commit is contained in:
ryanzhao 2021-08-16 14:03:06 +10:00
parent e8551a3545
commit 29e355c6ab

View File

@ -254,34 +254,35 @@ object MessageSender {
fun handleSuccessfulMessageSend(message: Message, destination: Destination, isSyncMessage: Boolean = false, openGroupSentTimestamp: Long = -1) { fun handleSuccessfulMessageSend(message: Message, destination: Destination, isSyncMessage: Boolean = false, openGroupSentTimestamp: Long = -1) {
val storage = MessagingModuleConfiguration.shared.storage val storage = MessagingModuleConfiguration.shared.storage
val userPublicKey = storage.getUserPublicKey()!! val userPublicKey = storage.getUserPublicKey()!!
val messageID = storage.getMessageIdInDatabase(message.sentTimestamp!!, message.sender?:userPublicKey) ?: return
// Ignore future self-sends // Ignore future self-sends
storage.addReceivedMessageTimestamp(message.sentTimestamp!!) storage.addReceivedMessageTimestamp(message.sentTimestamp!!)
if (openGroupSentTimestamp != -1L && message is VisibleMessage) { storage.getMessageIdInDatabase(message.sentTimestamp!!, message.sender?:userPublicKey)?.let { messageID ->
storage.addReceivedMessageTimestamp(openGroupSentTimestamp) if (openGroupSentTimestamp != -1L && message is VisibleMessage) {
storage.updateSentTimestamp(messageID, message.isMediaMessage(), openGroupSentTimestamp, message.threadID!!) storage.addReceivedMessageTimestamp(openGroupSentTimestamp)
message.sentTimestamp = openGroupSentTimestamp storage.updateSentTimestamp(messageID, message.isMediaMessage(), openGroupSentTimestamp, message.threadID!!)
} message.sentTimestamp = openGroupSentTimestamp
// When the sync message is successfully sent, the hash value of this TSOutgoingMessage }
// will be replaced by the hash value of the sync message. Since the hash value of the // When the sync message is successfully sent, the hash value of this TSOutgoingMessage
// real message has no use when we delete a message. It is OK to let it be. // will be replaced by the hash value of the sync message. Since the hash value of the
message.serverHash?.let { // real message has no use when we delete a message. It is OK to let it be.
storage.setMessageServerHash(messageID, it) message.serverHash?.let {
} storage.setMessageServerHash(messageID, it)
// Track the open group server message ID }
if (message.openGroupServerMessageID != null && destination is Destination.OpenGroupV2) { // Track the open group server message ID
val encoded = GroupUtil.getEncodedOpenGroupID("${destination.server}.${destination.room}".toByteArray()) if (message.openGroupServerMessageID != null && destination is Destination.OpenGroupV2) {
val threadID = storage.getThreadId(Address.fromSerialized(encoded)) val encoded = GroupUtil.getEncodedOpenGroupID("${destination.server}.${destination.room}".toByteArray())
if (threadID != null && threadID >= 0) { val threadID = storage.getThreadId(Address.fromSerialized(encoded))
storage.setOpenGroupServerMessageID(messageID, message.openGroupServerMessageID!!, threadID, !(message as VisibleMessage).isMediaMessage()) if (threadID != null && threadID >= 0) {
storage.setOpenGroupServerMessageID(messageID, message.openGroupServerMessageID!!, threadID, !(message as VisibleMessage).isMediaMessage())
}
}
// Mark the message as sent
storage.markAsSent(message.sentTimestamp!!, message.sender?:userPublicKey)
storage.markUnidentified(message.sentTimestamp!!, message.sender?:userPublicKey)
// Start the disappearing messages timer if needed
if (message is VisibleMessage && !isSyncMessage) {
SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(message.sentTimestamp!!, message.sender?:userPublicKey)
} }
}
// Mark the message as sent
storage.markAsSent(message.sentTimestamp!!, message.sender?:userPublicKey)
storage.markUnidentified(message.sentTimestamp!!, message.sender?:userPublicKey)
// Start the disappearing messages timer if needed
if (message is VisibleMessage && !isSyncMessage) {
SSKEnvironment.shared.messageExpirationManager.startAnyExpiration(message.sentTimestamp!!, message.sender?:userPublicKey)
} }
// Sync the message if: // Sync the message if:
// • it's a visible message // • it's a visible message