mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
do not fetch all messages for room if user was away for > 2 weeks
This commit is contained in:
parent
ab22126b45
commit
eff4f490f3
|
@ -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…
Reference in a new issue