fix: issue for overwriting local config with an outdated user config merge

This commit is contained in:
0x330a 2023-08-04 16:11:18 +10:00
parent 8db92cc55c
commit 2e3d50364c
3 changed files with 41 additions and 20 deletions

View File

@ -25,6 +25,7 @@ import org.thoughtcrime.securesms.database.RecipientDatabase
import org.thoughtcrime.securesms.database.ThreadDatabase import org.thoughtcrime.securesms.database.ThreadDatabase
import org.thoughtcrime.securesms.preferences.RadioOption import org.thoughtcrime.securesms.preferences.RadioOption
import org.thoughtcrime.securesms.preferences.RadioOptionAdapter import org.thoughtcrime.securesms.preferences.RadioOptionAdapter
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
import javax.inject.Inject import javax.inject.Inject
import kotlin.math.max import kotlin.math.max
@ -116,10 +117,9 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() {
viewModel.uiState.collect { uiState -> viewModel.uiState.collect { uiState ->
when (uiState.settingsSaved) { when (uiState.settingsSaved) {
true -> { true -> {
showToast(getString(R.string.ExpirationSettingsActivity_settings_updated)) ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(this@ExpirationSettingsActivity)
finish() finish()
} }
false -> showToast(getString(R.string.ExpirationSettingsActivity_settings_not_updated)) false -> showToast(getString(R.string.ExpirationSettingsActivity_settings_not_updated))
else -> {} else -> {}
} }

View File

@ -540,6 +540,9 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
} }
} }
updatePlaceholder() updatePlaceholder()
viewModel.recipient?.let {
maybeUpdateToolbar(recipient = it)
}
} }
override fun onLoaderReset(cursor: Loader<Cursor>) { override fun onLoaderReset(cursor: Loader<Cursor>) {
@ -859,6 +862,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
private fun isMessageRequestThread(): Boolean { private fun isMessageRequestThread(): Boolean {
val recipient = viewModel.recipient ?: return false val recipient = viewModel.recipient ?: return false
if (recipient.isLocalNumber) return false
return !recipient.isGroupRecipient && !recipient.isApproved return !recipient.isGroupRecipient && !recipient.isApproved
} }

View File

@ -486,9 +486,15 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
setPinned(ourThread, userProfile.getNtsPriority() > 0) setPinned(ourThread, userProfile.getNtsPriority() > 0)
} }
// Set or reset the shared library to use latest expiration config
getThreadId(recipient)?.let { ourThread -> getThreadId(recipient)?.let { ourThread ->
val expiration = ExpirationConfiguration(ourThread, userProfile.getNtsExpiry(), messageTimestamp) val currentExpiration = getExpirationConfiguration(ourThread)
DatabaseComponent.get(context).expirationConfigurationDatabase().setExpirationConfiguration(expiration) if (currentExpiration != null && currentExpiration.updatedTimestampMs > messageTimestamp) {
setExpirationConfiguration(currentExpiration)
} else {
val expiration = ExpirationConfiguration(ourThread, userProfile.getNtsExpiry(), messageTimestamp)
DatabaseComponent.get(context).expirationConfigurationDatabase().setExpirationConfiguration(expiration)
}
} }
} }
@ -622,15 +628,21 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
ClosedGroupPollerV2.shared.startPolling(group.sessionId) ClosedGroupPollerV2.shared.startPolling(group.sessionId)
} }
getThreadId(Address.fromSerialized(groupId))?.let { conversationThreadId -> getThreadId(Address.fromSerialized(groupId))?.let { conversationThreadId ->
val mode =
if (group.disappearingTimer == 0L) ExpiryMode.NONE val currentExpiration = getExpirationConfiguration(conversationThreadId)
else ExpiryMode.AfterRead(group.disappearingTimer) if (currentExpiration != null && currentExpiration.updatedTimestampMs > messageTimestamp) {
val newConfig = ExpirationConfiguration( setExpirationConfiguration(currentExpiration)
conversationThreadId, mode, messageTimestamp } else {
) val mode =
DatabaseComponent.get(context) if (group.disappearingTimer == 0L) ExpiryMode.NONE
.expirationConfigurationDatabase() else ExpiryMode.AfterRead(group.disappearingTimer)
.setExpirationConfiguration(newConfig) val newConfig = ExpirationConfiguration(
conversationThreadId, mode, messageTimestamp
)
DatabaseComponent.get(context)
.expirationConfigurationDatabase()
.setExpirationConfiguration(newConfig)
}
} }
} }
} }
@ -1221,13 +1233,18 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
} }
} }
getThreadId(recipient)?.let { conversationThreadId -> getThreadId(recipient)?.let { conversationThreadId ->
val expiration = ExpirationConfiguration( val currentExpiration = getExpirationConfiguration(conversationThreadId)
conversationThreadId, if (currentExpiration != null && currentExpiration.updatedTimestampMs > timestamp) {
contact.expiryMode, setExpirationConfiguration(currentExpiration)
timestamp } else {
) val expiration = ExpirationConfiguration(
DatabaseComponent.get(context).expirationConfigurationDatabase() conversationThreadId,
.setExpirationConfiguration(expiration) contact.expiryMode,
timestamp
)
DatabaseComponent.get(context).expirationConfigurationDatabase()
.setExpirationConfiguration(expiration)
}
} }
setRecipientHash(recipient, contact.hashCode().toString()) setRecipientHash(recipient, contact.hashCode().toString())
} }