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,9 +486,15 @@ 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 expiration = ExpirationConfiguration(ourThread, userProfile.getNtsExpiry(), messageTimestamp)
DatabaseComponent.get(context).expirationConfigurationDatabase().setExpirationConfiguration(expiration)
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,15 +628,21 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
ClosedGroupPollerV2.shared.startPolling(group.sessionId)
}
getThreadId(Address.fromSerialized(groupId))?.let { conversationThreadId ->
val mode =
if (group.disappearingTimer == 0L) ExpiryMode.NONE
else ExpiryMode.AfterRead(group.disappearingTimer)
val newConfig = ExpirationConfiguration(
conversationThreadId, mode, messageTimestamp
)
DatabaseComponent.get(context)
.expirationConfigurationDatabase()
.setExpirationConfiguration(newConfig)
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)
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 ->
val expiration = ExpirationConfiguration(
conversationThreadId,
contact.expiryMode,
timestamp
)
DatabaseComponent.get(context).expirationConfigurationDatabase()
.setExpirationConfiguration(expiration)
val currentExpiration = getExpirationConfiguration(conversationThreadId)
if (currentExpiration != null && currentExpiration.updatedTimestampMs > timestamp) {
setExpirationConfiguration(currentExpiration)
} else {
val expiration = ExpirationConfiguration(
conversationThreadId,
contact.expiryMode,
timestamp
)
DatabaseComponent.get(context).expirationConfigurationDatabase()
.setExpirationConfiguration(expiration)
}
}
setRecipientHash(recipient, contact.hashCode().toString())
}