Page MenuHomePhabricator

D12807.id42701.diff
No OneTemporary

D12807.id42701.diff

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 { sendEditMessageSpec } from './send-edit-message-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';
@@ -14,4 +15,5 @@
[dmOperationTypes.CREATE_SIDEBAR]: createSidebarSpec,
[dmOperationTypes.SEND_TEXT_MESSAGE]: sendTextMessageSpec,
[dmOperationTypes.SEND_REACTION_MESSAGE]: sendReactionMessageSpec,
+ [dmOperationTypes.SEND_EDIT_MESSAGE]: sendEditMessageSpec,
});
diff --git a/lib/shared/dm-ops/send-edit-message-spec.js b/lib/shared/dm-ops/send-edit-message-spec.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/dm-ops/send-edit-message-spec.js
@@ -0,0 +1,46 @@
+// @flow
+
+import uuid from 'uuid';
+
+import type { DMOperationSpec } from './dm-op-spec.js';
+import type { DMSendEditMessageOperation } 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 sendEditMessageSpec: DMOperationSpec<DMSendEditMessageOperation> =
+ Object.freeze({
+ processDMOperation: async (
+ dmOperation: DMSendEditMessageOperation,
+ viewerID: string,
+ ) => {
+ const { threadID, creatorID, time, messageID, targetMessageID, text } =
+ dmOperation;
+ const editMessage = {
+ type: messageTypes.EDIT_MESSAGE,
+ id: messageID,
+ threadID,
+ creatorID,
+ time,
+ targetMessageID,
+ text,
+ };
+
+ const updateInfos: Array<ClientUpdateInfo> = [];
+ if (creatorID !== viewerID) {
+ updateInfos.push({
+ type: updateTypes.UPDATE_THREAD_READ_STATUS,
+ id: uuid.v4(),
+ time,
+ threadID,
+ unread: true,
+ });
+ }
+ return {
+ rawMessageInfos: [editMessage],
+ updateInfos,
+ };
+ },
+ });
+
+export { sendEditMessageSpec };
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
@@ -17,6 +17,7 @@
CREATE_SIDEBAR: 'create_sidebar',
SEND_TEXT_MESSAGE: 'send_text_message',
SEND_REACTION_MESSAGE: 'send_reaction_message',
+ SEND_EDIT_MESSAGE: 'send_edit_message',
});
export type DMOperationType = $Values<typeof dmOperationTypes>;
@@ -108,16 +109,38 @@
action: t.enums.of(['add_reaction', 'remove_reaction']),
});
+export type DMSendEditMessageOperation = {
+ +type: 'send_edit_message',
+ +threadID: string,
+ +creatorID: string,
+ +time: number,
+ +messageID: string,
+ +targetMessageID: string,
+ +text: string,
+};
+export const dmSendEditMessageOperationValidator: TInterface<DMSendEditMessageOperation> =
+ tShape<DMSendEditMessageOperation>({
+ type: tString(dmOperationTypes.SEND_EDIT_MESSAGE),
+ threadID: t.String,
+ creatorID: tUserID,
+ time: t.Number,
+ messageID: t.String,
+ targetMessageID: t.String,
+ text: t.String,
+ });
+
export type DMOperation =
| DMCreateThreadOperation
| DMCreateSidebarOperation
| DMSendTextMessageOperation
- | DMSendReactionMessageOperation;
+ | DMSendReactionMessageOperation
+ | DMSendEditMessageOperation;
export const dmOperationValidator: TUnion<DMOperation> = t.union([
dmCreateThreadOperationValidator,
dmCreateSidebarOperationValidator,
dmSendTextMessageOperationValidator,
dmSendReactionMessageOperationValidator,
+ dmSendEditMessageOperationValidator,
]);
export type DMOperationResult = {

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 8, 8:46 AM (1 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2440515
Default Alt Text
D12807.id42701.diff (3 KB)

Event Timeline