From 74b8a0f10f36147b908d6cccb06cacd83546daee Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Thu, 9 Dec 2021 12:00:19 +0530 Subject: [PATCH] Fix msg not auto loading backwards Signed-off-by: Ajay Bura --- src/app/organisms/room/RoomViewContent.jsx | 13 ++++++------- src/client/state/RoomTimeline.js | 11 +++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/app/organisms/room/RoomViewContent.jsx b/src/app/organisms/room/RoomViewContent.jsx index 0a5e9c6..2b2a274 100644 --- a/src/app/organisms/room/RoomViewContent.jsx +++ b/src/app/organisms/room/RoomViewContent.jsx @@ -346,18 +346,17 @@ function usePaginate(roomTimeline, readEventStore, forceUpdateLimit) { const [info, setInfo] = useState(null); useEffect(() => { - const handleOnPagination = (backwards, loaded, canLoadMore) => { + const handleOnPagination = (backwards, loaded) => { if (loaded === 0) return; if (!readEventStore.getItem()) { const readUpToId = roomTimeline.getReadUpToEventId(); readEventStore.setItem(roomTimeline.findEventByIdInTimelineSet(readUpToId)); } limit.setFrom(limit.calcNextFrom(backwards, roomTimeline.timeline.length)); - setInfo({ + setTimeout(() => setInfo({ backwards, loaded, - canLoadMore, - }); + })); }; roomTimeline.on(cons.events.roomTimeline.PAGINATED, handleOnPagination); return () => { @@ -365,7 +364,7 @@ function usePaginate(roomTimeline, readEventStore, forceUpdateLimit) { }; }, [roomTimeline]); - const autoPaginate = useCallback(() => { + const autoPaginate = useCallback(async () => { if (roomTimeline.isOngoingPagination) return; const tLength = roomTimeline.timeline.length; @@ -376,7 +375,7 @@ function usePaginate(roomTimeline, readEventStore, forceUpdateLimit) { forceUpdateLimit(); } else if (roomTimeline.canPaginateForward()) { // paginate from server. - roomTimeline.paginateTimeline(false, PAG_LIMIT); + await roomTimeline.paginateTimeline(false, PAG_LIMIT); return; } } @@ -387,7 +386,7 @@ function usePaginate(roomTimeline, readEventStore, forceUpdateLimit) { forceUpdateLimit(); } else if (roomTimeline.canPaginateBackward()) { // paginate from server. - roomTimeline.paginateTimeline(true, PAG_LIMIT); + await roomTimeline.paginateTimeline(true, PAG_LIMIT); } } }, [roomTimeline]); diff --git a/src/client/state/RoomTimeline.js b/src/client/state/RoomTimeline.js index b6800ab..b6a5c14 100644 --- a/src/client/state/RoomTimeline.js +++ b/src/client/state/RoomTimeline.js @@ -90,7 +90,7 @@ class RoomTimeline extends EventEmitter { } canPaginateBackward() { - if (this.timeline[0].getType() === 'm.room.create') return false; + if (this.timeline[0]?.getType() === 'm.room.create') return false; const tm = getFirstLinkedTimeline(this.activeTimeline); return tm.getPaginationToken('b') !== null; } @@ -173,26 +173,25 @@ class RoomTimeline extends EventEmitter { : getLastLinkedTimeline(this.activeTimeline); if (timelineToPaginate.getPaginationToken(backwards ? 'b' : 'f') === null) { + this.emit(cons.events.roomTimeline.PAGINATED, backwards, 0); this.isOngoingPagination = false; - this.emit(cons.events.roomTimeline.PAGINATED, backwards, 0, false); return false; } const oldSize = this.timeline.length; try { - const canPaginateMore = await this.matrixClient - .paginateEventTimeline(timelineToPaginate, { backwards, limit }); + await this.matrixClient.paginateEventTimeline(timelineToPaginate, { backwards, limit }); if (this.isEncrypted()) await this.decryptAllEventsOfTimeline(this.activeTimeline); this._populateTimelines(); const loaded = this.timeline.length - oldSize; + this.emit(cons.events.roomTimeline.PAGINATED, backwards, loaded); this.isOngoingPagination = false; - this.emit(cons.events.roomTimeline.PAGINATED, backwards, loaded, canPaginateMore); return true; } catch { + this.emit(cons.events.roomTimeline.PAGINATED, backwards, 0); this.isOngoingPagination = false; - this.emit(cons.events.roomTimeline.PAGINATED, backwards, 0, true); return false; } }