mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 16:33:39 +00:00
refactor: add sender to be the person to trigger the legacy message send (in case of closed group updates)
This commit is contained in:
parent
d12bce54bd
commit
56878dbd35
@ -92,7 +92,6 @@ import org.session.libsession.utilities.Stub
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.session.libsession.utilities.concurrent.SimpleTask
|
||||
import org.session.libsession.utilities.recipients.Recipient
|
||||
import org.session.libsession.utilities.recipients.Recipient.DisappearingState
|
||||
import org.session.libsession.utilities.recipients.RecipientModifiedListener
|
||||
import org.session.libsignal.crypto.MnemonicCodec
|
||||
import org.session.libsignal.utilities.IdPrefix
|
||||
@ -697,13 +696,12 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
}
|
||||
|
||||
private fun setUpOutdatedClientBanner() {
|
||||
val recipient = viewModel.recipient?.takeIf { !it.isLocalNumber } ?: return
|
||||
val legacyRecipient = viewModel.legacyBannerRecipient(this)
|
||||
if (ExpirationConfiguration.isNewConfigEnabled &&
|
||||
recipient.disappearingState == DisappearingState.LEGACY &&
|
||||
viewModel.expirationConfiguration?.isEnabled == true
|
||||
legacyRecipient != null
|
||||
) {
|
||||
binding?.outdatedBannerTextView?.text =
|
||||
resources.getString(R.string.activity_conversation_outdated_client_banner_text, recipient.name)
|
||||
resources.getString(R.string.activity_conversation_outdated_client_banner_text, legacyRecipient.name)
|
||||
binding?.outdatedBanner?.isVisible = true
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.thoughtcrime.securesms.conversation.v2
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
@ -17,6 +18,7 @@ import org.session.libsession.messaging.open_groups.OpenGroup
|
||||
import org.session.libsession.messaging.open_groups.OpenGroupApi
|
||||
import org.session.libsession.messaging.utilities.SessionId
|
||||
import org.session.libsession.messaging.utilities.SodiumUtilities
|
||||
import org.session.libsession.utilities.Address
|
||||
import org.session.libsession.utilities.recipients.Recipient
|
||||
import org.session.libsignal.utilities.IdPrefix
|
||||
import org.session.libsignal.utilities.Log
|
||||
@ -221,6 +223,11 @@ class ConversationViewModel(
|
||||
fun hidesInputBar(): Boolean = openGroup?.canWrite != true &&
|
||||
blindedRecipient?.blocksCommunityMessageRequests == true
|
||||
|
||||
fun legacyBannerRecipient(context: Context): Recipient? = recipient?.let { recipient ->
|
||||
val legacyAddress = storage.getLastLegacyRecipient(recipient.address.serialize()) ?: return@let null
|
||||
return Recipient.from(context, Address.fromSerialized(legacyAddress), false)
|
||||
}
|
||||
|
||||
|
||||
@dagger.assisted.AssistedFactory
|
||||
interface AssistedFactory {
|
||||
|
@ -67,6 +67,7 @@ import org.session.libsession.utilities.ProfileKeyUtil
|
||||
import org.session.libsession.utilities.SSKEnvironment
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.session.libsession.utilities.recipients.Recipient
|
||||
import org.session.libsession.utilities.recipients.Recipient.DisappearingState
|
||||
import org.session.libsignal.crypto.ecc.DjbECPrivateKey
|
||||
import org.session.libsignal.crypto.ecc.DjbECPublicKey
|
||||
import org.session.libsignal.crypto.ecc.ECKeyPair
|
||||
@ -1345,6 +1346,14 @@ open class Storage(
|
||||
threadDb.setDate(threadId, newDate)
|
||||
}
|
||||
|
||||
override fun getLastLegacyRecipient(threadRecipient: String): String? {
|
||||
return DatabaseComponent.get(context).lokiAPIDatabase().getLastLegacySenderAddress(threadRecipient)
|
||||
}
|
||||
|
||||
override fun setLastLegacyRecipient(threadRecipient: String, senderRecipient: String?) {
|
||||
DatabaseComponent.get(context).lokiAPIDatabase().setLastLegacySenderAddress(threadRecipient, senderRecipient)
|
||||
}
|
||||
|
||||
override fun deleteConversation(threadID: Long) {
|
||||
val recipient = getRecipientForThread(threadID)
|
||||
val threadDB = DatabaseComponent.get(context).threadDatabase()
|
||||
@ -1759,10 +1768,18 @@ open class Storage(
|
||||
return expiringMessages
|
||||
}
|
||||
|
||||
override fun updateDisappearingState(threadID: Long, disappearingState: Recipient.DisappearingState) {
|
||||
override fun updateDisappearingState(
|
||||
messageSender: String,
|
||||
threadID: Long,
|
||||
disappearingState: Recipient.DisappearingState
|
||||
) {
|
||||
val threadDb = DatabaseComponent.get(context).threadDatabase()
|
||||
val recipient = threadDb.getRecipientForThreadId(threadID) ?: return
|
||||
val recipientDb = DatabaseComponent.get(context).recipientDatabase()
|
||||
recipientDb.setDisappearingState(recipient, disappearingState);
|
||||
if (disappearingState == DisappearingState.LEGACY) {
|
||||
DatabaseComponent.get(context).lokiAPIDatabase()
|
||||
.setLastLegacySenderAddress(recipient.address.serialize(), messageSender)
|
||||
}
|
||||
}
|
||||
}
|
@ -175,6 +175,8 @@ interface StorageProtocol {
|
||||
fun isPinned(threadID: Long): Boolean
|
||||
fun deleteConversation(threadID: Long)
|
||||
fun setThreadDate(threadId: Long, newDate: Long)
|
||||
fun getLastLegacyRecipient(threadRecipient: String): String?
|
||||
fun setLastLegacyRecipient(threadRecipient: String, senderRecipient: String?)
|
||||
|
||||
// Contacts
|
||||
fun getContactWithSessionID(sessionID: String): Contact?
|
||||
@ -226,7 +228,11 @@ interface StorageProtocol {
|
||||
fun getExpirationConfiguration(threadId: Long): ExpirationConfiguration?
|
||||
fun setExpirationConfiguration(config: ExpirationConfiguration)
|
||||
fun getExpiringMessages(messageIds: List<Long> = emptyList()): List<Pair<Long, Long>>
|
||||
fun updateDisappearingState(threadID: Long, disappearingState: Recipient.DisappearingState)
|
||||
fun updateDisappearingState(
|
||||
messageSender: String,
|
||||
threadID: Long,
|
||||
disappearingState: Recipient.DisappearingState
|
||||
)
|
||||
|
||||
// Shared configs
|
||||
fun notifyConfigUpdates(forConfigObject: ConfigBase, messageTimestamp: Long)
|
||||
|
@ -307,7 +307,7 @@ fun MessageReceiver.updateExpiryIfNeeded(
|
||||
|
||||
if (!recipient.isGroupRecipient && !recipient.isLocalNumber) {
|
||||
val disappearingState = if (proto.hasExpirationType()) Recipient.DisappearingState.UPDATED else Recipient.DisappearingState.LEGACY
|
||||
storage.updateDisappearingState(threadID, disappearingState)
|
||||
storage.updateDisappearingState(message.sender!!, threadID, disappearingState)
|
||||
}
|
||||
|
||||
remoteConfig.takeIf { localConfig == null || it.updatedTimestampMs > localConfig.updatedTimestampMs }
|
||||
|
Loading…
x
Reference in New Issue
Block a user