Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3181066
D13340.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
D13340.diff
View Options
diff --git a/lib/shared/dm-ops/delete-entry-spec.js b/lib/shared/dm-ops/delete-entry-spec.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/dm-ops/delete-entry-spec.js
@@ -0,0 +1,97 @@
+// @flow
+
+import uuid from 'uuid';
+
+import type {
+ DMOperationSpec,
+ ProcessDMOperationUtilities,
+} from './dm-op-spec.js';
+import type { DMDeleteEntryOperation } 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: DMDeleteEntryOperation) {
+ const { threadID, creatorID, time, entryID, entryDate, text } = dmOperation;
+ return {
+ type: messageTypes.DELETE_ENTRY,
+ threadID,
+ creatorID,
+ time,
+ entryID,
+ date: entryDate,
+ text,
+ };
+}
+
+const deleteEntrySpec: DMOperationSpec<DMDeleteEntryOperation> = Object.freeze({
+ notificationsCreationData: async (dmOperation: DMDeleteEntryOperation) => {
+ const messageData = createMessageDataFromDMOperation(dmOperation);
+ return { messageDatas: [messageData] };
+ },
+ processDMOperation: async (dmOperation: DMDeleteEntryOperation) => {
+ const {
+ threadID,
+ creatorID,
+ 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: time,
+ creatorID,
+ thick: true,
+ deleted: true,
+ lastUpdatedTime: time,
+ };
+
+ const entryUpdateInfo: EntryUpdateInfo = {
+ entryInfo: rawEntryInfo,
+ type: updateTypes.UPDATE_ENTRY,
+ id: uuid.v4(),
+ time,
+ };
+
+ return {
+ rawMessageInfos,
+ updateInfos: [entryUpdateInfo],
+ };
+ },
+ canBeProcessed(
+ dmOperation: DMDeleteEntryOperation,
+ 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 { deleteEntrySpec };
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
@@ -8,6 +8,7 @@
import { createEntrySpec } from './create-entry-spec.js';
import { createSidebarSpec } from './create-sidebar-spec.js';
import { createThreadSpec } from './create-thread-spec.js';
+import { deleteEntrySpec } from './delete-entry-spec.js';
import type { DMOperationSpec } from './dm-op-spec.js';
import { joinThreadSpec } from './join-thread-spec.js';
import { leaveThreadSpec } from './leave-thread-spec.js';
@@ -36,4 +37,5 @@
[dmOperationTypes.CHANGE_THREAD_SUBSCRIPTION]: changeThreadSubscriptionSpec,
[dmOperationTypes.CHANGE_THREAD_READ_STATUS]: changeThreadReadStatusSpec,
[dmOperationTypes.CREATE_ENTRY]: createEntrySpec,
+ [dmOperationTypes.DELETE_ENTRY]: deleteEntrySpec,
});
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
@@ -41,6 +41,7 @@
CHANGE_THREAD_SUBSCRIPTION: 'change_thread_subscription',
CHANGE_THREAD_READ_STATUS: 'change_thread_read_status',
CREATE_ENTRY: 'create_entry',
+ DELETE_ENTRY: 'delete_entry',
});
export type DMOperationType = $Values<typeof dmOperationTypes>;
@@ -396,6 +397,29 @@
messageID: t.String,
});
+export type DMDeleteEntryOperation = {
+ +type: 'delete_entry',
+ +threadID: string,
+ +creatorID: string,
+ +time: number,
+ +entryID: string,
+ +entryDate: string,
+ +text: string,
+ +messageID: string,
+};
+
+export const dmDeleteEntryOperationValidator: TInterface<DMDeleteEntryOperation> =
+ tShape<DMDeleteEntryOperation>({
+ type: tString(dmOperationTypes.DELETE_ENTRY),
+ threadID: t.String,
+ creatorID: t.String,
+ time: t.Number,
+ entryID: t.String,
+ entryDate: t.String,
+ text: t.String,
+ messageID: t.String,
+ });
+
export type DMOperation =
| DMCreateThreadOperation
| DMCreateSidebarOperation
@@ -411,7 +435,8 @@
| DMChangeThreadSettingsOperation
| DMChangeThreadSubscriptionOperation
| DMChangeThreadReadStatusOperation
- | DMCreateEntryOperation;
+ | DMCreateEntryOperation
+ | DMDeleteEntryOperation;
export const dmOperationValidator: TUnion<DMOperation> = t.union([
dmCreateThreadOperationValidator,
dmCreateSidebarOperationValidator,
@@ -428,6 +453,7 @@
dmChangeThreadSubscriptionOperationValidator,
dmChangeThreadReadStatusOperationValidator,
dmCreateEntryOperationValidator,
+ dmDeleteEntryOperationValidator,
]);
export type DMOperationResult = {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 9, 5:26 AM (21 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2449311
Default Alt Text
D13340.diff (5 KB)
Attached To
Mode
D13340: [lib] DMOperationSpec for delete entry operation
Attached
Detach File
Event Timeline
Log In to Comment