Ensure that seenStatus is always updated along with readStatus

This commit is contained in:
Scott Nonnenberg 2022-04-29 16:42:47 -07:00 committed by GitHub
parent 925b89b3a9
commit e078a2ae54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 10 deletions

View file

@ -1,6 +1,8 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { omit } from 'lodash';
import type { ConversationAttributesType } from '../model-types.d';
import { hasErrors } from '../state/selectors/message';
import { readReceiptsJobQueue } from '../jobs/readReceiptsJobQueue';
@ -9,6 +11,7 @@ import { notificationService } from '../services/notifications';
import { isGroup } from './whatTypeOfConversation';
import * as log from '../logging/log';
import { getConversationIdForLogging } from './idForLogging';
import { ReadStatus } from '../messages/MessageReadStatus';
export async function markConversationRead(
conversationAttrs: ConversationAttributesType,
@ -76,11 +79,12 @@ export async function markConversationRead(
const message = window.MessageController.getById(messageSyncData.id);
// we update the in-memory MessageModel with the fresh database call data
if (message) {
message.set(messageSyncData);
message.set(omit(messageSyncData, 'originalReadStatus'));
}
return {
messageId: messageSyncData.id,
originalReadStatus: messageSyncData.originalReadStatus,
senderE164: messageSyncData.source,
senderUuid: messageSyncData.sourceUuid,
senderId: window.ConversationController.ensureContactIds({
@ -92,14 +96,18 @@ export async function markConversationRead(
};
});
// Some messages we're marking read are local notifications with no sender
// If a message has errors, we don't want to send anything out about it.
// Some messages we're marking read are local notifications with no sender or were just
// unseen and not unread.
// Also, if a message has errors, we don't want to send anything out about it:
// read syncs - let's wait for a client that really understands the message
// to mark it read. we'll mark our local error read locally, though.
// read receipts - here we can run into infinite loops, where each time the
// conversation is viewed, another error message shows up for the contact
const unreadMessagesSyncData = allReadMessagesSync.filter(
item => Boolean(item.senderId) && !item.hasErrors
item =>
Boolean(item.senderId) &&
item.originalReadStatus === ReadStatus.Unread &&
!item.hasErrors
);
const readSyncs: Array<{