Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3170824
D12806.id42818.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D12806.id42818.diff
View Options
diff --git a/lib/shared/dm-ops/dm-op-specs.js b/lib/shared/dm-ops/dm-op-specs.js
--- a/lib/shared/dm-ops/dm-op-specs.js
+++ b/lib/shared/dm-ops/dm-op-specs.js
@@ -3,6 +3,7 @@
import { createSidebarSpec } from './create-sidebar-spec.js';
import { createThreadSpec } from './create-thread-spec.js';
import type { DMOperationSpec } from './dm-op-spec.js';
+import { sendReactionMessageSpec } from './send-reaction-message-spec.js';
import { sendTextMessageSpec } from './send-text-message-spec.js';
import { type DMOperationType, dmOperationTypes } from '../../types/dm-ops.js';
@@ -12,4 +13,5 @@
[dmOperationTypes.CREATE_THREAD]: createThreadSpec,
[dmOperationTypes.CREATE_SIDEBAR]: createSidebarSpec,
[dmOperationTypes.SEND_TEXT_MESSAGE]: sendTextMessageSpec,
+ [dmOperationTypes.SEND_REACTION_MESSAGE]: sendReactionMessageSpec,
});
diff --git a/lib/shared/dm-ops/send-reaction-message-spec.js b/lib/shared/dm-ops/send-reaction-message-spec.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/dm-ops/send-reaction-message-spec.js
@@ -0,0 +1,54 @@
+// @flow
+
+import uuid from 'uuid';
+
+import type { DMOperationSpec } from './dm-op-spec.js';
+import type { DMSendReactionMessageOperation } from '../../types/dm-ops.js';
+import { messageTypes } from '../../types/message-types-enum.js';
+import { updateTypes } from '../../types/update-types-enum.js';
+import type { ClientUpdateInfo } from '../../types/update-types.js';
+
+const sendReactionMessageSpec: DMOperationSpec<DMSendReactionMessageOperation> =
+ Object.freeze({
+ processDMOperation: async (
+ dmOperation: DMSendReactionMessageOperation,
+ viewerID: string,
+ ) => {
+ const {
+ threadID,
+ creatorID,
+ time,
+ messageID,
+ targetMessageID,
+ reaction,
+ action,
+ } = dmOperation;
+ const reactionMessage = {
+ type: messageTypes.REACTION,
+ id: messageID,
+ threadID,
+ creatorID,
+ time,
+ targetMessageID,
+ reaction,
+ action,
+ };
+
+ const updateInfos: Array<ClientUpdateInfo> = [];
+ if (creatorID !== viewerID) {
+ updateInfos.push({
+ type: updateTypes.UPDATE_THREAD_READ_STATUS,
+ id: uuid.v4(),
+ time,
+ threadID,
+ unread: true,
+ });
+ }
+ return {
+ rawMessageInfos: [reactionMessage],
+ updateInfos,
+ };
+ },
+ });
+
+export { sendReactionMessageSpec };
diff --git a/lib/types/dm-ops.js b/lib/types/dm-ops.js
--- a/lib/types/dm-ops.js
+++ b/lib/types/dm-ops.js
@@ -16,6 +16,7 @@
CREATE_THREAD: 'create_thread',
CREATE_SIDEBAR: 'create_sidebar',
SEND_TEXT_MESSAGE: 'send_text_message',
+ SEND_REACTION_MESSAGE: 'send_reaction_message',
});
export type DMOperationType = $Values<typeof dmOperationTypes>;
@@ -85,14 +86,38 @@
text: t.String,
});
+export type DMSendReactionMessageOperation = {
+ +type: 'send_reaction_message',
+ +threadID: string,
+ +creatorID: string,
+ +time: number,
+ +messageID: string,
+ +targetMessageID: string,
+ +reaction: string,
+ +action: 'add_reaction' | 'remove_reaction',
+};
+export const dmSendReactionMessageOperationValidator: TInterface<DMSendReactionMessageOperation> =
+ tShape<DMSendReactionMessageOperation>({
+ type: tString(dmOperationTypes.SEND_REACTION_MESSAGE),
+ threadID: t.String,
+ creatorID: tUserID,
+ time: t.Number,
+ messageID: t.String,
+ targetMessageID: t.String,
+ reaction: t.String,
+ action: t.enums.of(['add_reaction', 'remove_reaction']),
+ });
+
export type DMOperation =
| DMCreateThreadOperation
| DMCreateSidebarOperation
- | DMSendTextMessageOperation;
+ | DMSendTextMessageOperation
+ | DMSendReactionMessageOperation;
export const dmOperationValidator: TUnion<DMOperation> = t.union([
dmCreateThreadOperationValidator,
dmCreateSidebarOperationValidator,
dmSendTextMessageOperationValidator,
+ dmSendReactionMessageOperationValidator,
]);
export type DMOperationResult = {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 8, 1:17 PM (6 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2441886
Default Alt Text
D12806.id42818.diff (3 KB)
Attached To
Mode
D12806: [lib] DMOperationSpec for reaction operation
Attached
Detach File
Event Timeline
Log In to Comment