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 @@ -721,13 +721,9 @@ > { const requiredIDs = new Set(); for (const row of rows) { - if (row.type === messageTypes.SIDEBAR_SOURCE) { - const content = JSON.parse(row.content); - requiredIDs.add(content.sourceMessageID); - } else if (row.type === messageTypes.TOGGLE_PIN) { - const content = JSON.parse(row.content); - requiredIDs.add(content.targetMessageID); - } + // parseDerivedMessages should be defined for SIDEBAR_SOURCE and TOGGLE_PIN + const { parseDerivedMessages } = messageSpecs[row.type]; + parseDerivedMessages?.(row, requiredIDs); } const messagesByID = new Map< diff --git a/lib/shared/messages/message-spec.js b/lib/shared/messages/message-spec.js --- a/lib/shared/messages/message-spec.js +++ b/lib/shared/messages/message-spec.js @@ -116,6 +116,7 @@ +canBeSidebarSource: boolean, +canBePinned: boolean, +canBeRenderedIndependently?: boolean, + +parseDerivedMessages?: (row: Object, requiredIDs: Set) => void, +useCreationSideEffectsFunc?: () => CreationSideEffectsFunc, +validator: TType, }; 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 @@ -176,5 +176,16 @@ canBePinned: false, + parseDerivedMessages(row: Object, requiredIDs: Set): void { + try { + const content = JSON.parse(row.content); + requiredIDs.add(content.sourceMessageID); + } catch (e) { + console.error( + `Error parsing content of message with id ${row.id}: ${e.message}`, + ); + } + }, + validator: rawSidebarSourceMessageInfoValidator, }); diff --git a/lib/shared/messages/toggle-pin-message-spec.js b/lib/shared/messages/toggle-pin-message-spec.js --- a/lib/shared/messages/toggle-pin-message-spec.js +++ b/lib/shared/messages/toggle-pin-message-spec.js @@ -159,5 +159,16 @@ canBePinned: false, + parseDerivedMessages(row: Object, requiredIDs: Set): void { + try { + const content = JSON.parse(row.content); + requiredIDs.add(content.targetMessageID); + } catch (e) { + console.error( + `Error parsing content of message with id ${row.id}: ${e.message}`, + ); + } + }, + validator: rawTogglePinMessageInfoValidator, });