From 64e9324aa090ec9fe8b81c6d0ca707b8367eb422 Mon Sep 17 00:00:00 2001 From: Cody Henthorne Date: Wed, 10 Jan 2024 11:53:08 -0500 Subject: [PATCH] Default new notification profiles to allow calls. --- .../profiles/AddAllowedMembersFragment.kt | 33 +++++++++++++++++++ .../profiles/AddAllowedMembersViewModel.kt | 10 ++++++ .../NotificationProfileDetailsViewModel.kt | 13 ++------ .../NotificationProfilesRepository.kt | 16 +++++++++ .../database/NotificationProfileTables.kt | 4 ++- .../profiles/NotificationProfile.kt | 2 +- app/src/main/res/values/strings.xml | 6 ++++ 7 files changed, 71 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/AddAllowedMembersFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/AddAllowedMembersFragment.kt index 0220b5d7b5..540661a871 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/AddAllowedMembersFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/AddAllowedMembersFragment.kt @@ -7,9 +7,12 @@ import androidx.navigation.fragment.findNavController import com.google.android.material.snackbar.Snackbar import io.reactivex.rxjava3.kotlin.subscribeBy import org.signal.core.util.concurrent.LifecycleDisposable +import org.signal.core.util.logging.Log import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.components.settings.DSLConfiguration import org.thoughtcrime.securesms.components.settings.DSLSettingsFragment +import org.thoughtcrime.securesms.components.settings.DSLSettingsIcon +import org.thoughtcrime.securesms.components.settings.DSLSettingsText import org.thoughtcrime.securesms.components.settings.app.notifications.profiles.models.NotificationProfileAddMembers import org.thoughtcrime.securesms.components.settings.app.notifications.profiles.models.NotificationProfileRecipient import org.thoughtcrime.securesms.components.settings.configure @@ -93,6 +96,32 @@ class AddAllowedMembersFragment : DSLSettingsFragment(layoutId = R.layout.fragme ) ) } + + sectionHeaderPref(R.string.AddAllowedMembers__exceptions) + + switchPref( + title = DSLSettingsText.from(R.string.AddAllowedMembers__allow_all_calls), + icon = DSLSettingsIcon.from(R.drawable.symbol_phone_24), + isChecked = profile.allowAllCalls, + onClick = { + lifecycleDisposable += viewModel.toggleAllowAllCalls() + .subscribeBy( + onError = { Log.w(TAG, "Error updating profile", it) } + ) + } + ) + + switchPref( + title = DSLSettingsText.from(R.string.AddAllowedMembers__notify_for_all_mentions), + icon = DSLSettingsIcon.from(R.drawable.symbol_at_24), + isChecked = profile.allowAllMentions, + onClick = { + lifecycleDisposable += viewModel.toggleAllowAllMentions() + .subscribeBy( + onError = { Log.w(TAG, "Error updating profile", it) } + ) + } + ) } } @@ -100,4 +129,8 @@ class AddAllowedMembersFragment : DSLSettingsFragment(layoutId = R.layout.fragme lifecycleDisposable += viewModel.addMember(id) .subscribe() } + + companion object { + private val TAG = Log.tag(AddAllowedMembersFragment::class.java) + } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/AddAllowedMembersViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/AddAllowedMembersViewModel.kt index b52e131b68..2248f46a55 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/AddAllowedMembersViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/AddAllowedMembersViewModel.kt @@ -30,6 +30,16 @@ class AddAllowedMembersViewModel(private val profileId: Long, private val reposi .observeOn(AndroidSchedulers.mainThread()) } + fun toggleAllowAllMentions(): Single { + return repository.toggleAllowAllMentions(profileId) + .observeOn(AndroidSchedulers.mainThread()) + } + + fun toggleAllowAllCalls(): Single { + return repository.toggleAllowAllCalls(profileId) + .observeOn(AndroidSchedulers.mainThread()) + } + data class NotificationProfileAndRecipients(val profile: NotificationProfile, val recipients: List) class Factory(private val profileId: Long) : ViewModelProvider.Factory { diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfileDetailsViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfileDetailsViewModel.kt index 38a7ced8c3..ef02b10263 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfileDetailsViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfileDetailsViewModel.kt @@ -9,7 +9,6 @@ import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import io.reactivex.rxjava3.kotlin.subscribeBy -import org.thoughtcrime.securesms.database.NotificationProfileDatabase import org.thoughtcrime.securesms.notifications.profiles.NotificationProfile import org.thoughtcrime.securesms.notifications.profiles.NotificationProfiles import org.thoughtcrime.securesms.recipients.Recipient @@ -84,20 +83,12 @@ class NotificationProfileDetailsViewModel(private val profileId: Long, private v } fun toggleAllowAllMentions(): Single { - return repository.getProfile(profileId) - .take(1) - .singleOrError() - .flatMap { repository.updateProfile(it.copy(allowAllMentions = !it.allowAllMentions)) } - .map { (it as NotificationProfileDatabase.NotificationProfileChangeResult.Success).notificationProfile } + return repository.toggleAllowAllMentions(profileId) .observeOn(AndroidSchedulers.mainThread()) } fun toggleAllowAllCalls(): Single { - return repository.getProfile(profileId) - .take(1) - .singleOrError() - .flatMap { repository.updateProfile(it.copy(allowAllCalls = !it.allowAllCalls)) } - .map { (it as NotificationProfileDatabase.NotificationProfileChangeResult.Success).notificationProfile } + return repository.toggleAllowAllCalls(profileId) .observeOn(AndroidSchedulers.mainThread()) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfilesRepository.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfilesRepository.kt index eeddaaf7ea..7279c842f8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfilesRepository.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfilesRepository.kt @@ -94,6 +94,22 @@ class NotificationProfilesRepository { .subscribeOn(Schedulers.io()) } + fun toggleAllowAllMentions(profileId: Long): Single { + return getProfile(profileId) + .take(1) + .singleOrError() + .flatMap { updateProfile(it.copy(allowAllMentions = !it.allowAllMentions)) } + .map { (it as NotificationProfileDatabase.NotificationProfileChangeResult.Success).notificationProfile } + } + + fun toggleAllowAllCalls(profileId: Long): Single { + return getProfile(profileId) + .take(1) + .singleOrError() + .flatMap { updateProfile(it.copy(allowAllCalls = !it.allowAllCalls)) } + .map { (it as NotificationProfileDatabase.NotificationProfileChangeResult.Success).notificationProfile } + } + fun manuallyToggleProfile(profile: NotificationProfile, now: Long = System.currentTimeMillis()): Completable { return manuallyToggleProfile(profile.id, profile.schedule, now) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/NotificationProfileTables.kt b/app/src/main/java/org/thoughtcrime/securesms/database/NotificationProfileTables.kt index 136a3989c1..422445c8ee 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/NotificationProfileTables.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/NotificationProfileTables.kt @@ -111,6 +111,7 @@ class NotificationProfileDatabase(context: Context, databaseHelper: SignalDataba put(NotificationProfileTable.EMOJI, emoji) put(NotificationProfileTable.COLOR, color.serialize()) put(NotificationProfileTable.CREATED_AT, createdAt) + put(NotificationProfileTable.ALLOW_ALL_CALLS, 1) } val profileId = db.insert(NotificationProfileTable.TABLE_NAME, null, profileValues) @@ -134,7 +135,8 @@ class NotificationProfileDatabase(context: Context, databaseHelper: SignalDataba name = name, emoji = emoji, createdAt = createdAt, - schedule = getProfileSchedule(profileId) + schedule = getProfileSchedule(profileId), + allowAllCalls = true ) ) } finally { diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfile.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfile.kt index 5b567b7d78..822bf7e26e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfile.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfile.kt @@ -9,7 +9,7 @@ data class NotificationProfile( val emoji: String, val color: AvatarColor = AvatarColor.A210, val createdAt: Long, - val allowAllCalls: Boolean = false, + val allowAllCalls: Boolean = true, val allowAllMentions: Boolean = false, val schedule: NotificationProfileSchedule, val allowedMembers: Set = emptySet() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8f95bc1dcb..ad722a8c7e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -5079,6 +5079,12 @@ Add people and groups you want notifications and calls from when this profile is on Add people or groups + + Exceptions + + Allow all calls + + Notify for all mentions Add