Merge pull request #1652 from Bilb/fetch-x-messages-long-away

Fetch last messages only when long away from room
pull/1667/head
Audric Ackermann 4 years ago committed by GitHub
commit caf8397d29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,6 +15,10 @@ export type OpenGroupV2Room = {
* This value represents the rowId of the last message deleted. Not the id of the last message ID
*/
lastMessageDeletedServerID?: number;
/**
* This value is set with the current timestamp whenever we get new messages.
*/
lastFetchTimestamp?: number;
token?: string; // currently, the token is on a per room basis
};

@ -188,6 +188,7 @@ const getCompactPollRequest = async (
try {
const {
lastMessageFetchedServerID,
lastFetchTimestamp,
lastMessageDeletedServerID,
token,
roomId,
@ -197,7 +198,13 @@ const getCompactPollRequest = async (
auth_token: token || '',
};
roomRequestContent.from_deletion_server_id = lastMessageDeletedServerID;
roomRequestContent.from_message_server_id = lastMessageFetchedServerID;
if (Date.now() - (lastFetchTimestamp || 0) <= DURATION.DAYS * 14) {
roomRequestContent.from_message_server_id = lastMessageFetchedServerID;
} else {
window?.log?.info(
"We've been away for a long time... Only fetching last messages of room"
);
}
return roomRequestContent;
} catch (e) {
@ -276,7 +283,7 @@ async function sendOpenGroupV2RequestCompactPoll(
roomDetails.token = undefined;
// we might need to retry doing the request here, but how to make sure we don't retry indefinetely?
await saveV2OpenGroupRoom(roomDetails);
// do not await for that. We have a only one at a time logic on a per room basis
// we should not await for that. We have a only one at a time logic on a per room basis
await getAuthToken({ serverUrl, roomId });
})
);

@ -410,6 +410,7 @@ const handleNewMessages = async (
if (roomInfos && roomInfos.lastMessageFetchedServerID !== maxNewMessageId) {
roomInfos.lastMessageFetchedServerID = maxNewMessageId;
roomInfos.lastFetchTimestamp = Date.now();
await saveV2OpenGroupRoom(roomInfos);
}
} catch (e) {

Loading…
Cancel
Save