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 @@ -72,18 +72,21 @@ rawMessageInfoFromServerDBRow( row: Object, params: RawMessageInfoFromServerDBRowParams, - ): RawSidebarSourceMessageInfo { + ): ?RawSidebarSourceMessageInfo { const { derivedMessages } = params; invariant(derivedMessages, 'Derived messages should be provided'); const content = JSON.parse(row.content); const sourceMessage = derivedMessages.get(content.sourceMessageID); - if (!sourceMessage) { + if (!sourceMessage || isInvalidSidebarSource(sourceMessage)) { console.warn( - `Message with id ${row.id} has a derived message ` + - `${content.sourceMessageID} which is not present in the database`, + `Either message with id ${row.id} has a derived message ` + + `${content.sourceMessageID} which is not present in the database ` + + 'or the derived message is an invalid message type', ); + return null; } + return { type: messageTypes.SIDEBAR_SOURCE, id: row.id.toString(), 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 @@ -199,12 +199,32 @@ // Raw*MessageInfo = used by server, and contained in client's local store // *MessageInfo = used by client in UI code +export type ValidRawSidebarSourceMessageInfo = + | RawTextMessageInfo + | RawCreateThreadMessageInfo + | RawAddMembersMessageInfo + | RawCreateSubthreadMessageInfo + | RawChangeSettingsMessageInfo + | RawRemoveMembersMessageInfo + | RawChangeRoleMessageInfo + | RawLeaveThreadMessageInfo + | RawJoinThreadMessageInfo + | RawCreateEntryMessageInfo + | RawEditEntryMessageInfo + | RawDeleteEntryMessageInfo + | RawRestoreEntryMessageInfo + | RawImagesMessageInfo + | RawMediaMessageInfo + | RawUpdateRelationshipMessageInfo + | RawCreateSidebarMessageInfo + | RawUnsupportedMessageInfo; + export type SidebarSourceMessageData = { +type: 17, +threadID: string, +creatorID: string, +time: number, - +sourceMessage?: RawComposableMessageInfo | RawRobotextMessageInfo, + +sourceMessage?: ValidRawSidebarSourceMessageInfo, }; export type MessageData = @@ -358,13 +378,33 @@ | MultimediaMessageInfo | ReactionMessageInfo; +export type ValidSidebarSourceMessageInfo = + | TextMessageInfo + | CreateThreadMessageInfo + | AddMembersMessageInfo + | CreateSubthreadMessageInfo + | ChangeSettingsMessageInfo + | RemoveMembersMessageInfo + | ChangeRoleMessageInfo + | LeaveThreadMessageInfo + | JoinThreadMessageInfo + | CreateEntryMessageInfo + | EditEntryMessageInfo + | DeleteEntryMessageInfo + | RestoreEntryMessageInfo + | ImagesMessageInfo + | MediaMessageInfo + | UpdateRelationshipMessageInfo + | CreateSidebarMessageInfo + | UnsupportedMessageInfo; + export type SidebarSourceMessageInfo = { +type: 17, +id: string, +threadID: string, +creator: RelativeUserInfo, +time: number, - +sourceMessage: ComposableMessageInfo | RobotextMessageInfo, + +sourceMessage: ValidSidebarSourceMessageInfo, }; export type MessageInfo =