Skip to content

Commit

Permalink
Merge pull request #8114 from vector-im/feature/fre/poll_new_push_rules
Browse files Browse the repository at this point in the history
[Poll] Synchronize polls push rules with message push rules (PSG-954)
  • Loading branch information
Florian14 authored Feb 17, 2023
2 parents 3bb1983 + 0a0ad2d commit f887acd
Show file tree
Hide file tree
Showing 35 changed files with 741 additions and 184 deletions.
1 change: 1 addition & 0 deletions changelog.d/8007.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Poll] Synchronize polls push rules with message push rules
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,36 @@ object RuleIds {
const val RULE_ID_ALL_OTHER_MESSAGES_ROOMS = ".m.rule.message"
const val RULE_ID_ENCRYPTED = ".m.rule.encrypted"

const val RULE_ID_POLL_START_ONE_TO_ONE = ".m.rule.poll_start_one_to_one"
const val RULE_ID_POLL_START_ONE_TO_ONE_UNSTABLE = ".org.matrix.msc3930.rule.poll_start_one_to_one"
const val RULE_ID_POLL_END_ONE_TO_ONE = ".m.rule.poll_end_one_to_one"
const val RULE_ID_POLL_END_ONE_TO_ONE_UNSTABLE = ".org.matrix.msc3930.rule.poll_end_one_to_one"

const val RULE_ID_POLL_START = ".m.rule.poll_start"
const val RULE_ID_POLL_START_UNSTABLE = ".org.matrix.msc3930.rule.poll_start"
const val RULE_ID_POLL_END = ".m.rule.poll_end"
const val RULE_ID_POLL_END_UNSTABLE = ".org.matrix.msc3930.rule.poll_end"

// Not documented
const val RULE_ID_FALLBACK = ".m.rule.fallback"

const val RULE_ID_REACTION = ".m.rule.reaction"

fun getSyncedRules(ruleId: String): List<String> {
return when (ruleId) {
RULE_ID_ONE_TO_ONE_ROOM -> listOf(
RULE_ID_POLL_START_ONE_TO_ONE,
RULE_ID_POLL_START_ONE_TO_ONE_UNSTABLE,
RULE_ID_POLL_END_ONE_TO_ONE,
RULE_ID_POLL_END_ONE_TO_ONE_UNSTABLE,
)
RULE_ID_ALL_OTHER_MESSAGES_ROOMS -> listOf(
RULE_ID_POLL_START,
RULE_ID_POLL_START_UNSTABLE,
RULE_ID_POLL_END,
RULE_ID_POLL_END_UNSTABLE,
)
else -> emptyList()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,14 @@ data class RuleSet(
* @param ruleId a RULE_ID_XX value
* @return the matched bing rule or null it doesn't exist.
*/
fun findDefaultRule(ruleId: String?): PushRuleAndKind? {
var result: PushRuleAndKind? = null
// sanity check
if (null != ruleId) {
if (RuleIds.RULE_ID_CONTAIN_USER_NAME == ruleId) {
result = findRule(content, ruleId)?.let { PushRuleAndKind(it, RuleSetKey.CONTENT) }
} else {
// assume that the ruleId is unique.
result = findRule(override, ruleId)?.let { PushRuleAndKind(it, RuleSetKey.OVERRIDE) }
if (null == result) {
result = findRule(underride, ruleId)?.let { PushRuleAndKind(it, RuleSetKey.UNDERRIDE) }
}
}
fun findDefaultRule(ruleId: String): PushRuleAndKind? {
return if (RuleIds.RULE_ID_CONTAIN_USER_NAME == ruleId) {
findRule(content, ruleId)?.let { PushRuleAndKind(it, RuleSetKey.CONTENT) }
} else {
// assume that the ruleId is unique.
findRule(override, ruleId)?.let { PushRuleAndKind(it, RuleSetKey.OVERRIDE) }
?: findRule(underride, ruleId)?.let { PushRuleAndKind(it, RuleSetKey.UNDERRIDE) }
}
return result
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ internal class DefaultProcessEventForPushTask @Inject constructor(
val allEvents = (newJoinEvents + inviteEvents).filter { event ->
when (event.type) {
in EventType.POLL_START.values,
in EventType.POLL_END.values,
in EventType.STATE_ROOM_BEACON_INFO.values,
EventType.MESSAGE,
EventType.REDACTION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ import im.vector.app.features.settings.ignored.IgnoredUsersViewModel
import im.vector.app.features.settings.labs.VectorSettingsLabsViewModel
import im.vector.app.features.settings.legals.LegalsViewModel
import im.vector.app.features.settings.locale.LocalePickerViewModel
import im.vector.app.features.settings.notifications.VectorSettingsNotificationPreferenceViewModel
import im.vector.app.features.settings.notifications.VectorSettingsNotificationViewModel
import im.vector.app.features.settings.notifications.VectorSettingsPushRuleNotificationViewModel
import im.vector.app.features.settings.push.PushGatewaysViewModel
import im.vector.app.features.settings.threepids.ThreePidsSettingsViewModel
import im.vector.app.features.share.IncomingShareViewModel
Expand Down Expand Up @@ -690,9 +691,16 @@ interface MavericksViewModelModule {

@Binds
@IntoMap
@MavericksViewModelKey(VectorSettingsNotificationPreferenceViewModel::class)
@MavericksViewModelKey(VectorSettingsNotificationViewModel::class)
fun vectorSettingsNotificationPreferenceViewModelFactory(
factory: VectorSettingsNotificationPreferenceViewModel.Factory
factory: VectorSettingsNotificationViewModel.Factory
): MavericksAssistedViewModelFactory<*, *>

@Binds
@IntoMap
@MavericksViewModelKey(VectorSettingsPushRuleNotificationViewModel::class)
fun vectorSettingsPushRuleNotificationPreferenceViewModelFactory(
factory: VectorSettingsPushRuleNotificationViewModel.Factory
): MavericksAssistedViewModelFactory<*, *>

@Binds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class NotifiableEventResolver @Inject constructor(
) {

private val nonEncryptedNotifiableEventTypes: List<String> =
listOf(EventType.MESSAGE) + EventType.POLL_START.values + EventType.STATE_ROOM_BEACON_INFO.values
listOf(EventType.MESSAGE) + EventType.POLL_START.values + EventType.POLL_END.values + EventType.STATE_ROOM_BEACON_INFO.values

suspend fun resolveEvent(event: Event, session: Session, isNoisy: Boolean): NotifiableEvent? {
val roomID = event.roomId ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import im.vector.app.databinding.ActivityVectorSettingsBinding
import im.vector.app.features.discovery.DiscoverySettingsFragment
import im.vector.app.features.navigation.SettingsActivityPayload
import im.vector.app.features.settings.devices.VectorSettingsDevicesFragment
import im.vector.app.features.settings.notifications.VectorSettingsNotificationPreferenceFragment
import im.vector.app.features.settings.notifications.VectorSettingsNotificationFragment
import im.vector.app.features.settings.threepids.ThreePidsSettingsFragment
import im.vector.lib.core.utils.compat.getParcelableExtraCompat
import org.matrix.android.sdk.api.failure.GlobalError
Expand Down Expand Up @@ -92,7 +92,7 @@ class VectorSettingsActivity : VectorBaseActivity<ActivityVectorSettingsBinding>
}
SettingsActivityPayload.Notifications -> {
requestHighlightPreferenceKeyOnResume(VectorPreferences.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY)
replaceFragment(views.vectorSettingsPage, VectorSettingsNotificationPreferenceFragment::class.java, null, FRAGMENT_TAG)
replaceFragment(views.vectorSettingsPage, VectorSettingsNotificationFragment::class.java, null, FRAGMENT_TAG)
}
is SettingsActivityPayload.DiscoverySettings -> {
replaceFragment(views.vectorSettingsPage, DiscoverySettingsFragment::class.java, payload, FRAGMENT_TAG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ fun getStandardAction(ruleId: String, index: NotificationIndex): StandardActions
NotificationIndex.SILENT -> StandardActions.Notify
NotificationIndex.NOISY -> StandardActions.Highlight
}
RuleIds.RULE_ID_ONE_TO_ONE_ROOM ->
RuleIds.RULE_ID_ONE_TO_ONE_ROOM,
RuleIds.RULE_ID_POLL_START_ONE_TO_ONE,
RuleIds.RULE_ID_POLL_START_ONE_TO_ONE_UNSTABLE,
RuleIds.RULE_ID_POLL_END_ONE_TO_ONE,
RuleIds.RULE_ID_POLL_END_ONE_TO_ONE_UNSTABLE,
->
when (index) {
NotificationIndex.OFF -> StandardActions.DontNotify
NotificationIndex.SILENT -> StandardActions.Notify
Expand All @@ -50,7 +55,11 @@ fun getStandardAction(ruleId: String, index: NotificationIndex): StandardActions
NotificationIndex.SILENT -> StandardActions.Notify
NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
}
RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS ->
RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS,
RuleIds.RULE_ID_POLL_START,
RuleIds.RULE_ID_POLL_START_UNSTABLE,
RuleIds.RULE_ID_POLL_END,
RuleIds.RULE_ID_POLL_END_UNSTABLE ->
when (index) {
NotificationIndex.OFF -> StandardActions.DontNotify
NotificationIndex.SILENT -> StandardActions.Notify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import javax.inject.Inject

// Referenced in vector_settings_preferences_root.xml
@AndroidEntryPoint
class VectorSettingsNotificationPreferenceFragment :
class VectorSettingsNotificationFragment :
VectorSettingsBaseFragment(),
BackgroundSyncModeChooserDialog.InteractionListener {

Expand All @@ -90,7 +90,7 @@ class VectorSettingsNotificationPreferenceFragment :

private var interactionListener: VectorSettingsFragmentInteractionListener? = null

private val viewModel: VectorSettingsNotificationPreferenceViewModel by fragmentViewModel()
private val viewModel: VectorSettingsNotificationViewModel by fragmentViewModel()

private val notificationStartForActivityResult = registerStartForActivityResult { _ ->
// No op
Expand All @@ -116,10 +116,10 @@ class VectorSettingsNotificationPreferenceFragment :
private fun observeViewEvents() {
viewModel.observeViewEvents {
when (it) {
VectorSettingsNotificationPreferenceViewEvent.NotificationsForDeviceEnabled -> onNotificationsForDeviceEnabled()
VectorSettingsNotificationPreferenceViewEvent.NotificationsForDeviceDisabled -> onNotificationsForDeviceDisabled()
is VectorSettingsNotificationPreferenceViewEvent.AskUserForPushDistributor -> askUserToSelectPushDistributor()
VectorSettingsNotificationPreferenceViewEvent.NotificationMethodChanged -> onNotificationMethodChanged()
VectorSettingsNotificationViewEvent.NotificationsForDeviceEnabled -> onNotificationsForDeviceEnabled()
VectorSettingsNotificationViewEvent.NotificationsForDeviceDisabled -> onNotificationsForDeviceDisabled()
is VectorSettingsNotificationViewEvent.AskUserForPushDistributor -> askUserToSelectPushDistributor()
VectorSettingsNotificationViewEvent.NotificationMethodChanged -> onNotificationMethodChanged()
}
}
}
Expand All @@ -143,9 +143,9 @@ class VectorSettingsNotificationPreferenceFragment :
findPreference<SwitchPreference>(VectorPreferences.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY)
?.setOnPreferenceChangeListener { _, isChecked ->
val action = if (isChecked as Boolean) {
VectorSettingsNotificationPreferenceViewAction.EnableNotificationsForDevice(pushDistributor = "")
VectorSettingsNotificationViewAction.EnableNotificationsForDevice(pushDistributor = "")
} else {
VectorSettingsNotificationPreferenceViewAction.DisableNotificationsForDevice
VectorSettingsNotificationViewAction.DisableNotificationsForDevice
}
viewModel.handle(action)
// preference will be updated on ViewEvent reception
Expand Down Expand Up @@ -231,9 +231,9 @@ class VectorSettingsNotificationPreferenceFragment :
private fun askUserToSelectPushDistributor(withUnregister: Boolean = false) {
unifiedPushHelper.showSelectDistributorDialog(requireContext()) { selection ->
if (withUnregister) {
viewModel.handle(VectorSettingsNotificationPreferenceViewAction.RegisterPushDistributor(selection))
viewModel.handle(VectorSettingsNotificationViewAction.RegisterPushDistributor(selection))
} else {
viewModel.handle(VectorSettingsNotificationPreferenceViewAction.EnableNotificationsForDevice(selection))
viewModel.handle(VectorSettingsNotificationViewAction.EnableNotificationsForDevice(selection))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package im.vector.app.features.settings.notifications

import im.vector.app.core.platform.VectorViewModelAction

sealed interface VectorSettingsNotificationPreferenceViewAction : VectorViewModelAction {
data class EnableNotificationsForDevice(val pushDistributor: String) : VectorSettingsNotificationPreferenceViewAction
object DisableNotificationsForDevice : VectorSettingsNotificationPreferenceViewAction
data class RegisterPushDistributor(val pushDistributor: String) : VectorSettingsNotificationPreferenceViewAction
sealed interface VectorSettingsNotificationViewAction : VectorViewModelAction {
data class EnableNotificationsForDevice(val pushDistributor: String) : VectorSettingsNotificationViewAction
object DisableNotificationsForDevice : VectorSettingsNotificationViewAction
data class RegisterPushDistributor(val pushDistributor: String) : VectorSettingsNotificationViewAction
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package im.vector.app.features.settings.notifications

import im.vector.app.core.platform.VectorViewEvents

sealed interface VectorSettingsNotificationPreferenceViewEvent : VectorViewEvents {
object NotificationsForDeviceEnabled : VectorSettingsNotificationPreferenceViewEvent
object NotificationsForDeviceDisabled : VectorSettingsNotificationPreferenceViewEvent
object AskUserForPushDistributor : VectorSettingsNotificationPreferenceViewEvent
object NotificationMethodChanged : VectorSettingsNotificationPreferenceViewEvent
sealed interface VectorSettingsNotificationViewEvent : VectorViewEvents {
object NotificationsForDeviceEnabled : VectorSettingsNotificationViewEvent
object NotificationsForDeviceDisabled : VectorSettingsNotificationViewEvent
object AskUserForPushDistributor : VectorSettingsNotificationViewEvent
object NotificationMethodChanged : VectorSettingsNotificationViewEvent
}
Loading

0 comments on commit f887acd

Please sign in to comment.