Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
7 changes: 7 additions & 0 deletions .changeset/bright-dots-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@rocket.chat/meteor': patch
'@rocket.chat/model-typings': patch
'@rocket.chat/models': patch
---

Fixes main channel scroll position changing when jumping to a thread message from search
4 changes: 2 additions & 2 deletions apps/meteor/app/ui-utils/client/lib/RoomHistoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class RoomHistoryManagerClass extends Emitter {
room.loaded = undefined;
}

public async getSurroundingMessages(message?: Pick<IMessage, '_id' | 'rid'> & { ts?: Date }) {
public async getSurroundingMessages(message?: Pick<IMessage, '_id' | 'rid'> & { ts?: Date }, showThreadMessages = true) {
Comment thread
aleksandernsilva marked this conversation as resolved.
Outdated
if (!message?.rid) {
return;
}
Expand All @@ -309,7 +309,7 @@ class RoomHistoryManagerClass extends Emitter {
const room = this.getRoom(message.rid);

const subscription = Subscriptions.state.find((record) => record.rid === message.rid);
const result = await callWithErrorHandling('loadSurroundingMessages', message, defaultLimit);
const result = await callWithErrorHandling('loadSurroundingMessages', message, defaultLimit, showThreadMessages);

this.clear(message.rid);

Expand Down
12 changes: 9 additions & 3 deletions apps/meteor/client/lib/utils/legacyJumpToMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ export const legacyJumpToMessage = async (message: IMessage) => {
routeParamsOverrides: { tab: 'thread', context: message.tmid || message._id },
replace: RoomManager.opened === message.rid,
});
await RoomHistoryManager.getSurroundingMessages(message);

if (message.tcount) {
await RoomHistoryManager.getSurroundingMessages(message, false);
} else if (!RoomHistoryManager.isLoaded(message.rid)) {
await RoomHistoryManager.getMore(message.rid);
}

return;
}

if (RoomManager.opened === message.rid) {
await RoomHistoryManager.getSurroundingMessages(message);
await RoomHistoryManager.getSurroundingMessages(message, false);
return;
}

await goToRoomById(message.rid);

await RoomHistoryManager.getSurroundingMessages(message);
await RoomHistoryManager.getSurroundingMessages(message, false);
};
24 changes: 14 additions & 10 deletions apps/meteor/client/views/room/body/hooks/useGetMore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,36 @@ export const useGetMore = (rid: string, atBottomRef: MutableRefObject<boolean>)
return;
}

const { scrollTop, clientHeight, scrollHeight } = getBoundingClientRect(element);
if (jumpToRef.current) {
return;
}

if (RoomHistoryManager.isLoading(rid)) {
return;
}

if (msgIdRef.current && !RoomHistoryManager.isLoaded(rid)) {
return;
}

const { scrollTop, clientHeight, scrollHeight } = getBoundingClientRect(element);

const lastScrollTopRef = scrollTop;
const height = clientHeight;
const isLoading = RoomHistoryManager.isLoading(rid);
const hasMore = RoomHistoryManager.hasMore(rid);
const hasMoreNext = RoomHistoryManager.hasMoreNext(rid);

if (jumpToRef.current) {
return;
}

if (isLoading) {
return;
}

if (hasMore === true && lastScrollTopRef <= height / 3) {
await RoomHistoryManager.getMore(rid);

if (jumpToRef.current) {
return;
}

if (!element.isConnected) {
return;
}

flushSync(() => {
RoomHistoryManager.restoreScroll(rid);
});
Expand Down
18 changes: 15 additions & 3 deletions apps/meteor/server/methods/loadSurroundingMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ declare module '@rocket.chat/ddp-client' {
loadSurroundingMessages(
message: Pick<IMessage, '_id' | 'rid'> & { ts?: Date },
limit?: number,
showThreadMessages?: boolean,
):
| {
messages: IMessage[];
Expand All @@ -25,9 +26,10 @@ declare module '@rocket.chat/ddp-client' {
}

Meteor.methods<ServerMethods>({
Comment thread
aleksandernsilva marked this conversation as resolved.
async loadSurroundingMessages(message, limit = 50) {
async loadSurroundingMessages(message, limit = 50, showThreadMessages = true) {
check(message, Object);
check(limit, Number);
Comment thread
aleksandernsilva marked this conversation as resolved.
check(showThreadMessages, Boolean);

if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
Expand Down Expand Up @@ -60,7 +62,12 @@ Meteor.methods<ServerMethods>({
limit: Math.ceil(limit / 2),
};

const messages = await Messages.findVisibleByRoomIdBeforeTimestamp(mainMessage.rid, mainMessage.ts, options).toArray();
const messages = await Messages.findVisibleByRoomIdBeforeTimestamp(
mainMessage.rid,
mainMessage.ts,
options,
showThreadMessages,
).toArray();

const moreBefore = messages.length === options.limit;

Expand All @@ -72,7 +79,12 @@ Meteor.methods<ServerMethods>({

options.limit = Math.floor(limit / 2);

const afterMessages = await Messages.findVisibleByRoomIdAfterTimestamp(mainMessage.rid, mainMessage.ts, options).toArray();
const afterMessages = await Messages.findVisibleByRoomIdAfterTimestamp(
mainMessage.rid,
mainMessage.ts,
options,
showThreadMessages,
).toArray();

const moreAfter = afterMessages.length === options.limit;

Expand Down
Loading
Loading