Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions go/libkb/secret_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,22 @@ func GetConfiguredAccountsFromProvisionedUsernames(m MetaContext, s SecretStoreA
allUsernames = append(allUsernames, currentUsername)
}

// Build UIDs first so we can attach them to each account
uids := make([]keybase1.UID, len(allUsernames))
for idx, username := range allUsernames {
uids[idx] = GetUIDByNormalizedUsername(m.G(), username)
}

accounts := make(map[NormalizedUsername]keybase1.ConfiguredAccount)
for _, username := range allUsernames {
for idx, username := range allUsernames {
accounts[username] = keybase1.ConfiguredAccount{
Username: username.String(),
IsCurrent: username.Eq(currentUsername),
Uid: uids[idx],
}
}

// Get the full names
uids := make([]keybase1.UID, len(allUsernames))
for idx, username := range allUsernames {
uids[idx] = GetUIDByNormalizedUsername(m.G(), username)
}
usernamePackages, err := m.G().UIDMapper.MapUIDsToUsernamePackages(m.Ctx(), m.G(),
uids, time.Hour*24, time.Second*10, false)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions go/protocol/keybase1/login.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions protocol/avdl/keybase1/login.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ protocol login {
FullName fullname;
boolean hasStoredSecret;
boolean isCurrent;
UID uid;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions protocol/json/keybase1/login.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions shared/constants/init/push-listener.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type DataNewMessageSilent2 = DataCommon & {
}
type DataFollow = DataCommon & {
type: 'follow'
targetUID?: string
Comment thread
zoom-ua marked this conversation as resolved.
username?: string
}
type DataChatExtension = DataCommon & {
Expand Down Expand Up @@ -73,6 +74,8 @@ const normalizePush = (_n?: object): T.Push.PushNotification | undefined => {

const data = _n as PushN
const userInteraction = !!data.userInteraction
const dataUid = data as {uid?: string; targetUID?: string}
const forUid = dataUid.uid

switch (data.type) {
case 'chat.readmessage': {
Expand All @@ -86,6 +89,7 @@ const normalizePush = (_n?: object): T.Push.PushNotification | undefined => {
return data.convID
? {
conversationIDKey: T.Chat.stringToConversationIDKey(data.convID),
forUid,
membersType: anyToConversationMembersType(data.t),
type: 'chat.newmessage',
unboxPayload: data.m || '',
Expand All @@ -108,6 +112,7 @@ const normalizePush = (_n?: object): T.Push.PushNotification | undefined => {
case 'follow':
return data.username
? {
forUid: forUid ?? dataUid.targetUID,
type: 'follow',
userInteraction,
username: data.username,
Expand All @@ -117,6 +122,7 @@ const normalizePush = (_n?: object): T.Push.PushNotification | undefined => {
return data.convID
? {
conversationIDKey: T.Chat.stringToConversationIDKey(data.convID),
forUid,
type: 'chat.extension',
}
: undefined
Expand Down Expand Up @@ -213,6 +219,26 @@ export const initPushListener = () => {

usePushState.getState().dispatch.initialPermissionsCheck()

// When current-user.uid changes, run pending push if it was for this account
storeRegistry.getStore('current-user').subscribe((s, old) => {
if (s.uid === old.uid) return
const pushState = storeRegistry.getState('push')
const pending = pushState.pendingPushNotification
if (!pending || !('forUid' in pending)) return
const forUid = (pending as {forUid?: string}).forUid
if (!forUid || forUid !== s.uid) return
pushState.dispatch.clearPendingPushNotification()
pushState.dispatch.handlePush(pending)
})

// Clear pending push on logout
storeRegistry.getStore('config').subscribe((s, old) => {
if (s.loggedIn === old.loggedIn) return
if (!s.loggedIn) {
storeRegistry.getState('push').dispatch.clearPendingPushNotification()
}
})

const listenNative = async () => {
const RNEmitter = getNativeEmitter()

Expand Down
1 change: 1 addition & 0 deletions shared/constants/types/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export type DaemonHandshakeState = 'starting' | 'waitingForWaiters' | 'done'
export type ConfiguredAccount = {
fullname?: string
hasStoredSecret: boolean
uid?: string
username: string
}
5 changes: 4 additions & 1 deletion shared/constants/types/push.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ export type PushNotification =
}
| {
conversationIDKey: ChatTypes.ConversationIDKey
forUid?: string
membersType?: RPCChatTypes.ConversationMembersType
type: 'chat.newmessage'
unboxPayload: string
userInteraction: boolean
}
| {
forUid?: string
type: 'follow'
userInteraction: boolean
username: string
}
| {
type: 'chat.extension'
conversationIDKey: ChatTypes.ConversationIDKey
forUid?: string
type: 'chat.extension'
}
| {
type: 'settings.contacts'
Expand Down
2 changes: 1 addition & 1 deletion shared/constants/types/rpc-gen.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shared/desktop/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
• On iOS quicky share to recent conversations
• On iOS quickly share to recent conversations
• Emoji 16 support
• iOS HEIC Avatar support
• Better sharing/push support
Expand Down
12 changes: 10 additions & 2 deletions shared/stores/daemon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ const initialStore: Store = {

export interface State extends Store {
dispatch: {
loadDaemonAccounts: (configuredAccountsLength: number, loggedIn: boolean, refreshAccounts: () => Promise<void>) => void
loadDaemonAccounts: (
configuredAccountsLength: number,
loggedIn: boolean,
refreshAccounts: () => Promise<void>
) => void
loadDaemonBootstrapStatus: () => Promise<void>
resetState: () => void
setError: (e?: Error) => void
Expand Down Expand Up @@ -117,7 +121,11 @@ export const useDaemonState = Z.createZustand<State>('daemon', (set, get) => {
daemonHandshakeDone: () => {
get().dispatch.setState('done')
},
loadDaemonAccounts: (configuredAccountsLength: number, loggedIn: boolean, refreshAccounts: () => Promise<void>) => {
loadDaemonAccounts: (
configuredAccountsLength: number,
loggedIn: boolean,
refreshAccounts: () => Promise<void>
) => {
const f = async () => {
const version = get().handshakeVersion
if (configuredAccountsLength) {
Expand Down
2 changes: 2 additions & 0 deletions shared/stores/push.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {UseBoundStore, StoreApi} from 'zustand'
type Store = T.Immutable<{
hasPermissions: boolean
justSignedUp: boolean
pendingPushNotification?: T.Push.PushNotification
showPushPrompt: boolean
token: string
}>
Expand All @@ -14,6 +15,7 @@ export type State = Store & {
onGetDaemonHandshakeState?: () => T.Config.DaemonHandshakeState
}
checkPermissions: () => Promise<boolean>
clearPendingPushNotification: () => void
deleteToken: (version: number) => void
handlePush: (notification: T.Push.PushNotification) => void
initialPermissionsCheck: () => void
Expand Down
34 changes: 32 additions & 2 deletions shared/stores/push.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const tokenType = isIOS ? (isDevApplePushToken ? 'appledev' : 'apple') :
const initialStore: Store = {
hasPermissions: true,
justSignedUp: false,
pendingPushNotification: undefined,
showPushPrompt: false,
token: '',
}
Expand Down Expand Up @@ -114,6 +115,11 @@ export const usePushState = Z.createZustand<State>('push', (set, get) => {
return false
}
},
clearPendingPushNotification: () => {
set(s => {
s.pendingPushNotification = undefined
})
},
defer: {
onGetDaemonHandshakeState: () => {
throw new Error('onGetDaemonHandshakeState not implemented')
Expand Down Expand Up @@ -148,6 +154,31 @@ export const usePushState = Z.createZustand<State>('push', (set, get) => {
handlePush: notification => {
const f = async () => {
try {
const forUid = 'forUid' in notification ? notification.forUid : undefined

if (forUid) {
const currentUid = storeRegistry.getState('current-user').uid
if (forUid !== currentUid) {
const {configuredAccounts, dispatch: configDispatch} = storeRegistry.getState('config')
const account = configuredAccounts.find(acc => acc.uid === forUid)
if (!account) {
logger.info('[Push] notification forUid not in configured accounts, skipping')
return
}
if (!account.hasStoredSecret) {
logger.info('[Push] account has no stored secret, cannot switch')
return
}
logger.info('[Push] switching to account for notification tap')
set(s => {
s.pendingPushNotification = notification
})
configDispatch.setUserSwitching(true)
configDispatch.login(account.username, '')
return
}
}

switch (notification.type) {
case 'chat.readmessage':
if (notification.badges === 0) {
Expand Down Expand Up @@ -182,8 +213,7 @@ export const usePushState = Z.createZustand<State>('push', (set, get) => {
if (__DEV__) {
console.error(e)
}

logger.error('[Push] unhandled!!')
logger.error('[Push] unhandled', e)
}
}
ignorePromise(f())
Expand Down