-
Notifications
You must be signed in to change notification settings - Fork 71
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
Remove old Notification tokens #2173
Conversation
85796c5
to
3870175
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.
Conditionally rely on the type of areas across different services seems very brittle.
What would be the issue with calling unregister on every incoming device, catching the errors, and then continuing registration?
src/domain/notifications/v2/notifications.repository.integration.spec.ts
Show resolved
Hide resolved
That’s quite risky. If we call unregister first and encounter an error during registration, it could result in token loss. In this PR, we address this by ensuring that tokens are successfully registered in the new system before attempting to remove them from the old system. You might argue that if a token is registered but the unregister process fails, we could end up delivering multiple notifications. However, between duplicate notifications and no notifications, I’d prefer the former. |
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.
For visbility: the conditional error checks are confusing but unavoidable due to the compatability layer. They will, however, be removed soon as we will keep them as is.
5e5999d
to
bdf9a89
Compare
…tionNotificationTypes
Co-authored-by: Aaron Cook <aaron@safe.global>
293fed8
to
ac5074b
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.
Looking back at this, I realised we aren't testing the new logic on the controller.
I suggest we extend the notifications.controller.spect
to ensure we are handling unregistration as expected/throwing the correct error. What do you think?
if (error instanceof Error) { | ||
if ('code' in error && error.code !== 404) { | ||
throw error; | ||
} | ||
} |
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.
If the error is not instanceof Error
, it is being swallowed here.
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.
Change in the new version
6a9aa2f
if (error instanceof Error) { | ||
if ('code' in error && error.code !== 404) { | ||
throw error; | ||
} | ||
} |
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.
If the error is not instanceof Error
, it is being swallowed here.
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.
Change in the new version
6a9aa2f
Thanks for the suggestion! I gave this some thought, and while I agree that testing is important, in this specific case, the logic is quite straightforward and only covers one error scenario. I don’t believe adding a test here provides enough value to justify the extra maintenance overhead. If there are more complex cases or future changes to this part of the controller, we can revisit and add tests as needed. Let me know what you think! |
Summary
This PR ensures that duplicate push notifications are avoided by removing the registered push notification token from the TX service during device registration through the Client Gateway (CGW). This prevents multiple registrations from causing redundant notifications.
Changes
unregisterDevice
is called.unregisterSafe
is invoked to maintain data consistency.