Skip to content
Draft
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
10 changes: 10 additions & 0 deletions shared/chat/blocking/block-buttons-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Z from '@/util/zustand'
import {bodyToJSON} from '@/constants/rpc-utils'
import {ignorePromise} from '@/constants/utils'
import logger from '@/logger'
import {EnginePriority, registerEngineHandlers} from '@/engine/action-listener'

const blockButtonsGregorPrefix = 'blockButtons.'

Expand Down Expand Up @@ -122,3 +123,12 @@ export const useBlockButtonsInfo = (teamID: T.Teams.TeamID) => {

return blockButtonsInfo
}

registerEngineHandlers(
{
'keybase.1.gregorUI.pushState': action => {
useBlockButtonsState.getState().dispatch.updateFromGregorItems(action.payload.params.state.items)
},
},
{id: 'chat/blocking/block-buttons-state', priority: EnginePriority.shared}
)
5 changes: 4 additions & 1 deletion shared/chat/conversation/center-context.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ jest.mock('./thread-context', () => ({
jest.mock('./send-actions', () => ({
useConversationSendActions: () => ({sendGiphyResult: jest.fn(), sendMessage: jest.fn()}),
}))
jest.mock('@/engine/action-listener', () => ({useEngineActionListener: () => {}}))
jest.mock('@/engine/action-listener', () => ({
...jest.requireActual<object>('@/engine/action-listener'),
useEngineActionListener: () => {},
}))
jest.mock('./thread-load-status-context', () => ({
useThreadLoadStatusOptionsGetter: () => () => mockThreadLoadStatusOptions,
}))
Expand Down
1 change: 1 addition & 0 deletions shared/chat/conversation/normal/container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jest.mock('@/constants', () => {
})

jest.mock('@/engine/action-listener', () => ({
...jest.requireActual<object>('@/engine/action-listener'),
useEngineActionListener: jest.fn(),
}))

Expand Down
13 changes: 13 additions & 0 deletions shared/chat/inbox/badge-state.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as T from '@/constants/types'
import * as Z from '@/util/zustand'
import {EnginePriority, registerEngineHandlers} from '@/engine/action-listener'

export type BadgeCounts = {badgeCount: number; unreadCount: number}

Expand Down Expand Up @@ -35,3 +36,15 @@ export const syncInboxBadgeState = (badgeState?: T.RPCGen.BadgeState) => {

export const getInboxBadge = (id: T.Chat.ConversationIDKey): BadgeCounts =>
useInboxBadgeState.getState().counts.get(id) ?? emptyCounts

// Runs ahead of every other badgeState handler: the tab badge counts useNotifState
// derives, and anything rendering off them, must never read a conversation map
// from the previous badgeState.
registerEngineHandlers(
{
'keybase.1.NotifyBadges.badgeState': action => {
syncInboxBadgeState(action.payload.params.badgeState)
},
},
{id: 'chat/inbox/badge-state', priority: EnginePriority.sharedFirst}
)
50 changes: 50 additions & 0 deletions shared/chat/inbox/engine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ import {
getInboxConversationMeta,
metaReceivedError,
metasReceived,
onIncomingInboxUIItem,
syncInboxParticipantsFromParticipantMap,
updateInboxConversationMeta,
unboxRows,
} from './metadata'
import {useDaemonState} from '@/stores/daemon'
import {EnginePriority, registerEngineHandlers} from '@/engine/action-listener'

type ConvoEngineIncomingResult = {
handled: boolean
Expand Down Expand Up @@ -283,3 +286,50 @@ export const handleConvoEngineIncoming = (action: EngineGen.Actions): ConvoEngin
return {handled: false}
}
}

const routeConvoEngineIncoming = (action: EngineGen.Actions) => {
const result = handleConvoEngineIncoming(action)
if (result.inboxUIItem) {
onIncomingInboxUIItem(result.inboxUIItem)
}
if (result.userReacjis) {
useDaemonState.getState().dispatch.updateUserReacjis(result.userReacjis)
}
}

registerEngineHandlers(
{
'chat.1.NotifyChat.ChatAttachmentDownloadComplete': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatAttachmentDownloadProgress': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatAttachmentUploadProgress': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatAttachmentUploadStart': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatConvUpdate': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatIdentifyUpdate': action => {
const {update} = action.payload.params
const usernames = update.CanonicalName.split(',')
const broken = (update.breaks.breaks || []).map(b => b.user.username)
useUsersState
.getState()
.dispatch.updates(usernames.map(name => ({info: {broken: broken.includes(name)}, name})))
},
'chat.1.NotifyChat.ChatParticipantsInfo': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatPaymentInfo': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatPromptUnfurl': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatRequestInfo': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatSetConvRetention': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatSetConvSettings': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatSetTeamRetention': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatSubteamRename': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatTLFFinalize': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatThreadsStale': routeConvoEngineIncoming,
'chat.1.NotifyChat.ChatTypingUpdate': routeConvoEngineIncoming,
'chat.1.NotifyChat.NewChatActivity': routeConvoEngineIncoming,
'chat.1.chatUi.chatCoinFlipStatus': routeConvoEngineIncoming,
'chat.1.chatUi.chatCommandMarkdown': routeConvoEngineIncoming,
'chat.1.chatUi.chatCommandStatus': routeConvoEngineIncoming,
'chat.1.chatUi.chatGiphySearchResults': routeConvoEngineIncoming,
'chat.1.chatUi.chatGiphyToggleResultWindow': routeConvoEngineIncoming,
'chat.1.chatUi.chatInboxFailed': routeConvoEngineIncoming,
},
{id: 'chat/inbox/engine', priority: EnginePriority.shared}
)
32 changes: 32 additions & 0 deletions shared/chat/inbox/metadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import * as Z from '@/util/zustand'
import {useConfigState} from '@/stores/config'
import {useCurrentUserState} from '@/stores/current-user'
import {useUsersState} from '@/stores/users'
import {useWaitingState} from '@/stores/waiting'
import {useInboxLayoutState} from './layout-state'
import {waitingKeyChatInboxSyncStarted} from '@/constants/strings'
import {EnginePriority, registerEngineHandlers} from '@/engine/action-listener'

export const getInboxConversationMeta = (conversationIDKey: T.Chat.ConversationIDKey) =>
useInboxMetadataState.getState().metas.get(conversationIDKey)
Expand Down Expand Up @@ -673,3 +677,31 @@ export const onChatInboxSynced = async (
await refreshInbox('inboxSyncedUnknown')
}
}

registerEngineHandlers(
{
'chat.1.NotifyChat.ChatInboxStale': () => {
ignorePromise(useInboxLayoutState.getState().dispatch.refresh('inboxStale'))
},
'chat.1.NotifyChat.ChatInboxSyncStarted': () => {
useWaitingState.getState().dispatch.increment(waitingKeyChatInboxSyncStarted)
},
'chat.1.NotifyChat.ChatInboxSynced': action => {
useWaitingState.getState().dispatch.clear(waitingKeyChatInboxSyncStarted)
ignorePromise(
onChatInboxSynced(action, async reason => useInboxLayoutState.getState().dispatch.refresh(reason))
)
},
'chat.1.chatUi.chatInboxConversation': onGetInboxConvsUnboxed,
'chat.1.chatUi.chatInboxLayout': action => {
const {hasLoaded, dispatch} = useInboxLayoutState.getState()
dispatch.updateLayout(action.payload.params.layout)
const {layout} = useInboxLayoutState.getState()
if (layout) {
onInboxLayoutChanged(layout, hasLoaded)
}
},
'chat.1.chatUi.chatInboxUnverified': onGetInboxUnverifiedConvs,
},
{id: 'chat/inbox/metadata', priority: EnginePriority.shared}
)
10 changes: 10 additions & 0 deletions shared/common-adapters/avatar/store.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type * as T from '@/constants/types'
import * as Z from '@/util/zustand'
import {EnginePriority, registerEngineHandlers} from '@/engine/action-listener'

// This store has no dependencies on other stores and is safe to import directly from other stores.
type Store = T.Immutable<{
Expand Down Expand Up @@ -38,3 +39,12 @@ export const useAvatarState = Z.createZustand<State>(set => {
dispatch,
}
})

registerEngineHandlers(
{
'keybase.1.NotifyTeam.avatarUpdated': action => {
useAvatarState.getState().dispatch.updated(action.payload.params.name)
},
},
{id: 'common-adapters/avatar/store', priority: EnginePriority.shared}
)
Loading