Skip to content

Commit

Permalink
fix: not scrolling to bottom on sending message
Browse files Browse the repository at this point in the history
Closes #4186
The bug was introduced in fecdbbe,
#4145
  • Loading branch information
WofWca committed Oct 7, 2024
1 parent 427ad76 commit e823699
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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
- improved performance a bit #4145, #4188
- show contact / group name when pasting invite link in the search field #4151
- Update local help (2024-10-02) #4165
- trim whitepaces when reading from clipboard in qr code reader #4169
Expand Down
35 changes: 31 additions & 4 deletions packages/frontend/src/stores/messagelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,37 @@ class MessageListStore extends Store<MessageListState> {

if (messagesAlreadyLoaded) {
newMessageCache = this.state.messageCache
oldestFetchedMessageListItemIndex =
this.state.oldestFetchedMessageListItemIndex
newestFetchedMessageListItemIndex =
this.state.newestFetchedMessageListItemIndex

// Why do we need `Math.min` / `Math.max` here, instead of simply
// keeping `this.state.oldestFetchedMessageListItemIndex`
// and `this.state.newestFetchedMessageListItemIndex` as they are?
// Because some other code might update the state in such a way
// that `messageCache` and these
// `(oldest|newest)FetchedMessageListItemIndex` are out of sync:
// `messageCache` actually has a message, but
// these integers say that the message is not yet fetched.
// Namely, this can happen inside of `messageChanged` when
// it gets invoked for a not yet fetched message, and it gets
// added `messageCache` instead of getting updated.
// This, in turn, can happen when you send a message.
//
// The result would be that we'd fail to jump to message inside of
// `MessageList.tsx`, because the message wouldn't be rendered,
// because we only render messages that are between
// `oldestFetchedMessageListItemIndex` and
// `newestFetchedMessageListItemIndex` (see `activeView`).
//
// TODO it would be ideal to get ensure that we don't corrupt
// the state in the first place, but let's make
// this workaround for now.
oldestFetchedMessageListItemIndex = Math.min(
this.state.oldestFetchedMessageListItemIndex,
oldestFetchedMessageListItemIndex
)
newestFetchedMessageListItemIndex = Math.max(
this.state.newestFetchedMessageListItemIndex,
newestFetchedMessageListItemIndex
)
} else {
newMessageCache =
(await loadMessages(
Expand Down

0 comments on commit e823699

Please sign in to comment.