diff --git a/ts/models/messages.ts b/ts/models/messages.ts index 5774fa2af0..038a977d03 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -21,7 +21,7 @@ import { import type { SentEventData } from '../textsecure/messageReceiverEvents'; import { isNotNil } from '../util/isNotNil'; import { isNormalNumber } from '../util/isNormalNumber'; -import { strictAssert } from '../util/assert'; +import { softAssert, strictAssert } from '../util/assert'; import { missingCaseError } from '../util/missingCaseError'; import { dropNull } from '../util/dropNull'; import type { ConversationModel } from './conversations'; @@ -324,16 +324,16 @@ export class MessageModel extends window.Backbone.Model { if (!message) { const conversation = this.getConversation(); - strictAssert( + softAssert( conversation && isDirectConversation(conversation.attributes), - 'Hydrating story context on a non-private conversation' + 'hydrateStoryContext: Not a type=direct conversation' ); this.set({ storyReplyContext: { attachment: undefined, // This is ok to do because story replies only show in 1:1 conversations // so the story that was quoted should be from the same conversation. - authorUuid: conversation.get('uuid'), + authorUuid: conversation?.get('uuid'), // No messageId, referenced story not found! messageId: '', }, diff --git a/ts/sql/Server.ts b/ts/sql/Server.ts index 1675d13863..88efea4234 100644 --- a/ts/sql/Server.ts +++ b/ts/sql/Server.ts @@ -2869,7 +2869,11 @@ async function getConversationRangeCenteredOnMessage({ sentAt, storyId, }), - metrics: getMessageMetricsForConversationSync(conversationId, storyId), + metrics: getMessageMetricsForConversationSync( + conversationId, + storyId, + isGroup + ), }; })(); } diff --git a/ts/util/assert.ts b/ts/util/assert.ts index 2206de0c48..dcc125d25d 100644 --- a/ts/util/assert.ts +++ b/ts/util/assert.ts @@ -4,6 +4,21 @@ import { getEnvironment, Environment } from '../environment'; import * as log from '../logging/log'; +/** + * In production and beta, logs a warning and continues. For development it + * starts the debugger. + */ +export function softAssert(condition: unknown, message: string): void { + if (!condition) { + if (getEnvironment() === Environment.Development) { + debugger; // eslint-disable-line no-debugger + } + + const err = new Error(message); + log.warn('softAssert failure:', err && err.stack ? err.stack : err); + } +} + /** * In production, logs an error and continues. In all other environments, throws an error. */