Fix duplicate notification channels being created.
This commit is contained in:
parent
130b796564
commit
ba54051f8c
7 changed files with 51 additions and 20 deletions
|
@ -32,9 +32,14 @@ class SoundsAndNotificationsSettingsFragment : DSLSettingsFragment(
|
|||
}
|
||||
)
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
viewModel.channelConsistencyCheck()
|
||||
}
|
||||
|
||||
override fun bindAdapter(adapter: DSLSettingsAdapter) {
|
||||
viewModel.state.observe(viewLifecycleOwner) { state ->
|
||||
if (state.recipientId != Recipient.UNKNOWN.id) {
|
||||
if (state.channelConsistencyCheckComplete && state.recipientId != Recipient.UNKNOWN.id) {
|
||||
adapter.submitList(getConfiguration(state).toMappingModelList())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,15 @@ import org.thoughtcrime.securesms.recipients.RecipientId
|
|||
|
||||
class SoundsAndNotificationsSettingsRepository(private val context: Context) {
|
||||
|
||||
fun ensureCustomChannelConsistency(complete: () -> Unit) {
|
||||
SignalExecutors.BOUNDED.execute {
|
||||
if (NotificationChannels.supported()) {
|
||||
NotificationChannels.ensureCustomChannelConsistency(context)
|
||||
}
|
||||
complete()
|
||||
}
|
||||
}
|
||||
|
||||
fun setMuteUntil(recipientId: RecipientId, muteUntil: Long) {
|
||||
SignalExecutors.BOUNDED.execute {
|
||||
SignalDatabase.recipients.setMuted(recipientId, muteUntil)
|
||||
|
|
|
@ -9,5 +9,6 @@ data class SoundsAndNotificationsSettingsState(
|
|||
val muteUntil: Long = 0L,
|
||||
val mentionSetting: RecipientDatabase.MentionSetting = RecipientDatabase.MentionSetting.DO_NOT_NOTIFY,
|
||||
val hasCustomNotificationSettings: Boolean = false,
|
||||
val hasMentionsSupport: Boolean = false
|
||||
val hasMentionsSupport: Boolean = false,
|
||||
val channelConsistencyCheckComplete: Boolean = false
|
||||
)
|
||||
|
|
|
@ -42,6 +42,13 @@ class SoundsAndNotificationsSettingsViewModel(
|
|||
repository.setMentionSetting(recipientId, mentionSetting)
|
||||
}
|
||||
|
||||
fun channelConsistencyCheck() {
|
||||
store.update { s -> s.copy(channelConsistencyCheckComplete = false) }
|
||||
repository.ensureCustomChannelConsistency {
|
||||
store.update { s -> s.copy(channelConsistencyCheckComplete = true) }
|
||||
}
|
||||
}
|
||||
|
||||
class Factory(
|
||||
private val recipientId: RecipientId,
|
||||
private val repository: SoundsAndNotificationsSettingsRepository
|
||||
|
|
|
@ -42,6 +42,11 @@ class CustomNotificationsSettingsFragment : DSLSettingsFragment(R.string.CustomN
|
|||
return CustomNotificationsSettingsViewModel.Factory(recipientId, repository)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
viewModel.channelConsistencyCheck()
|
||||
}
|
||||
|
||||
override fun bindAdapter(adapter: DSLSettingsAdapter) {
|
||||
messageSoundResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
handleResult(result, viewModel::setMessageSound)
|
||||
|
|
|
@ -17,19 +17,20 @@ class CustomNotificationsSettingsRepository(context: Context) {
|
|||
private val context = context.applicationContext
|
||||
private val executor = SerialExecutor(SignalExecutors.BOUNDED)
|
||||
|
||||
fun initialize(recipientId: RecipientId, onInitializationComplete: () -> Unit) {
|
||||
fun ensureCustomChannelConsistency(recipientId: RecipientId, onComplete: () -> Unit) {
|
||||
executor.execute {
|
||||
val recipient = Recipient.resolved(recipientId)
|
||||
val database = SignalDatabase.recipients
|
||||
|
||||
if (NotificationChannels.supported() && recipient.notificationChannel != null) {
|
||||
database.setMessageRingtone(recipient.id, NotificationChannels.getMessageRingtone(context, recipient))
|
||||
database.setMessageVibrate(recipient.id, RecipientDatabase.VibrateState.fromBoolean(NotificationChannels.getMessageVibrate(context, recipient)))
|
||||
|
||||
if (NotificationChannels.supported()) {
|
||||
NotificationChannels.ensureCustomChannelConsistency(context)
|
||||
|
||||
val recipient = Recipient.resolved(recipientId)
|
||||
val database = SignalDatabase.recipients
|
||||
if (recipient.notificationChannel != null) {
|
||||
database.setMessageRingtone(recipient.id, NotificationChannels.getMessageRingtone(context, recipient))
|
||||
database.setMessageVibrate(recipient.id, RecipientDatabase.VibrateState.fromBoolean(NotificationChannels.getMessageVibrate(context, recipient)))
|
||||
}
|
||||
}
|
||||
|
||||
onInitializationComplete()
|
||||
onComplete()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,15 +22,6 @@ class CustomNotificationsSettingsViewModel(
|
|||
val state: LiveData<CustomNotificationsSettingsState> = store.stateLiveData
|
||||
|
||||
init {
|
||||
repository.initialize(recipientId) {
|
||||
store.update {
|
||||
it.copy(
|
||||
isInitialLoadComplete = true,
|
||||
controlsEnabled = (!NotificationChannels.supported() || it.hasCustomNotifications)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
store.update(Recipient.live(recipientId).liveData) { recipient, state ->
|
||||
val recipientHasCustomNotifications = NotificationChannels.supported() && recipient.notificationChannel != null
|
||||
state.copy(
|
||||
|
@ -70,6 +61,18 @@ class CustomNotificationsSettingsViewModel(
|
|||
repository.setCallSound(recipientId, uri)
|
||||
}
|
||||
|
||||
fun channelConsistencyCheck() {
|
||||
store.update { it.copy(isInitialLoadComplete = false) }
|
||||
repository.ensureCustomChannelConsistency(recipientId) {
|
||||
store.update {
|
||||
it.copy(
|
||||
isInitialLoadComplete = true,
|
||||
controlsEnabled = (!NotificationChannels.supported() || it.hasCustomNotifications)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Factory(
|
||||
private val recipientId: RecipientId,
|
||||
private val repository: CustomNotificationsSettingsRepository
|
||||
|
|
Loading…
Add table
Reference in a new issue