From 106305f118c131b8d7696aa9dea6a48d863bffd6 Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Thu, 18 Jan 2024 13:46:46 +1100 Subject: [PATCH] fix: outdated banner showing and updating on messages properly --- .../conversation/v2/ConversationActivityV2.kt | 13 ++++++++----- .../org/thoughtcrime/securesms/database/Storage.kt | 6 +++++- .../sending_receiving/ReceivedMessageHandler.kt | 11 +++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 9678bf20cd..201c6c94dd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -537,6 +537,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe updatePlaceholder() viewModel.recipient?.let { maybeUpdateToolbar(recipient = it) + setUpOutdatedClientBanner() } } @@ -697,12 +698,14 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe private fun setUpOutdatedClientBanner() { val legacyRecipient = viewModel.legacyBannerRecipient(this) - if (ExpirationConfiguration.isNewConfigEnabled && - legacyRecipient != null - ) { + + val shouldShowLegacy = ExpirationConfiguration.isNewConfigEnabled && + legacyRecipient != null + + binding?.outdatedBanner?.isVisible = shouldShowLegacy + if (shouldShowLegacy) { binding?.outdatedBannerTextView?.text = - resources.getString(R.string.activity_conversation_outdated_client_banner_text, legacyRecipient.name) - binding?.outdatedBanner?.isVisible = true + resources.getString(R.string.activity_conversation_outdated_client_banner_text, legacyRecipient!!.name) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index f37f9b5b63..dca386a7b6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -30,7 +30,6 @@ import org.session.libsession.messaging.jobs.MessageSendJob import org.session.libsession.messaging.jobs.RetrieveProfileAvatarJob import org.session.libsession.messaging.messages.Destination import org.session.libsession.messaging.messages.ExpirationConfiguration -import org.session.libsession.messaging.messages.ExpirationConfiguration.Companion.isNewConfigEnabled import org.session.libsession.messaging.messages.Message import org.session.libsession.messaging.messages.control.ConfigurationMessage import org.session.libsession.messaging.messages.control.MessageRequestResponse @@ -1733,6 +1732,11 @@ open class Storage( if (currentConfig != null && currentConfig.updatedTimestampMs >= config.updatedTimestampMs) return val expiryMode = config.expiryMode + if (expiryMode == ExpiryMode.NONE) { + // Clear the legacy recipients on updating config to be none + DatabaseComponent.get(context).lokiAPIDatabase().setLastLegacySenderAddress(recipient.address.serialize(), null) + } + if (recipient.isClosedGroupRecipient) { val userGroups = configFactory.userGroups ?: return val groupPublicKey = GroupUtil.addressToGroupSessionId(recipient.address) diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt index 53ad3da19d..0d856c06fe 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt @@ -335,6 +335,17 @@ fun MessageReceiver.handleVisibleMessage( if (userPublicKey != messageSender && !isUserBlindedSender) { storage.setBlocksCommunityMessageRequests(recipient, message.blocksMessageRequests) } + + // update the disappearing / legacy banner for the sender + val disappearingState = when { + proto.dataMessage.expireTimer > 0 && !proto.hasExpirationType() -> Recipient.DisappearingState.LEGACY + else -> Recipient.DisappearingState.UPDATED + } + storage.updateDisappearingState( + messageSender, + threadID, + disappearingState + ) } // Parse quote if needed var quoteModel: QuoteModel? = null