feat: add InstanceSessionManager (switch + logout) and route forced logout through it - #681
Conversation
…ogout through it
Implements infra-only -- no Presentation-layer files touched.
logout no longer wipes a session's cached content, only its actual session state.
- InstanceSessionManagerProtocol splits into two methods:
- switchActiveInstance(to:) -- pure selection change, no teardown at all.
Not called from anywhere yet (no picker UI exists), but built now.
- logoutCurrentInstance() -- cancels in-flight downloads, unregisters this
device's push token, clears storage (Keychain tokens/cached user), then
clears the instance selection last. Deliberately does NOT clear CoreData
rows or delete downloaded files -- a later re-login to the same instance
resumes fast instead of re-fetching everything.
- AppDelegate.didUserLogout now calls logoutCurrentInstance() instead of the
three separate .clear()/.deleteAllProgress()/.deleteAll() calls it used to
make inline.
- New Core/Core/Configuration/PushTokenUnregistering.swift: a small protocol
so logoutCurrentInstance() can call an app-target push-unregister step
without depending on push/Firebase wiring (a later PR) landing first.
InstanceSessionManager takes it as an optional dependency (nil today, so
the step is simply skipped) rather than the reference implementation's
required-protocol-with-default-no-op-extension shape, since nothing
conforms to it yet and an optional avoids forcing a placeholder DI
registration for a capability nobody can exercise yet.
- CoreDataHandlerProtocol.clear(instanceKey:) / DatabaseManager's
implementation are kept as built, but are no longer called by
logout -- left in place as general per-instance infra (e.g. a future
explicit "remove this instance's data" action), not dead-ended.
- Wired InstanceSessionManagerProtocol through AppAssembly.
- InstanceSessionManagerTests covers: switch does no teardown, logout tears
down session state but not cached content, and logout still completes
when no push conformance is wired.
- CoreDataHandlerProtocol gains clear(instanceKey:), implemented in
DatabaseManager via one NSBatchDeleteRequest per instanceKey-scoped entity
(CDDownloadData, CDOfflineProgress, CDCourseItem, CDDownloadCoursePreview)
against the shared merged store.
…-lifecycle # Conflicts: # Core/Core.xcodeproj/project.pbxproj
|
Thanks for the pull request, @RawanMatar89! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
Base
Stacked on
infra/07-coredata-downloads-scoping.What's in this PR
Implements infra-only — no Presentation-layer files touched.
Logout no longer wipes a session's cached content, only its actual session state.
InstanceSessionManagerProtocolsplits into two methods:switchActiveInstance(to:)— pure selection change, no teardown at all. Not called from anywhere yet (no picker UI exists), but built now.logoutCurrentInstance()— cancels in-flight downloads, unregisters this device's push token, clears storage (Keychain tokens/cached user), then clears the instance selection last. Deliberately does not clear CoreData rows or delete downloaded files — a later re-login to the same instance resumes fast instead of re-fetching everything.AppDelegate.didUserLogoutnow callslogoutCurrentInstance()instead of the three separate.clear()/.deleteAllProgress()/.deleteAll()calls it used to make inline.Core/Core/Configuration/PushTokenUnregistering.swift: a small protocol sologoutCurrentInstance()can call an app-target push-unregister step without depending on push/Firebase wiring (a later PR) landing first.InstanceSessionManagertakes it as an optional dependency (niltoday, so the step is simply skipped) rather than the reference implementation's required-protocol-with-default-no-op-extension shape, since nothing conforms to it yet and an optional avoids forcing a placeholder DI registration for a capability nobody can exercise yet.CoreDataHandlerProtocol.clear(instanceKey:)/DatabaseManager's implementation are kept as built, but are no longer called by logout — left in place as general per-instance infra (e.g. a future explicit "remove this instance's data" action), not dead-ended.InstanceSessionManagerProtocolthroughAppAssembly.InstanceSessionManagerTestscovers: switch does no teardown, logout tears down session state but not cached content, and logout still completes when no push conformance is wired.CoreDataHandlerProtocolgainsclear(instanceKey:), implemented inDatabaseManagervia oneNSBatchDeleteRequestper instanceKey-scoped entity (CDDownloadData,CDOfflineProgress,CDCourseItem,CDDownloadCoursePreview) against the shared merged store.