-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: cannot load previous messages when lastMessage thread exceeds 50 messages #6680
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
+79
−11
Merged
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
cedc45b
fix: update lastMesssage as thread and avoid load more
OtavioStasiak 26da048
fix: new loading
OtavioStasiak 370e90e
chore: update thread messages if only have threads
OtavioStasiak af3bd46
fix: use loadPreviousMessages to avoid duplicated requests
OtavioStasiak b82fd67
Merge branch 'develop' into fix.load-more-at-bottom
OtavioStasiak 369e401
chore: code improvements
OtavioStasiak 0707ed3
fix: rollback fetch on useMessages
OtavioStasiak be4cf30
chore: refactor loadMessagesForRoom
OtavioStasiak 48e4771
Merge branch 'develop' into fix.load-more-at-bottom
OtavioStasiak 20c7da6
fix: load messages for room code improvements
OtavioStasiak 79a4bce
chore: e2e tests
OtavioStasiak 17d786c
Merge branch 'develop' into fix.load-more-at-bottom
OtavioStasiak 48e876d
fix: remove unused logs
OtavioStasiak 4bfe21c
chore: format code with Prettier [skip ci]
OtavioStasiak 964d19f
Merge branch 'develop' into fix.load-more-at-bottom
OtavioStasiak 8cccb16
fix: duplicaded code
OtavioStasiak 9c8e8ea
fix: loadMoreMessage not added
OtavioStasiak 01d6c61
Merge branch 'develop' into fix.load-more-at-bottom
OtavioStasiak 5b9d71f
fix: remove unused logs
OtavioStasiak b754054
chore: code improvements
OtavioStasiak 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
Some comments aren't visible on the classic Files Changed page.
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
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,71 @@ | ||
| import { compareServerVersion } from './helpers'; | ||
| import updateMessages from './updateMessages'; | ||
| import sdk from '../services/sdk'; | ||
| import { store } from '../store/auxStore'; | ||
| import { getSubscriptionByRoomId } from '../database/services/Subscription'; | ||
|
|
||
| const count = 50; | ||
|
|
||
| const syncMessages = async ({ roomId, previous, type }: { roomId: string; previous: number; type: 'UPDATED' | 'DELETED' }) => { | ||
| // @ts-ignore // this method dont have type | ||
| const { result } = await sdk.get('chat.syncMessages', { roomId, previous, count, type }); | ||
| return result; | ||
| }; | ||
|
|
||
| const getSyncMessagesFromCursor = async (roomId: string, lastOpen: number) => { | ||
| const promises = []; | ||
|
|
||
| if (lastOpen) { | ||
| promises.push(syncMessages({ roomId, previous: lastOpen, type: 'UPDATED' })); | ||
| promises.push(syncMessages({ roomId, previous: lastOpen, type: 'DELETED' })); | ||
| } | ||
|
|
||
| const [updatedMessages, deletedMessages] = await Promise.all(promises); | ||
| return { | ||
| deleted: deletedMessages?.deleted ?? [], | ||
| deletedNext: deletedMessages?.cursor.next, | ||
| updated: updatedMessages?.updated ?? [], | ||
| updatedNext: updatedMessages?.cursor.next | ||
| }; | ||
| }; | ||
|
|
||
| const getLastUpdate = async (rid: string) => { | ||
| const sub = await getSubscriptionByRoomId(rid); | ||
| if (!sub) { | ||
| return null; | ||
| } | ||
| return sub.lastOpen; | ||
| }; | ||
|
|
||
| async function loadPreviousMessages({ rid: roomId, lastOpen }: { rid: string; lastOpen?: Date }) { | ||
| const { version: serverVersion } = store.getState().server; | ||
| if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '7.1.0')) { | ||
| let lastOpenTimestamp; | ||
| if (lastOpen) { | ||
| lastOpenTimestamp = new Date(lastOpen).getTime(); | ||
| } else { | ||
| const lastUpdate = await getLastUpdate(roomId); | ||
| lastOpenTimestamp = lastUpdate?.getTime(); | ||
| } | ||
| if (!lastOpenTimestamp) { | ||
| return; | ||
| } | ||
| const result = await getSyncMessagesFromCursor(roomId, lastOpenTimestamp); | ||
|
|
||
| await updateMessages({ rid: roomId, update: result.updated, remove: result.deleted }); | ||
| } | ||
|
|
||
| let lastOpenISOString; | ||
| if (lastOpen) { | ||
| lastOpenISOString = new Date(lastOpen).toISOString(); | ||
| } else { | ||
| const lastUpdate = await getLastUpdate(roomId); | ||
| lastOpenISOString = lastUpdate?.toISOString(); | ||
| } | ||
| // RC 0.60.0 | ||
| // @ts-ignore // this method dont have type | ||
| const { result } = await sdk.get('chat.syncMessages', { roomId, lastUpdate: lastOpenISOString }); | ||
| return result; | ||
| } | ||
|
|
||
| export default loadPreviousMessages; | ||
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.
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.