fix: drop messages from a room left since start of current poll

pull/2475/head
Audric Ackermann 3 years ago
parent 89dfe6e49d
commit aa0c15c8c1

@ -316,12 +316,7 @@ export class OpenGroupServerPoller {
} }
// ==> At this point all those results need to trigger conversation updates, so update what we have to update // ==> At this point all those results need to trigger conversation updates, so update what we have to update
await handleBatchPollResults( await handleBatchPollResults(this.serverUrl, batchPollResults, subrequestOptions);
this.serverUrl,
batchPollResults,
subrequestOptions,
this.roomIdsToPoll
);
} catch (e) { } catch (e) {
window?.log?.warn('Got error while compact fetch:', e.message); window?.log?.warn('Got error while compact fetch:', e.message);
} finally { } finally {

@ -82,8 +82,7 @@ async function handlePollInfoResponse(
hidden_moderators?: Array<string>; hidden_moderators?: Array<string>;
}; };
}, },
serverUrl: string, serverUrl: string
roomIdsStillPolled: Set<string>
) { ) {
if (statusCode !== 200) { if (statusCode !== 200) {
window.log.info('handlePollInfoResponse subRequest status code is not 200:', statusCode); window.log.info('handlePollInfoResponse subRequest status code is not 200:', statusCode);
@ -101,8 +100,9 @@ async function handlePollInfoResponse(
window.log.info('handlePollInfoResponse token and serverUrl must be set'); window.log.info('handlePollInfoResponse token and serverUrl must be set');
return; return;
} }
const stillPolledRooms = OpenGroupData.getV2OpenGroupRoomsByServerUrl(serverUrl);
if (!roomIdsStillPolled.has(token)) { if (!stillPolledRooms?.some(r => r.roomId === token && r.serverUrl === serverUrl)) {
window.log.info('handlePollInfoResponse room is no longer polled: ', token); window.log.info('handlePollInfoResponse room is no longer polled: ', token);
return; return;
} }
@ -188,8 +188,7 @@ const handleSogsV3DeletedMessages = async (
const handleMessagesResponseV4 = async ( const handleMessagesResponseV4 = async (
messages: Array<OpenGroupMessageV4>, messages: Array<OpenGroupMessageV4>,
serverUrl: string, serverUrl: string,
subrequestOption: SubRequestMessagesType, subrequestOption: SubRequestMessagesType
roomIdsStillPolled: Set<string>
) => { ) => {
if (!subrequestOption || !subrequestOption.messages) { if (!subrequestOption || !subrequestOption.messages) {
window?.log?.error('handleBatchPollResults - missing fields required for message subresponse'); window?.log?.error('handleBatchPollResults - missing fields required for message subresponse');
@ -199,7 +198,9 @@ const handleMessagesResponseV4 = async (
try { try {
const { roomId } = subrequestOption.messages; const { roomId } = subrequestOption.messages;
if (!roomIdsStillPolled.has(roomId)) { const stillPolledRooms = OpenGroupData.getV2OpenGroupRoomsByServerUrl(serverUrl);
if (!stillPolledRooms?.some(r => r.roomId === roomId && r.serverUrl === serverUrl)) {
window.log.info(`handleMessagesResponseV4: we are no longer polling for ${roomId}: skipping`); window.log.info(`handleMessagesResponseV4: we are no longer polling for ${roomId}: skipping`);
return; return;
} }
@ -490,8 +491,7 @@ export const handleBatchPollResults = async (
serverUrl: string, serverUrl: string,
batchPollResults: BatchSogsReponse, batchPollResults: BatchSogsReponse,
/** using this as explicit way to ensure order */ /** using this as explicit way to ensure order */
subrequestOptionsLookup: Array<OpenGroupBatchRow>, subrequestOptionsLookup: Array<OpenGroupBatchRow>
roomIdsStillPolled: Set<string> // if we get anything for a room we stopped polling, we need to skip it.
) => { ) => {
// @@: Might not need the explicit type field. // @@: Might not need the explicit type field.
// pro: prevents cases where accidentally two fields for the opt. e.g. capability and message fields truthy. // pro: prevents cases where accidentally two fields for the opt. e.g. capability and message fields truthy.
@ -520,20 +520,10 @@ export const handleBatchPollResults = async (
break; break;
case 'messages': case 'messages':
// this will also include deleted messages explicitly with `data: null` & edited messages with a new data field & react changes with data not existing // this will also include deleted messages explicitly with `data: null` & edited messages with a new data field & react changes with data not existing
await handleMessagesResponseV4( await handleMessagesResponseV4(subResponse.body, serverUrl, subrequestOption);
subResponse.body,
serverUrl,
subrequestOption,
roomIdsStillPolled
);
break; break;
case 'pollInfo': case 'pollInfo':
await handlePollInfoResponse( await handlePollInfoResponse(subResponse.code, subResponse.body, serverUrl);
subResponse.code,
subResponse.body,
serverUrl,
roomIdsStillPolled
);
break; break;
case 'inbox': case 'inbox':
await handleInboxOutboxMessages(subResponse.body, serverUrl, false); await handleInboxOutboxMessages(subResponse.body, serverUrl, false);

Loading…
Cancel
Save