Assert presence of sent_at timestamp for receipts
This commit is contained in:
parent
9a7f1e86e2
commit
9d1252ae19
1 changed files with 46 additions and 25 deletions
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2021 Signal Messenger, LLC
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { omit } from 'lodash';
|
import { omit, isNumber } from 'lodash';
|
||||||
|
|
||||||
import type { ConversationAttributesType } from '../model-types.d';
|
import type { ConversationAttributesType } from '../model-types.d';
|
||||||
import { hasErrors } from '../state/selectors/message';
|
import { hasErrors } from '../state/selectors/message';
|
||||||
|
@ -13,6 +13,8 @@ import { isGroup, isDirectConversation } from './whatTypeOfConversation';
|
||||||
import * as log from '../logging/log';
|
import * as log from '../logging/log';
|
||||||
import { getConversationIdForLogging } from './idForLogging';
|
import { getConversationIdForLogging } from './idForLogging';
|
||||||
import { drop } from './drop';
|
import { drop } from './drop';
|
||||||
|
import { isNotNil } from './isNotNil';
|
||||||
|
import { assertDev } from './assert';
|
||||||
import { isConversationAccepted } from './isConversationAccepted';
|
import { isConversationAccepted } from './isConversationAccepted';
|
||||||
import { ReadStatus } from '../messages/MessageReadStatus';
|
import { ReadStatus } from '../messages/MessageReadStatus';
|
||||||
import {
|
import {
|
||||||
|
@ -52,8 +54,10 @@ export async function markConversationRead(
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
log.info('markConversationRead', {
|
const convoId = getConversationIdForLogging(conversationAttrs);
|
||||||
conversationId: getConversationIdForLogging(conversationAttrs),
|
const logId = `markConversationRead(${convoId})`;
|
||||||
|
|
||||||
|
log.info(logId, {
|
||||||
newestSentAt: options.newestSentAt,
|
newestSentAt: options.newestSentAt,
|
||||||
newestUnreadAt,
|
newestUnreadAt,
|
||||||
unreadMessages: unreadMessages.length,
|
unreadMessages: unreadMessages.length,
|
||||||
|
@ -94,29 +98,46 @@ export async function markConversationRead(
|
||||||
|
|
||||||
const allUnreadMessages = [...unreadMessages, ...unreadEditedMessages];
|
const allUnreadMessages = [...unreadMessages, ...unreadEditedMessages];
|
||||||
|
|
||||||
const allReadMessagesSync = allUnreadMessages.map(messageSyncData => {
|
const allReadMessagesSync = allUnreadMessages
|
||||||
|
.map(messageSyncData => {
|
||||||
const message = window.MessageController.getById(messageSyncData.id);
|
const message = window.MessageController.getById(messageSyncData.id);
|
||||||
// we update the in-memory MessageModel with the fresh database call data
|
// we update the in-memory MessageModel with the fresh database call data
|
||||||
if (message) {
|
if (message) {
|
||||||
message.set(omit(messageSyncData, 'originalReadStatus'));
|
message.set(omit(messageSyncData, 'originalReadStatus'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
sent_at: timestamp,
|
||||||
|
source: senderE164,
|
||||||
|
sourceUuid: senderUuid,
|
||||||
|
} = messageSyncData;
|
||||||
|
|
||||||
|
if (!isNumber(timestamp)) {
|
||||||
|
assertDev(
|
||||||
|
false,
|
||||||
|
`${logId}: message sent_at timestamp is not number` +
|
||||||
|
`type=${messageSyncData.type}`
|
||||||
|
);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messageId: messageSyncData.id,
|
messageId: messageSyncData.id,
|
||||||
conversationId: conversationAttrs.id,
|
conversationId: conversationAttrs.id,
|
||||||
originalReadStatus: messageSyncData.originalReadStatus,
|
originalReadStatus: messageSyncData.originalReadStatus,
|
||||||
senderE164: messageSyncData.source,
|
senderE164,
|
||||||
senderUuid: messageSyncData.sourceUuid,
|
senderUuid,
|
||||||
senderId: window.ConversationController.lookupOrCreate({
|
senderId: window.ConversationController.lookupOrCreate({
|
||||||
e164: messageSyncData.source,
|
e164: senderE164,
|
||||||
uuid: messageSyncData.sourceUuid,
|
uuid: senderUuid,
|
||||||
reason: 'markConversationRead',
|
reason: 'markConversationRead',
|
||||||
})?.id,
|
})?.id,
|
||||||
timestamp: messageSyncData.sent_at,
|
timestamp,
|
||||||
isDirectConversation: isDirectConversation(conversationAttrs),
|
isDirectConversation: isDirectConversation(conversationAttrs),
|
||||||
hasErrors: message ? hasErrors(message.attributes) : false,
|
hasErrors: message ? hasErrors(message.attributes) : false,
|
||||||
};
|
};
|
||||||
});
|
})
|
||||||
|
.filter(isNotNil);
|
||||||
|
|
||||||
// Some messages we're marking read are local notifications with no sender or were just
|
// Some messages we're marking read are local notifications with no sender or were just
|
||||||
// unseen and not unread.
|
// unseen and not unread.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue