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'; @@ -538,6 +539,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, @@ -561,4 +574,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, @@ -103,4 +109,5 @@ +startsThread?: boolean, +threadIDs?: (rawMessageInfo: RawInfo) => $ReadOnlyArray, +includedInRepliesCount?: boolean, + +useCreationSideEffectsFunc?: () => CreationSideEffectsFunc, };