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

fix: notifications stop working when switching backend - WPB-15127 #2389

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

netbe
Copy link
Collaborator

@netbe netbe commented Jan 15, 2025

BugWPB-15127 [iOS] Notifications stop working

Issue

When switching backend after logging out from an account and then log to a new account, the NSE will not work because the cookie is invalid.

This is due to the fact that the environmentType (prod, staging,...), although it is correctly saved to applicationGroup UserDefaults for the NSE to work correctly, it does not read from the UserDefaults. Therefore it falls back to production and invalidates the session.

Solution:

Read environmentType from applicationGroup in BackendEnvironment.shared.

Testing

  • See steps in ticket to reproduce

Note: as the code is in a static variable it is hard to add a unit test.


Checklist

  • Title contains a reference JIRA issue number like [WPB-XXX].
  • Description is filled and free of optional paragraphs.
  • Adds/updates automated tests.

@echoes-hq echoes-hq bot added the echoes: unplanned Any work item that isn’t part of the product or technical roadmap. label Jan 15, 2025
@netbe netbe requested review from a team, samwyndham, caldrian and KaterinaWire and removed request for a team January 15, 2025 16:03
@netbe netbe changed the title fix: read from userdefaults environmentType - WPB-15127 fix: notifications stop working when switching backend - WPB-15127 Jan 15, 2025
Copy link
Contributor

Test Results

    1 files      2 suites   1m 58s ⏱️
1 793 tests 1 767 ✅ 26 💤 0 ❌
1 803 runs  1 777 ✅ 26 💤 0 ❌

Results for commit 446bf6b.

@datadog-wireapp
Copy link

Datadog Report

Branch report: fix/WPB-15127-notifications-stop-working
Commit report: d2adfe2
Test service: wire-ios-mono

✅ 0 Failed, 1689 Passed, 26 Skipped, 1m 58.36s Total Time

@@ -24,7 +24,8 @@ private let zmsLog = ZMSLog(tag: "backend-environment")
public extension BackendEnvironment {
static let backendSwitchNotification = Notification.Name("backendEnvironmentSwitchNotification")
static var shared: BackendEnvironment = {
var environmentType: EnvironmentType?
// read from userDefaults first
var environmentType: EnvironmentType? = EnvironmentType(userDefaults: .applicationGroup)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think environmentType needs to be optional after your change and you can do something like the following to remove the var too:

        let environmentType: EnvironmentType
        if let typeOverride = AutomationHelper.sharedHelper.backendEnvironmentTypeOverride() {
            environmentType = EnvironmentType(stringValue: typeOverride)
        } else {
            environmentType = EnvironmentType(userDefaults: .applicationGroup)
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
echoes: unplanned Any work item that isn’t part of the product or technical roadmap.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants