From 39df560f0cdc0ad9c4908e0a5088ab35d52588f4 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 21 Feb 2024 01:16:05 +1030 Subject: [PATCH] Don't shorten ttl of closedGroupControlMessage --- .../sending_receiving/MessageSender.kt | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt index 4199e69486..10c627d1b3 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt @@ -252,19 +252,18 @@ object MessageSender { return promise } - private fun getSpecifiedTtl(message: Message, isSyncMessage: Boolean): Long? { - val storage = MessagingModuleConfiguration.shared.storage - val threadId = message.threadID - ?: run { - val address = if (isSyncMessage && message is VisibleMessage) message.syncTarget else message.recipient - storage.getThreadId(Address.fromSerialized(address!!)) ?: return null - } - val config = storage.getExpirationConfiguration(threadId)?.takeIf { it.isEnabled } ?: return null - val expiryMode = config.expiryMode - return if (expiryMode is ExpiryMode.AfterSend || isSyncMessage) { - expiryMode.expiryMillis - } else null - } + private fun getSpecifiedTtl( + message: Message, + isSyncMessage: Boolean + ): Long? = message.takeUnless { it is ClosedGroupControlMessage }?.run { + threadID ?: (if (isSyncMessage && this is VisibleMessage) syncTarget else recipient) + ?.let(Address.Companion::fromSerialized) + ?.let(MessagingModuleConfiguration.shared.storage::getThreadId) + }?.let(MessagingModuleConfiguration.shared.storage::getExpirationConfiguration) + ?.takeIf { it.isEnabled } + ?.expiryMode + ?.takeIf { it is ExpiryMode.AfterSend || isSyncMessage } + ?.expiryMillis // Open Groups private fun sendToOpenGroupDestination(destination: Destination, message: Message): Promise {