Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3174464
D13341.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D13341.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
@@ -10,6 +10,7 @@
import { createThreadSpec } from './create-thread-spec.js';
import { deleteEntrySpec } from './delete-entry-spec.js';
import type { DMOperationSpec } from './dm-op-spec.js';
+import { editEntrySpec } from './edit-entry-spec.js';
import { joinThreadSpec } from './join-thread-spec.js';
import { leaveThreadSpec } from './leave-thread-spec.js';
import { removeMembersSpec } from './remove-members-spec.js';
@@ -38,4 +39,5 @@
[dmOperationTypes.CHANGE_THREAD_READ_STATUS]: changeThreadReadStatusSpec,
[dmOperationTypes.CREATE_ENTRY]: createEntrySpec,
[dmOperationTypes.DELETE_ENTRY]: deleteEntrySpec,
+ [dmOperationTypes.EDIT_ENTRY]: editEntrySpec,
});
diff --git a/lib/shared/dm-ops/edit-entry-spec.js b/lib/shared/dm-ops/edit-entry-spec.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/dm-ops/edit-entry-spec.js
@@ -0,0 +1,99 @@
+// @flow
+
+import uuid from 'uuid';
+
+import type {
+ DMOperationSpec,
+ ProcessDMOperationUtilities,
+} from './dm-op-spec.js';
+import type { DMEditEntryOperation } from '../../types/dm-ops.js';
+import type { ThickRawEntryInfo } from '../../types/entry-types.js';
+import { messageTypes } from '../../types/message-types-enum.js';
+import { updateTypes } from '../../types/update-types-enum.js';
+import type { EntryUpdateInfo } from '../../types/update-types.js';
+import { dateFromString } from '../../utils/date-utils.js';
+import { rawMessageInfoFromMessageData } from '../message-utils.js';
+
+function createMessageDataFromDMOperation(dmOperation: DMEditEntryOperation) {
+ const { threadID, creatorID, creationTime, entryID, entryDate, text } =
+ dmOperation;
+ return {
+ type: messageTypes.EDIT_ENTRY,
+ threadID,
+ creatorID,
+ entryID,
+ time: creationTime,
+ date: entryDate,
+ text,
+ };
+}
+
+const editEntrySpec: DMOperationSpec<DMEditEntryOperation> = Object.freeze({
+ notificationsCreationData: async (dmOperation: DMEditEntryOperation) => {
+ const messageData = createMessageDataFromDMOperation(dmOperation);
+ return { messageDatas: [messageData] };
+ },
+ processDMOperation: async (dmOperation: DMEditEntryOperation) => {
+ const {
+ threadID,
+ creatorID,
+ creationTime,
+ time,
+ entryID,
+ entryDate: dateString,
+ text,
+ messageID,
+ } = dmOperation;
+
+ const messageData = createMessageDataFromDMOperation(dmOperation);
+ const rawMessageInfos = [
+ rawMessageInfoFromMessageData(messageData, messageID),
+ ];
+
+ const date = dateFromString(dateString);
+ const rawEntryInfo: ThickRawEntryInfo = {
+ id: entryID,
+ threadID,
+ text,
+ year: date.getFullYear(),
+ month: date.getMonth() + 1,
+ day: date.getDate(),
+ creationTime,
+ creatorID,
+ thick: true,
+ deleted: false,
+ lastUpdatedTime: time,
+ };
+
+ const entryUpdateInfo: EntryUpdateInfo = {
+ entryInfo: rawEntryInfo,
+ type: updateTypes.UPDATE_ENTRY,
+ id: uuid.v4(),
+ time,
+ };
+
+ return {
+ rawMessageInfos,
+ updateInfos: [entryUpdateInfo],
+ };
+ },
+ canBeProcessed(
+ dmOperation: DMEditEntryOperation,
+ viewerID: string,
+ utilities: ProcessDMOperationUtilities,
+ ) {
+ if (utilities.threadInfos[dmOperation.threadID]) {
+ return { isProcessingPossible: true };
+ }
+ return {
+ isProcessingPossible: false,
+ reason: {
+ type: 'missing_thread',
+ threadID: dmOperation.threadID,
+ },
+ };
+ },
+ supportsAutoRetry: true,
+});
+
+export { editEntrySpec };
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
@@ -42,6 +42,7 @@
CHANGE_THREAD_READ_STATUS: 'change_thread_read_status',
CREATE_ENTRY: 'create_entry',
DELETE_ENTRY: 'delete_entry',
+ EDIT_ENTRY: 'edit_entry',
});
export type DMOperationType = $Values<typeof dmOperationTypes>;
@@ -420,6 +421,31 @@
messageID: t.String,
});
+export type DMEditEntryOperation = {
+ +type: 'edit_entry',
+ +threadID: string,
+ +creatorID: string,
+ +time: number,
+ +creationTime: number,
+ +entryID: string,
+ +entryDate: string,
+ +text: string,
+ +messageID: string,
+};
+
+export const dmEditEntryOperationValidator: TInterface<DMEditEntryOperation> =
+ tShape<DMEditEntryOperation>({
+ type: tString(dmOperationTypes.EDIT_ENTRY),
+ threadID: t.String,
+ creatorID: t.String,
+ creationTime: t.Number,
+ time: t.Number,
+ entryID: t.String,
+ entryDate: t.String,
+ text: t.String,
+ messageID: t.String,
+ });
+
export type DMOperation =
| DMCreateThreadOperation
| DMCreateSidebarOperation
@@ -436,7 +462,8 @@
| DMChangeThreadSubscriptionOperation
| DMChangeThreadReadStatusOperation
| DMCreateEntryOperation
- | DMDeleteEntryOperation;
+ | DMDeleteEntryOperation
+ | DMEditEntryOperation;
export const dmOperationValidator: TUnion<DMOperation> = t.union([
dmCreateThreadOperationValidator,
dmCreateSidebarOperationValidator,
@@ -454,6 +481,7 @@
dmChangeThreadReadStatusOperationValidator,
dmCreateEntryOperationValidator,
dmDeleteEntryOperationValidator,
+ dmEditEntryOperationValidator,
]);
export type DMOperationResult = {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 8, 4:52 PM (11 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2440335
Default Alt Text
D13341.diff (5 KB)
Attached To
Mode
D13341: [lib] DMOperationSpec for edit entry operation
Attached
Detach File
Event Timeline
Log In to Comment