Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3249512
D6803.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D6803.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D6803: [lib] Add useCreationSideEffectsFunc to MessageSpec
Attached
Detach File
Event Timeline
Log In to Comment