Skip to content

Commit e80a596

Browse files
committed
x
1 parent 2a1b9f3 commit e80a596

6 files changed

Lines changed: 28 additions & 3 deletions

File tree

go/bind/keybase.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ func Init(homeDir, mobileSharedHome, logFile, runModeStr string,
288288
kbCtx = libkb.NewGlobalContext()
289289
kbCtx.Init()
290290
kbCtx.SetProofServices(externals.NewProofServices(kbCtx))
291+
kbCtx.AddLogoutHook(accountCacheLogoutHook{}, "notifications/accountCache")
291292

292293
var suffix string
293294
if isIPad {

go/bind/notifications.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ var (
3131
multipleAccountsCached *bool
3232
)
3333

34+
// accountCacheLogoutHook implements libkb.LogoutHook. It clears the cached
35+
// result of hasMultipleLoggedInAccounts so that the next background
36+
// notification recomputes it against the post-logout account list.
37+
type accountCacheLogoutHook struct{}
38+
39+
func (accountCacheLogoutHook) OnLogout(_ libkb.MetaContext) error {
40+
multipleAccountsMtx.Lock()
41+
multipleAccountsCached = nil
42+
multipleAccountsMtx.Unlock()
43+
return nil
44+
}
45+
3446
func hasMultipleLoggedInAccounts(ctx context.Context) bool {
3547
multipleAccountsMtx.Lock()
3648
defer multipleAccountsMtx.Unlock()
@@ -260,8 +272,11 @@ func HandleBackgroundNotification(strConvID, body, serverMessageBody, sender str
260272
// Return nil (not an error) so Android does not treat this as failure and show a fallback notification.
261273
return nil
262274
}
263-
pusher.DisplayChatNotification(&chatNotification)
275+
// Add to cache before displaying so that any concurrent goroutine that
276+
// reaches the second check while DisplayChatNotification is running will
277+
// see the entry and bail out rather than displaying a duplicate.
264278
seenNotifications.Add(dupKey, struct{}{})
279+
pusher.DisplayChatNotification(&chatNotification)
265280
if len(pushID) > 0 {
266281
mp.AckNotificationSuccess(ctx, []string{pushID})
267282
}

shared/constants/platform-specific/push.native.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,15 @@ export const initPushListener = () => {
205205

206206
storeRegistry.getState('push').dispatch.initialPermissionsCheck()
207207

208-
// When current-user.uid changes, run pending push if it was for this account
208+
// Second half of the account-switch-for-notification flow: when the uid
209+
// changes (i.e. login completes after a switch initiated in handlePush in
210+
// constants/push.native.tsx), replay the pending notification for the new
211+
// account if it was addressed to them.
209212
storeRegistry.getStore('current-user').subscribe((s, old) => {
210213
if (s.uid === old.uid) return
211214
const pushState = storeRegistry.getState('push')
212215
const pending = pushState.pendingPushNotification
216+
if (!pending) return
213217
const forUid = (pending as {forUid?: string}).forUid
214218
if (!forUid || forUid !== s.uid) return
215219
pushState.dispatch.clearPendingPushNotification()

shared/constants/push.desktop.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const usePushState = Z.createZustand<State>(() => {
1515
checkPermissions: async () => {
1616
return Promise.resolve(false)
1717
},
18+
clearPendingPushNotification: () => {},
1819
deleteToken: () => {},
1920
handlePush: () => {},
2021
initialPermissionsCheck: () => {},

shared/constants/push.native.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ export const usePushState = Z.createZustand<State>((set, get) => {
162162
logger.info('[Push] account has no stored secret, cannot switch')
163163
return
164164
}
165+
// Store the notification and trigger an account switch. We do NOT
166+
// process the notification here — execution continues once the uid
167+
// changes, picked up by the subscriber in
168+
// constants/platform-specific/push.native.tsx (initPushListener).
165169
logger.info('[Push] switching to account for notification tap')
166170
set(s => {
167171
s.pendingPushNotification = notification

shared/login/relogin/index.desktop.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Login = (props: Props) => {
3232
}
3333

3434
const userRows = props.users
35-
.concat({hasStoredSecret: false, username: other})
35+
.concat({hasStoredSecret: false, uid: '', username: other})
3636
.map(u => <UserRow user={u.username} key={u.username} hasStoredSecret={u.hasStoredSecret} />)
3737

3838
const selectedIdx = props.users.findIndex(u => u.username === props.selectedUser)

0 commit comments

Comments
 (0)