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

fix: not scrolling to bottom on sending message #4188

Merged
merged 1 commit into from
Oct 8, 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 @@ -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
Loading