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

View File

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

View File

@ -486,10 +486,16 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
setPinned(ourThread, userProfile.getNtsPriority() > 0)
}
// Set or reset the shared library to use latest expiration config
getThreadId(recipient)?.let { ourThread ->
val currentExpiration = getExpirationConfiguration(ourThread)
if (currentExpiration != null && currentExpiration.updatedTimestampMs > messageTimestamp) {
setExpirationConfiguration(currentExpiration)
} else {
val expiration = ExpirationConfiguration(ourThread, userProfile.getNtsExpiry(), messageTimestamp)
DatabaseComponent.get(context).expirationConfigurationDatabase().setExpirationConfiguration(expiration)
}
}
}
@ -622,6 +628,11 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
ClosedGroupPollerV2.shared.startPolling(group.sessionId)
}
getThreadId(Address.fromSerialized(groupId))?.let { conversationThreadId ->
val currentExpiration = getExpirationConfiguration(conversationThreadId)
if (currentExpiration != null && currentExpiration.updatedTimestampMs > messageTimestamp) {
setExpirationConfiguration(currentExpiration)
} else {
val mode =
if (group.disappearingTimer == 0L) ExpiryMode.NONE
else ExpiryMode.AfterRead(group.disappearingTimer)
@ -634,6 +645,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
}
}
}
}
override fun setAuthToken(room: String, server: String, newValue: String) {
val id = "$server.$room"
@ -1221,6 +1233,10 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
}
}
getThreadId(recipient)?.let { conversationThreadId ->
val currentExpiration = getExpirationConfiguration(conversationThreadId)
if (currentExpiration != null && currentExpiration.updatedTimestampMs > timestamp) {
setExpirationConfiguration(currentExpiration)
} else {
val expiration = ExpirationConfiguration(
conversationThreadId,
contact.expiryMode,
@ -1229,6 +1245,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
DatabaseComponent.get(context).expirationConfigurationDatabase()
.setExpirationConfiguration(expiration)
}
}
setRecipientHash(recipient, contact.hashCode().toString())
}
}