-
Notifications
You must be signed in to change notification settings - Fork 270
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
notif: Ignore notifications for logged out accounts #1349
base: main
Are you sure you want to change the base?
Conversation
Thanks @tomlin7 for the contribution! Before we can review this, it will need a test — see the repo's README file. |
6c31bb2
to
51c72de
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Comments below from a brief review.
lib/model/actions.dart
Outdated
@@ -11,6 +12,8 @@ Future<void> logOutAccount(GlobalStore globalStore, int accountId) async { | |||
// Unawaited, to not block removing the account on this request. | |||
unawaited(unregisterToken(globalStore, accountId)); | |||
|
|||
await NotificationDisplayManager.removeNotificationsForAccount(account.realmUrl, account.userId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our tests for logOutAccount
should check that the notifications are removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, what's the effect when this runs on iOS? Does it error or do nothing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also let's have this be unawaited
, like unregisterToken
above; we still want to do the removeAccount
, as soon as possible, if this fails or takes a long time for some reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrisbobbe The tests are passing, I can't test on iOS atm since I'm on Android :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah; I see this output in the console when I log out on iOS:
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.zulip.AndroidNotificationHostApi.getActiveNotifications"., null, null)
#0 AndroidNotificationHostApi.getActiveNotifications (package:zulip/host/android_notifications.g.dart:721:7)
<asynchronous suspension>
#1 NotificationDisplayManager.removeNotificationsForAccount (package:zulip/notifications/display.dart:531:33)
<asynchronous suspension>
I'll start a CZO discussion on what to do for iOS here. Edit: here: https://chat.zulip.org/#narrow/channel/243-mobile-team/topic/NotificationDisplayManager.20Android-only/near/2099143
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following that discussion, yeah, we will need to put the new call inside an Android platform conditional.
Then as an optional, independent improvement, you could add a commit that does this:
Could be helpful to put asserts at the top of [
NotificationDisplayManager
's] public methods, checking the target platform is indeed Android — because that's basically an assumption the implementation is making
lib/notifications/display.dart
Outdated
@@ -518,6 +525,16 @@ class NotificationDisplayManager { | |||
} | |||
return null; | |||
} | |||
|
|||
static Future<void> removeNotificationsForAccount(Uri realmUri, int userId) async { | |||
final groupKey = "$realmUri|$userId"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have other code for computing a group key; let's be sure to use shared code for that, so the implementations stay in sync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrisbobbe but the current implementation of _groupKey()
takes a subtype of FcmMessageWithIdentity
and I don't have sufficient data at this point. What should be done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see two options:
- Change
_groupKey
to take a realm URL and user ID instead of anFcmMessageWithIdentity
. - Keep
_groupKey
's signature but add a separate helper that takes a realm URL and user ID; have_groupKey
and this new function call that new helper.
Option 1 is less code; let's try that for now, and perhaps Greg will have thoughts in his review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrisbobbe I noticed _personKey
does exactly what I needed here, and it works fine. What do you think about using it instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'd appreciate @gnprice's thoughts on that question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found some 🙂—https://chat.zulip.org/#narrow/channel/516-mobile-dev-help/topic/Removing.20notifications.20for.20logged.20out.20account/near/2088813 :
As a matter of code organization, we'll want to keep centralized in one place the details of how the group key is formatted — the fact that it's the realm URL, then user ID, and separated by
|
. That's currently in this method:static String _groupKey(FcmMessageWithIdentity data) { // The realm URL can't contain a `|`, because `|` is not a URL code point: // https://url.spec.whatwg.org/#url-code-points return "${data.realmUrl}|${data.userId}"; }So you'll want to refactor that a bit so that it can be used by this code path as well as the existing code paths that use it.
I read that as suggesting my option (1) above.
4bc60b5
to
90daa5f
Compare
90daa5f
to
bbd7f14
Compare
I believe the two questions above that were open now have answers:
So you should be able to proceed, incorporating those. |
Fixes: #1264
Changes