Repository navigation
fix: thread content disappears after jumping to recent messages #39859
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
Merged
dionisio-bot
merged 12 commits into
develop
from
fix/thread-content-disappears-on-jump-to-recent
May 5, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b833369
separate thread and main message stores to prevent thread content reset
abhinavkrin 9b9c8ca
modify onClientMessageReceived to update threads messages cache
abhinavkrin cccb1f2
added tests
abhinavkrin e105384
remove useLegacyThreadMessages.ts
abhinavkrin aee531c
added changest
abhinavkrin 346767e
Merge branch 'develop' into fix/thread-content-disappears-on-jump-to-…
abhinavkrin c86a56d
subscribe messageRead
abhinavkrin 861c4b6
subscribe to readMessage in useThreadMainMessagesQuery.ts
abhinavkrin f48ba59
fixes
abhinavkrin 694ad52
fix: thread message not marked read when last user to read it opens t…
abhinavkrin e2d71c8
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into fix/…
abhinavkrin be60d75
Merge branch 'develop' into fix/thread-content-disappears-on-jump-to-…
abhinavkrin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@rocket.chat/meteor': patch | ||
| --- | ||
|
|
||
| Fixes an issue where thread content would disappear after clicking "Jump to recent messages". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import type { IMessage, IThreadMessage, MessageAttachment } from '@rocket.chat/core-typings'; | ||
| import { createPredicateFromFilter } from '@rocket.chat/mongo-adapter'; | ||
| import type { QueryClient } from '@tanstack/react-query'; | ||
| import type { Condition, Filter } from 'mongodb'; | ||
|
|
||
| import { queryClient as defaultQueryClient } from '../queryClient'; | ||
| import { roomsQueryKeys } from '../queryKeys'; | ||
|
|
||
| export type NotifyRoomRidDeleteBulkEvent = { | ||
| rid: IMessage['rid']; | ||
| excludePinned: boolean; | ||
| ignoreDiscussion: boolean; | ||
| ts: Condition<Date>; | ||
| users: string[]; | ||
| ids?: string[]; | ||
| showDeletedStatus?: boolean; | ||
| } & ( | ||
| | { | ||
| filesOnly: true; | ||
| replaceFileAttachmentsWith?: MessageAttachment; | ||
| } | ||
| | { | ||
| filesOnly?: false; | ||
| } | ||
| ); | ||
|
|
||
| export const createDeleteCriteria = (params: NotifyRoomRidDeleteBulkEvent): ((message: IMessage) => boolean) => { | ||
| const query: Filter<IMessage> = {}; | ||
|
|
||
| if (params.ids) { | ||
| query._id = { $in: params.ids }; | ||
| } else { | ||
| query.ts = params.ts; | ||
| } | ||
|
|
||
| if (params.excludePinned) { | ||
| query.pinned = { $ne: true }; | ||
| } | ||
|
|
||
| if (params.ignoreDiscussion) { | ||
| query.drid = { $exists: false }; | ||
| } | ||
| if (params.users?.length) { | ||
| query['u.username'] = { $in: params.users }; | ||
| } | ||
|
|
||
| return createPredicateFromFilter(query); | ||
| }; | ||
|
|
||
| export const upsertThreadMessageInCache = ( | ||
| message: IMessage, | ||
| rid: IMessage['rid'], | ||
| tmid: IMessage['_id'], | ||
| client: QueryClient = defaultQueryClient, | ||
| ): void => { | ||
| const queryKey = roomsQueryKeys.threadMessages(rid, tmid); | ||
| client.setQueryData<IMessage[]>(queryKey, (old) => { | ||
| if (!old) { | ||
| return [message]; | ||
| } | ||
| const idx = old.findIndex((m) => m._id === message._id); | ||
| if (idx >= 0) { | ||
| const updated = [...old]; | ||
| updated[idx] = message; | ||
| return updated; | ||
| } | ||
| return [...old, message].sort((a, b) => new Date(a.ts).getTime() - new Date(b.ts).getTime()); | ||
| }); | ||
| }; | ||
|
|
||
| export const markThreadMessagesAsRead = (messages: IThreadMessage[], until?: Date): IThreadMessage[] => { | ||
| return messages.map((msg) => { | ||
| if (!msg.unread) { | ||
| return msg; | ||
| } | ||
| if (until && new Date(msg.ts) > until) { | ||
| return msg; | ||
| } | ||
| const { unread: _, ...rest } = msg; | ||
| return rest as IThreadMessage; | ||
| }); | ||
| }; | ||
|
|
||
| export const mergeThreadMessages = (cachedMessages: IThreadMessage[], fetchedMessages: IThreadMessage[]): IThreadMessage[] => { | ||
| const messageMap = new Map<string, IThreadMessage>(); | ||
|
|
||
| for (const msg of cachedMessages) { | ||
| messageMap.set(msg._id, msg); | ||
| } | ||
|
|
||
| for (const msg of fetchedMessages) { | ||
| const existing = messageMap.get(msg._id); | ||
| if (!existing) { | ||
| messageMap.set(msg._id, msg); | ||
| } else { | ||
| const msgTime = new Date(msg._updatedAt ?? msg.ts).getTime(); | ||
| const existingTime = new Date(existing._updatedAt ?? existing.ts).getTime(); | ||
| if (msgTime > existingTime) { | ||
| messageMap.set(msg._id, msg); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return Array.from(messageMap.values()).sort((a, b) => new Date(a.ts).getTime() - new Date(b.ts).getTime()); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
apps/meteor/client/views/room/contextualBar/Threads/hooks/useLegacyThreadMessages.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.