chore: changes to foreground and background logic#6958
chore: changes to foreground and background logic#6958
Conversation
WalkthroughAdded background-presence handling during login and consolidated authentication+connection readiness checks into a shared helper used by foreground/background sagas. A new saga forks on login success to set user presence to away when the app is backgrounded. Changes
Sequence DiagramsequenceDiagram
participant App as App Instance
participant LoginSaga as Login Saga
participant StateSaga as State Saga
participant RestAPI as REST API
participant Redux as Redux State
App->>LoginSaga: Login success event
LoginSaga->>Redux: fetch user-related data
LoginSaga->>LoginSaga: fork checkBackgroundAndSetAway
alt App in background
LoginSaga->>RestAPI: setUserPresenceAway()
end
App->>StateSaga: App -> Foreground
StateSaga->>Redux: isAuthAndConnected?
alt Authenticated & connected
StateSaga->>Redux: fetch server
StateSaga->>RestAPI: setUserPresenceOnline()
end
App->>StateSaga: App -> Background
StateSaga->>Redux: isAuthAndConnected?
alt Authenticated & connected
StateSaga->>Redux: save last auth session
StateSaga->>RestAPI: setUserPresenceAway()
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@app/sagas/login.js`:
- Around line 226-235: checkBackgroundAndSetAway currently sets presence based
only on background state and can run before the app/root/auth/connection are
ready; update the generator to first guard that the app is inside the root and
that auth and connection are ready before calling setUserPresenceAway.
Concretely, inside checkBackgroundAndSetAway use select to verify
RootEnum.ROOT_INSIDE (e.g. select(state => state.root.current ===
RootEnum.ROOT_INSIDE)) and also select auth/connection readiness flags (e.g.
select(state => state.auth.ready) and select(state => state.connection.ready) or
existing selectors like isAuthReady/isConnectionReady) and only if all are true
proceed to check the background flag and call setUserPresenceAway; keep the
try/catch and error logging as-is.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Proposed changes
Fix app state handling in sagas/state.js by ensuring logic only runs when appRoot is available, extracting shared background/foreground logic into a reusable function, and gating it on isAuthenticated && meteor.connected. Update presence handling so authentication/connection logic also runs in background, and add safeguards to mark user as away if the app goes to background during connection.
Issue(s)
https://rocketchat.atlassian.net/browse/CORE-1781
How to test or reproduce
Screenshots
Types of changes
Checklist
Further comments
Summary by CodeRabbit
New Features
Improvements