Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: make jumpToMessage a tiny bit faster #4206

Merged
merged 1 commit into from
Oct 12, 2024
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- windows 64bit and 32bit protable and setup now have different filenames #4131
- scroll the selected account into view in the accounts sidebar #4137
- dev: clarify scrolling-related code #4121
- improved performance a bit #4145, #4188
- improved performance a bit #4145, #4188, #4206
- show contact / group name & avatar when pasting invite link in the search field #4151, #4178
- Update local help (2024-10-02) #4165
- trim whitepaces when reading from clipboard in qr code reader #4169
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const contextMenuFactory = (
},
{
label: tx('show_in_chat'),
action: () => jumpToMessage(accountId, message.id),
action: () => jumpToMessage(accountId, message.id, message.chatId),
},
{
label: tx('info'),
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ export function useDraft(

// TODO perf: jumpToMessage is not instant, but it should be
// since the message is (almost?) always already rendered.
jumpToMessage(accountId, messageId, true)
jumpToMessage(accountId, messageId, chatId, true)
}
// TODO perf: I imagine this is pretty slow, given IPC and some chats
// being quite large. Perhaps we could hook into the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const DisplayedStickerPack = ({
const stickerPath = fileName.replace('file://', '')
BackendRemote.rpc
.sendSticker(accountId, chatId, stickerPath)
.then(id => jumpToMessage(accountId, id, false))
.then(id => jumpToMessage(accountId, id, chatId, false))
setShowEmojiPicker(false)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ function buildContextMenu(
label: tx('show_in_chat'),
action: () => {
closeDialogCallback()
setTimeout(() => jumpToMessage(accountId, message.id, true))
setTimeout(() =>
jumpToMessage(accountId, message.id, message.chatId, true)
)
},
},
// Show Webxdc in Chat
Expand All @@ -53,7 +55,10 @@ function buildContextMenu(
action: () => {
if (message.parentId) {
closeDialogCallback()
jumpToMessage(accountId, message.parentId, true)
// Currently the info message is always in the same chat
// as the message with `message.parentId`,
// but let's not pass `chatId` here, for future-proofing.
jumpToMessage(accountId, message.parentId, undefined, true)
}
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function ForwardMessage(props: Props) {
)
const lastMessage = messageIds[messageIds.length - 1]
if (lastMessage) {
jumpToMessage(accountId, lastMessage)
jumpToMessage(accountId, lastMessage, chatId)
}
} else {
selectChat(accountId, message.chatId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default function FullscreenMedia(props: Props & DialogProps) {
{
label: tx('show_in_chat'),
action: () => {
jumpToMessage(accountId, msg.id)
jumpToMessage(accountId, msg.id, msg.chatId)
onClose()
},
},
Expand Down
16 changes: 14 additions & 2 deletions packages/frontend/src/components/message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,13 @@ export default function Message(props: {
if (isInteractive) {
onClick = async () => {
if (isWebxdcInfo && message.parentId) {
jumpToMessage(accountId, message.parentId, true, message.id)
jumpToMessage(
accountId,
message.parentId,
undefined,
true,
message.id
)
} else if (isProtectionBrokenMsg) {
const { name } = await BackendRemote.rpc.getBasicChatInfo(
selectedAccountId(),
Expand Down Expand Up @@ -738,7 +744,13 @@ export const Quote = ({
className='quote-background'
onClick={() => {
quote.kind === 'WithMessage' &&
jumpToMessage(accountId, quote.messageId, true, msgParentId)
jumpToMessage(
accountId,
quote.messageId,
undefined,
true,
msgParentId
)
}}
>
<div
Expand Down
19 changes: 15 additions & 4 deletions packages/frontend/src/hooks/chat/useMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import type { T } from '@deltachat/jsonrpc-client'
export type JumpToMessage = (
accountId: number,
msgId: number,
/**
* Optional, but if it is known, it's best to provide it
* for better performance.
* When provided, the caller guarantees that
* `msgChatId === await rpc.getMessage(accountId, msgId)).chatId`.
*/
msgChatId?: number,
highlight?: boolean,
msgParentId?: number
) => Promise<void>
Expand Down Expand Up @@ -51,15 +58,19 @@ export default function useMessage() {
async (
accountId: number,
msgId: number,
msgChatId?: number,
highlight = true,
msgParentId?: number
) => {
log.debug(`jumpToMessage with messageId: ${msgId}`)

if (msgChatId == undefined) {
msgChatId = (await BackendRemote.rpc.getMessage(accountId, msgId))
.chatId
}
// Check if target message is in same chat, if not switch first
const message = await BackendRemote.rpc.getMessage(accountId, msgId)
if (message.chatId !== chatId) {
await selectChat(accountId, message.chatId)
if (msgChatId !== chatId) {
await selectChat(accountId, msgChatId)
}
setChatView(ChatView.MessageList)

Expand All @@ -83,7 +94,7 @@ export default function useMessage() {
})

// Jump down on sending
jumpToMessage(accountId, id, false)
jumpToMessage(accountId, id, chatId, false)
},
[jumpToMessage]
)
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/hooks/useVideoChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function useVideoChat() {
accountId,
chatId
)
jumpToMessage(accountId, messageId, false)
jumpToMessage(accountId, messageId, chatId, false)
await joinVideoChat(accountId, messageId)
} catch (error: todo) {
log.error('failed send call invitation', error)
Expand Down
Loading