Skip to content

Commit

Permalink
fix: onEventMessagesChanged: handle msgId == 0
Browse files Browse the repository at this point in the history
This cause the message list to be empty when the chat gets opened,
and not update on some events.

Reproduction steps are roughly as follows:
1. Create two accounts
2. On Alice, send ~20 messages to Bob.
3. Switch to Bob's account and open the chat with Alice.
  Do not scroll to bottom.
4. Switch to Alice account and send another message to Bob.
5. Switch to Bob's account and open the chat with Alice.

You will see the `Failed to load message Msg#0 for account` error
in the console and the chat will be empty.

The bug was introduced in 7a968b6
(#4529).

The added `messageId > C.DC_MSG_ID_LAST_SPECIAL` in the first `if`
is purely for consistency and performance.
It's the second one that matters.
  • Loading branch information
WofWca committed Jan 25, 2025
1 parent b017715 commit 432bff1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Changed

### Fixed
- message list being empty when opening a chat in some cases #4555
- numpad "Enter" not working as regular "Enter" #4546
- improve performance a little

Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/src/stores/messagelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ class MessageListStore extends Store<MessageListState> {
onEventMessagesChanged: this.scheduler.queuedEffect(
async (messageId: number) => {
if (
messageId > C.DC_MSG_ID_LAST_SPECIAL &&
this.state.messageListItems.findIndex(
m => m.kind === 'message' && m.msg_id === messageId
) !== -1
Expand Down Expand Up @@ -954,6 +955,7 @@ class MessageListStore extends Store<MessageListState> {
// perhaps by moving `getLastKnownScrollPosition()`
// to the render function of `MessageList`.
if (
messageId > C.DC_MSG_ID_LAST_SPECIAL &&
(await BackendRemote.rpc.getMessage(this.accountId, messageId))
.state === C.DC_STATE_OUT_DRAFT
) {
Expand Down

0 comments on commit 432bff1

Please sign in to comment.