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
61 changes: 53 additions & 8 deletions shared/constants/init/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type * as UseTeamsStateType from '@/stores/teams'
import type * as UseTracker2StateType from '@/stores/tracker2'
import type * as UseUnlockFoldersStateType from '@/stores/unlock-folders'
import type * as UseUsersStateType from '@/stores/users'
import {createTBStore} from '@/stores/team-building'
import {createTBStore, getTBStore} from '@/stores/team-building'
import {getSelectedConversation} from '@/constants/chat2/common'
import {handleKeybaseLink} from '@/constants/deeplinks'
import {ignorePromise} from '../utils'
Expand All @@ -41,6 +41,8 @@ import {useProvisionState} from '@/stores/provision'
import {usePushState} from '@/stores/push'
import {useSettingsContactsState} from '@/stores/settings-contacts'
import {useSettingsEmailState} from '@/stores/settings-email'
import {useSettingsPhoneState} from '@/stores/settings-phone'
import {useSettingsState} from '@/stores/settings'
import {useSignupState} from '@/stores/signup'
import {useState as useRecoverPasswordState} from '@/stores/recover-password'
import {useTeamsState} from '@/stores/teams'
Expand All @@ -49,7 +51,7 @@ import {useUsersState} from '@/stores/users'
import {useWhatsNewState} from '@/stores/whats-new'
import {useRouterState} from '@/stores/router2'
import * as Util from '@/constants/router2'
import {setOtherStores} from '@/stores/convostate'
import {setConvoDefer} from '@/stores/convostate'

let _emitStartupOnLoadDaemonConnectedOnce = false
let _devicesLoaded = false
Expand Down Expand Up @@ -373,12 +375,54 @@ export const initTracker2Callbacks = () => {
})
}

export const initSettingsCallbacks = () => {
const currentState = useSettingsState.getState()
useSettingsState.setState({
dispatch: {
...currentState.dispatch,
defer: {
...currentState.dispatch.defer,
getSettingsPhonePhones: () => {
return useSettingsPhoneState.getState().phones
},
onSettingsEmailNotifyEmailsChanged: (emails: ReadonlyArray<T.RPCChat.Keybase1.Email>) => {
useSettingsEmailState.getState().dispatch.notifyEmailAddressEmailsChanged(emails)
},
onSettingsPhoneSetNumbers: (phoneNumbers?: ReadonlyArray<T.RPCChat.Keybase1.UserPhoneNumber>) => {
useSettingsPhoneState.getState().dispatch.setNumbers(phoneNumbers)
},
},
},
})
}

export const initSharedSubscriptions = () => {
setOtherStores(
storeRegistry.getStore('chat'),
storeRegistry.getStore('teams'),
storeRegistry.getStore('users')
)
setConvoDefer({
chatBlockButtonsMapHas: teamID =>
storeRegistry.getState('chat').blockButtonsMap.has(teamID),
chatInboxLayoutSmallTeamsFirstConvID: () =>
storeRegistry.getState('chat').inboxLayout?.smallTeams?.[0]?.convID,
chatInboxRefresh: reason =>
storeRegistry.getState('chat').dispatch.inboxRefresh(reason),
chatMetasReceived: metas =>
storeRegistry.getState('chat').dispatch.metasReceived(metas),
chatNavigateToInbox: () =>
storeRegistry.getState('chat').dispatch.navigateToInbox(),
chatPaymentInfoReceived: (_messageID, paymentInfo) =>
storeRegistry.getState('chat').dispatch.paymentInfoReceived(paymentInfo),
chatPreviewConversation: p =>
storeRegistry.getState('chat').dispatch.previewConversation(p),
chatResetConversationErrored: () =>
storeRegistry.getState('chat').dispatch.resetConversationErrored(),
chatUnboxRows: (convIDs, force) =>
storeRegistry.getState('chat').dispatch.unboxRows(convIDs, force),
chatUpdateInfoPanel: (show, tab) =>
storeRegistry.getState('chat').dispatch.updateInfoPanel(show, tab),
teamsGetMembers: teamID =>
storeRegistry.getState('teams').dispatch.getMembers(teamID),
usersGetBio: username =>
storeRegistry.getState('users').dispatch.getBio(username),
})
useConfigState.subscribe((s, old) => {
if (s.loadOnStartPhase !== old.loadOnStartPhase) {
if (s.loadOnStartPhase === 'startupOrReloginButNotInARush') {
Expand Down Expand Up @@ -581,7 +625,7 @@ export const initSharedSubscriptions = () => {
// team building or modal on top of that still
const isTeamBuilding = namespaceToRoute.get(namespace) === Util.getVisibleScreen(next)?.name
if (!isTeamBuilding) {
storeRegistry.getTBStore(namespace).dispatch.cancelTeamBuilding()
getTBStore(namespace).dispatch.cancelTeamBuilding()
}
}
}
Expand Down Expand Up @@ -651,6 +695,7 @@ export const initSharedSubscriptions = () => {
initProfileCallbacks()
initPushCallbacks()
initRecoverPasswordCallbacks()
initSettingsCallbacks()
initSignupCallbacks()
initTracker2Callbacks()
}
Expand Down
28 changes: 14 additions & 14 deletions shared/stores/chat2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,19 @@ const initialStore: Store = {
userReacjis: defaultUserReacjis,
}

export type RefreshReason =
| 'bootstrap'
| 'componentNeverLoaded'
| 'inboxStale'
| 'inboxSyncedClear'
| 'inboxSyncedUnknown'
| 'joinedAConversation'
| 'leftAConversation'
| 'teamTypeChanged'
| 'maybeKickedFromTeam'
| 'widgetRefresh'
| 'shareConfigSearch'

export interface State extends Store {
dispatch: {
badgesUpdated: (badgeState?: T.RPCGen.BadgeState) => void
Expand All @@ -310,20 +323,7 @@ export interface State extends Store {
ensureWidgetMetas: () => void
findGeneralConvIDFromTeamID: (teamID: T.Teams.TeamID) => void
fetchUserEmoji: (conversationIDKey?: T.Chat.ConversationIDKey, onlyInTeam?: boolean) => void
inboxRefresh: (
reason:
| 'bootstrap'
| 'componentNeverLoaded'
| 'inboxStale'
| 'inboxSyncedClear'
| 'inboxSyncedUnknown'
| 'joinedAConversation'
| 'leftAConversation'
| 'teamTypeChanged'
| 'maybeKickedFromTeam'
| 'widgetRefresh'
| 'shareConfigSearch'
) => void
inboxRefresh: (reason: RefreshReason) => void
inboxSearch: (query: string) => void
inboxSearchMoveSelectedIndex: (increment: boolean) => void
inboxSearchSelect: (
Expand Down
Loading