Page MenuHomePhabricator

D6803.diff
No OneTemporary

D6803.diff

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<Info: RawMessageInfo>(
+ messageType: $PropertyType<Info, 'type'>,
+): CreationSideEffectsFunc<Info> {
+ 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<typeof pushTypes>;
+export type CreationSideEffectsFunc<RawInfo> = (
+ messageInfo: RawInfo,
+ threadInfo: ThreadInfo,
+ parentThreadInfo: ?ThreadInfo,
+) => Promise<mixed>;
+
export type MessageSpec<Data, RawInfo, Info> = {
+messageContentForServerDB?: (data: Data | RawInfo) => string,
+messageContentForClientDB?: (data: RawInfo) => string,
@@ -103,4 +109,5 @@
+startsThread?: boolean,
+threadIDs?: (rawMessageInfo: RawInfo) => $ReadOnlyArray<string>,
+includedInRepliesCount?: boolean,
+ +useCreationSideEffectsFunc?: () => CreationSideEffectsFunc<RawInfo>,
};

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 16, 3:39 PM (21 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2498139
Default Alt Text
D6803.diff (1 KB)

Event Timeline