diff --git a/keyserver/src/fetchers/message-fetchers.js b/keyserver/src/fetchers/message-fetchers.js --- a/keyserver/src/fetchers/message-fetchers.js +++ b/keyserver/src/fetchers/message-fetchers.js @@ -24,6 +24,7 @@ defaultMaxMessageAge, type FetchPinnedMessagesRequest, type FetchPinnedMessagesResult, + rawMessageInfoIsNotMessageSidebarSourceReactionOrEdit, } from 'lib/types/message-types.js'; import { threadPermissions } from 'lib/types/thread-types.js'; import { ServerError } from 'lib/utils/errors.js'; @@ -742,13 +743,14 @@ for (const message of messages) { let { rawMessageInfo } = message; + rawMessageInfo = + rawMessageInfoIsNotMessageSidebarSourceReactionOrEdit(rawMessageInfo); + invariant( + rawMessageInfo, + 'SIDEBAR_SOURCE or TOGGLE_PIN should not point to a ' + + 'SIDEBAR_SOURCE, REACTION or EDIT_MESSAGE', + ); if (rawMessageInfo.id) { - invariant( - rawMessageInfo.type !== messageTypes.SIDEBAR_SOURCE && - rawMessageInfo.type !== messageTypes.REACTION && - rawMessageInfo.type !== messageTypes.EDIT_MESSAGE, - 'SIDEBAR_SOURCE should not point to a SIDEBAR_SOURCE, REACTION or EDIT_MESSAGE', - ); const editedContent = edits.get(rawMessageInfo.id); if (editedContent && rawMessageInfo.type === messageTypes.TEXT) { rawMessageInfo = { diff --git a/lib/shared/messages/sidebar-source-message-spec.js b/lib/shared/messages/sidebar-source-message-spec.js --- a/lib/shared/messages/sidebar-source-message-spec.js +++ b/lib/shared/messages/sidebar-source-message-spec.js @@ -10,13 +10,14 @@ } from './message-spec.js'; import { joinResult } from './utils.js'; import type { PlatformDetails } from '../../types/device-types.js'; -import type { - RawSidebarSourceMessageInfo, - SidebarSourceMessageData, - SidebarSourceMessageInfo, - ClientDBMessageInfo, +import { + type RawSidebarSourceMessageInfo, + type SidebarSourceMessageData, + type SidebarSourceMessageInfo, + type ClientDBMessageInfo, + messageTypes, + messageInfoIsNotMessageSidebarSourceReactionOrEdit, } from '../../types/message-types.js'; -import { messageTypes } from '../../types/message-types.js'; import type { RawUnsupportedMessageInfo } from '../../types/messages/unsupported.js'; import type { NotifTexts } from '../../types/notif-types.js'; import type { RelativeUserInfo } from '../../types/user-types.js'; @@ -102,14 +103,14 @@ if (!rawMessageInfo.sourceMessage) { return null; } - const sourceMessage = params.createMessageInfoFromRaw( + const sourceMessageFromRow = params.createMessageInfoFromRaw( rawMessageInfo.sourceMessage, ); + const sourceMessage = sourceMessageFromRow + ? messageInfoIsNotMessageSidebarSourceReactionOrEdit(sourceMessageFromRow) + : sourceMessageFromRow; invariant( - sourceMessage && - sourceMessage.type !== messageTypes.SIDEBAR_SOURCE && - sourceMessage.type !== messageTypes.REACTION && - sourceMessage.type !== messageTypes.EDIT_MESSAGE, + sourceMessage, 'Sidebars can not be created from SIDEBAR SOURCE, REACTION or EDIT MESSAGE', ); diff --git a/lib/types/message-types.js b/lib/types/message-types.js --- a/lib/types/message-types.js +++ b/lib/types/message-types.js @@ -202,6 +202,33 @@ ); return message; } + +export function rawMessageInfoIsNotMessageSidebarSourceReactionOrEdit( + message: RawMessageInfo, +): ?(RawComposableMessageInfo | RawRobotextMessageInfo) { + if ( + message.type === messageTypes.SIDEBAR_SOURCE || + message.type === messageTypes.REACTION || + message.type === messageTypes.EDIT_MESSAGE + ) { + return null; + } + return message; +} + +export function messageInfoIsNotMessageSidebarSourceReactionOrEdit( + message: MessageInfo, +): ?(ComposableMessageInfo | RobotextMessageInfo) { + if ( + message.type === messageTypes.SIDEBAR_SOURCE || + message.type === messageTypes.REACTION || + message.type === messageTypes.EDIT_MESSAGE + ) { + return null; + } + return message; +} + export function messageDataLocalID(messageData: MessageData): ?string { if ( messageData.type !== messageTypes.TEXT &&