Skip to content

Commit

Permalink
refactor: __internal_jump_to_message params
Browse files Browse the repository at this point in the history
Follow-up to the previous commit.
  • Loading branch information
WofWca committed Oct 29, 2024
1 parent 00bdab0 commit ef328ca
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/frontend/src/components/RuntimeAdapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function RuntimeAdapter({
clearNotificationsForChat(notificationAccountId, chatId)
}
if (msgId) {
window.__internal_jump_to_message?.(msgId)
window.__internal_jump_to_message?.({ msgId })
}
}
)
Expand Down
10 changes: 5 additions & 5 deletions packages/frontend/src/components/message/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -796,11 +796,11 @@ function JumpDownButton({
jumpToMessageStack,
}: {
countUnreadMessages: number
jumpToMessage: (
msgId: number | undefined,
highlight?: boolean,
jumpToMessage: (params: {
msgId: number | undefined
highlight?: boolean
addMessageIdToStack?: undefined | number
) => Promise<void>
}) => Promise<void>
jumpToMessageStack: number[]
}) {
let countToShow: string = countUnreadMessages.toString()
Expand All @@ -823,7 +823,7 @@ function JumpDownButton({
<div
className='button'
onClick={() => {
jumpToMessage(undefined, true)
jumpToMessage({ msgId: undefined, highlight: true })
}}
>
<div
Expand Down
6 changes: 5 additions & 1 deletion packages/frontend/src/contexts/ChatContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ export const ChatProvider = ({
// Jump to last message if user clicked chat twice
// @TODO: We probably want this to be part of the UI logic instead
if (nextChatId === chatId) {
window.__internal_jump_to_message?.(undefined, false, undefined)
window.__internal_jump_to_message?.({
msgId: undefined,
highlight: false,
addMessageIdToStack: undefined,
})
}

// Already set known state
Expand Down
8 changes: 4 additions & 4 deletions packages/frontend/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ declare global {
__refetchChatlist: undefined | (() => void)
__internal_jump_to_message:
| undefined
| ((
msgId: number | undefined,
highlight?: boolean,
| ((params: {
msgId: number | undefined
highlight?: boolean
addMessageIdToStack?: undefined | number
) => Promise<void>)
}) => Promise<void>)
__updateAccountListSidebar: (() => void) | undefined
}
}
6 changes: 5 additions & 1 deletion packages/frontend/src/hooks/chat/useMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ export default function useMessage() {

// Workaround to actual jump to message in regarding mounted component view
setTimeout(() => {
window.__internal_jump_to_message?.(msgId, highlight, msgParentId)
window.__internal_jump_to_message?.({
msgId,
highlight,
addMessageIdToStack: msgParentId,
})
}, 0)
},
[chatId, selectChat, setChatView]
Expand Down
15 changes: 11 additions & 4 deletions packages/frontend/src/stores/messagelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ class MessageListStore extends Store<MessageListState> {
if (firstUnreadMsgId !== null) {
setTimeout(async () => {
const chat = await chatP
this.effect.jumpToMessage(firstUnreadMsgId, false)
this.effect.jumpToMessage({
msgId: firstUnreadMsgId,
highlight: false,
})
ActionEmitter.emitAction(
chat.archived
? KeybindAction.ChatList_SwitchToArchiveView
Expand Down Expand Up @@ -403,11 +406,15 @@ class MessageListStore extends Store<MessageListState> {
*/
jumpToMessage: this.scheduler.lockedQueuedEffect(
'scroll',
async (
jumpToMessageId: number | undefined,
async ({
msgId: jumpToMessageId,
highlight = true,
addMessageIdToStack,
}: {
msgId: number | undefined
highlight?: boolean
addMessageIdToStack?: undefined | number
) => {
}) => {
const startTime = performance.now()

this.log.debug('jumpToMessage with messageId: ', jumpToMessageId)
Expand Down

0 comments on commit ef328ca

Please sign in to comment.