diff --git a/lib/shared/message-utils.js b/lib/shared/message-utils.js --- a/lib/shared/message-utils.js +++ b/lib/shared/message-utils.js @@ -6,6 +6,7 @@ import * as React from 'react'; import { codeBlockRegex, type ParserRules } from './markdown.js'; +import type { CreationSideEffectsFunc } from './messages/message-spec.js'; import { messageSpecs } from './messages/message-specs.js'; import { threadIsGroupChat } from './thread-utils.js'; import { useStringForUser } from '../hooks/ens-cache.js'; @@ -528,6 +529,18 @@ }, [message, username]); } +function useMessageCreationSideEffectsFunc( + messageType: $PropertyType, +): CreationSideEffectsFunc { + const messageSpec = messageSpecs[messageType]; + invariant(messageSpec, `we're not aware of messageType ${messageType}`); + invariant( + messageSpec.useCreationSideEffectsFunc, + `no useCreationSideEffectsFunc in message spec for ${messageType}`, + ); + return messageSpec.useCreationSideEffectsFunc(); +} + export { localIDPrefix, messageKey, @@ -551,4 +564,5 @@ getMessageTitle, mergeThreadMessageInfos, useMessagePreview, + useMessageCreationSideEffectsFunc, }; 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 @@ -62,6 +62,12 @@ }); export type PushType = $Values; +export type CreationSideEffectsFunc = ( + messageInfo: RawInfo, + threadInfo: ThreadInfo, + parentThreadInfo: ?ThreadInfo, +) => Promise; + export type MessageSpec = { +messageContentForServerDB?: (data: Data | RawInfo) => string, +messageContentForClientDB?: (data: RawInfo) => string, @@ -102,4 +108,5 @@ +startsThread?: boolean, +threadIDs?: (rawMessageInfo: RawInfo) => $ReadOnlyArray, +includedInRepliesCount?: boolean, + +useCreationSideEffectsFunc?: () => CreationSideEffectsFunc, };