Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add email notification toggle #4052

Merged
merged 24 commits into from
Sep 24, 2021
Merged

Conversation

ouchadam
Copy link
Contributor

@ouchadam ouchadam commented Sep 21, 2021

#2243 Email notification toggles

  • Adds a Email notifications category to settings/notifications which allows for individually toggling email notifications for all associated emails
    • When the account has no associated emails, the category contains a link to the Email and Phone numbers screen
    • addEmailPusher functionality is added to the matrix-sdk PushersService which allows an email address to be registered or unregistered for notifications
  • Adds a REMOVE button to the settings/advanced settings/notification targets
  • Renames a few AddHttpPusher classes to AddPusher as they were able to be repurposed for emails
  • personal data has been manually overridden and replaced with [redacted]
BEFORE NO EMAILS AVAILABLE EMAIL PRESENT LIGHT - MULTIPLE EMAILS
account-before account-no-emails-registered account-emails-notification-disabled account-light-multiple
NAVIGATING EMPTY REMOVING ADDING ERROR HANDLING
account-no-emails-clickthrough account-removing-email-pusher account-registering-email account-error-handling

- email pushes make use of a new undocumented `brand` field, for now this field maps directly to the app display name so we can resuse it
- will display a _no emails_ when the matrix account has no emails set and tapping will navigate to the emails and phone numbers screen where the user can add an email
- toggling the email notification with register and unregister push notification for the given email address
- Extracts out a transactional switch helper to handle reverting the switch back to its original state if an error occurs
- Reuses existing toast message for unknown error
- Does not include the isAdded to the async callback as the couroutine is tied to the fragment lifecycle scope
…pushers

- Updates the doc to reflect that to remove emails an appId of m.email is required
…self closing tag

- the category is dynamically populated so we shouldn't be adding anything static here anyways!
…ch rather than when the listener is initially set
append = append)
withEventIdOnly: Boolean
) = addPusher(
JsonPusher(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a lot of duplication here caused by the amount of parameters, the next PR coming up will address this by introducing a dedicated HttpPusher data class

*/
suspend fun removeHttpPusher(pushkey: String, appId: String)
suspend fun removePusher(pushkey: String, appId: String)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed because technically this function can remove email and http pushers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks, but maybe for clarity / symmetry keep removeHttpPusher and add new fun removeEmailPusher which takes only one parameter email?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally had that but it felt odd that PushGateway could still use the removeHttpPusher for both http and email pushers

the PushersManager has symmetrical register/unregister for http and email but that's a layer above the SDK

we could force the different flows based on appId

fun removePusher(pusher: Pusher) {
  when (pusher.appId) {
      Pusher.APP_ID_EMAIL -> session.removeEmailPusher(pusher.pushKey)
      else -> session.removeHttpPusher(pusher.pushKey, pusher.appId)
  }
}

what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PushersManager is on the app side, so I would say its Api is less "important" than the SDK API PushersService. I agree that removeHttpPusher is not KO to remove email pushers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after speaking offline, I've opted for adding a 3rd method for removing Pushers 4482cbd this has the benefit of avoiding redundancy in checking the appId if we already have a pusher instance and we can have dedicated symmetrical http/email removal functions for convenience

* @param emailBranding The branding placeholder to include in the email communications.
* @param appDisplayName A human readable string that will allow the user to identify what application owns this pusher.
* @param deviceDisplayName A human readable string that will allow the user to identify what device owns this pusher.
* @return A work request uuid. Can be used to listen to the status
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the next PR will remove the reliance on the WorkManager by switching to a suspend fun, allowing us to handle and simplify the registration errors

@github-actions
Copy link

github-actions bot commented Sep 21, 2021

Unit Test Results

  34 files  ±0    34 suites  ±0   19s ⏱️ ±0s
  73 tests ±0    73 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
180 runs  ±0  180 ✔️ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 045e4bb. ± Comparison against base commit 045e4bb.

♻️ This comment has been updated with latest results.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work thanks.
A few comments and remarks

*/
suspend fun removeHttpPusher(pushkey: String, appId: String)
suspend fun removePusher(pushkey: String, appId: String)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks, but maybe for clarity / symmetry keep removeHttpPusher and add new fun removeEmailPusher which takes only one parameter email?


val params = AddHttpPusherWorker.Params(sessionId, pusher)
override fun addEmailPusher(email: String, lang: String, emailBranding: String, appDisplayName: String, deviceDisplayName: String) = addPusher(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One param per line is better when there are a lot of parameters like here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why there is no param append here?

Copy link
Contributor Author

@ouchadam ouchadam Sep 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

append was removed as an option because it sounds like it has the side effect of causing other accounts which use the same email to lose email notifications https://github.com/matrix-org/matrix-react-sdk/pull/2727/files#diff-ec232520bf51337e5e6939b885d21f428ad6da3306c8e17a3ff660b2b341179dR165

happy to add back if you think it should be configurable by clients

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's sometimes difficult to decide between what we want the SDK to expose (as parameters for instance) and what we want the SDK to handle, so keep hidden from the client app. On one side the SDK should let the app do whatever it wants to, and on the other side we want the SDK to provide a high level service... So maybe add the parameter, with default value to true and with the same comment from https://github.com/matrix-org/matrix-react-sdk/pull/2727/files#diff-ec232520bf51337e5e6939b885d21f428ad6da3306c8e17a3ff660b2b341179dR165 in the doc of the fun addEmailPusher.
Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, will do 👍

vector/src/main/res/values/strings.xml Show resolved Hide resolved
vector/src/main/res/values/strings.xml Outdated Show resolved Hide resolved
@ouchadam ouchadam force-pushed the feature/adm/email_notification_toggle branch from 5033ea5 to 8316728 Compare September 23, 2021 10:51
@ouchadam ouchadam force-pushed the feature/adm/email_notification_toggle branch from 8cfdc43 to 3a1cb1c Compare September 23, 2021 13:46
… typically we wouldn't want to overwrite other accounts but we can expose the option to clients if they want that behaviour
…hers

- also adds a separate removePusher which supports removing any type of pusher
@@ -75,12 +75,12 @@ class PushersManager @Inject constructor(

suspend fun unregisterEmailPusher(email: String) {
val currentSession = activeSessionHolder.getSafeActiveSession() ?: return
currentSession.removePusher(email, appId = "m.email")
currentSession.removeEmailPusher(email)
}

suspend fun unregisterPusher(pushKey: String) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: rename to unregisterHttpPusher for parity?

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, LGTM!

@bmarty bmarty merged commit 045e4bb into develop Sep 24, 2021
@bmarty bmarty deleted the feature/adm/email_notification_toggle branch September 24, 2021 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants