Fix excessive last sent calls

This commit is contained in:
Andrew
2024-05-20 13:58:13 +09:30
parent cf13caaee4
commit 4904524af5
12 changed files with 86 additions and 48 deletions

View File

@@ -0,0 +1,9 @@
package org.session.libsession.messaging
interface LastSentTimestampCache {
fun getTimestamp(threadId: Long): Long?
fun submitTimestamp(threadId: Long, timestamp: Long)
fun delete(threadId: Long, timestamps: List<Long>)
fun delete(threadId: Long, timestamp: Long) = delete(threadId, listOf(timestamp))
fun refresh(threadId: Long)
}

View File

@@ -13,7 +13,8 @@ class MessagingModuleConfiguration(
val device: Device,
val messageDataProvider: MessageDataProvider,
val getUserED25519KeyPair: () -> KeyPair?,
val configFactory: ConfigFactoryProtocol
val configFactory: ConfigFactoryProtocol,
val lastSentTimestampCache: LastSentTimestampCache
) {
companion object {

View File

@@ -73,6 +73,7 @@ object MessageSender {
// Convenience
fun send(message: Message, destination: Destination, isSyncMessage: Boolean): Promise<Unit, Exception> {
if (message is VisibleMessage) MessagingModuleConfiguration.shared.lastSentTimestampCache.submitTimestamp(message.threadID!!, message.sentTimestamp!!)
return if (destination is Destination.LegacyOpenGroup || destination is Destination.OpenGroup || destination is Destination.OpenGroupInbox) {
sendToOpenGroupDestination(destination, message)
} else {

View File

@@ -290,6 +290,7 @@ fun MessageReceiver.handleVisibleMessage(
): Long? {
val storage = MessagingModuleConfiguration.shared.storage
val context = MessagingModuleConfiguration.shared.context
message.sentTimestamp?.let { MessagingModuleConfiguration.shared.lastSentTimestampCache.submitTimestamp(threadId, it) }
val userPublicKey = storage.getUserPublicKey()
val messageSender: String? = message.sender
@@ -410,12 +411,7 @@ fun MessageReceiver.handleVisibleMessage(
message.hasMention = listOf(userPublicKey, userBlindedKey)
.filterNotNull()
.any { key ->
return@any (
messageText != null &&
messageText.contains("@$key")
) || (
(quoteModel?.author?.serialize() ?: "") == key
)
messageText?.contains("@$key") == true || key == (quoteModel?.author?.serialize() ?: "")
}
// Persist the message