Page MenuHomePhabricator

D13342.diff
No OneTemporary

D13342.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
@@ -14,6 +14,7 @@
import { joinThreadSpec } from './join-thread-spec.js';
import { leaveThreadSpec } from './leave-thread-spec.js';
import { removeMembersSpec } from './remove-members-spec.js';
+import { restoreEntrySpec } from './restore-entry-spec.js';
import { sendEditMessageSpec } from './send-edit-message-spec.js';
import { sendMultimediaMessageSpec } from './send-multimedia-message-spec.js';
import { sendReactionMessageSpec } from './send-reaction-message-spec.js';
@@ -40,4 +41,5 @@
[dmOperationTypes.CREATE_ENTRY]: createEntrySpec,
[dmOperationTypes.DELETE_ENTRY]: deleteEntrySpec,
[dmOperationTypes.EDIT_ENTRY]: editEntrySpec,
+ [dmOperationTypes.RESTORE_ENTRY]: restoreEntrySpec,
});
diff --git a/lib/shared/dm-ops/restore-entry-spec.js b/lib/shared/dm-ops/restore-entry-spec.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/dm-ops/restore-entry-spec.js
@@ -0,0 +1,100 @@
+// @flow
+
+import uuid from 'uuid';
+
+import type {
+ DMOperationSpec,
+ ProcessDMOperationUtilities,
+} from './dm-op-spec.js';
+import type { DMRestoreEntryOperation } 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: DMRestoreEntryOperation,
+) {
+ const { threadID, creatorID, time, entryID, entryDate, text } = dmOperation;
+ return {
+ type: messageTypes.RESTORE_ENTRY,
+ threadID,
+ creatorID,
+ time,
+ entryID,
+ date: entryDate,
+ text,
+ };
+}
+
+const restoreEntrySpec: DMOperationSpec<DMRestoreEntryOperation> =
+ Object.freeze({
+ notificationsCreationData: async (dmOperation: DMRestoreEntryOperation) => {
+ const messageData = createMessageDataFromDMOperation(dmOperation);
+ return { messageDatas: [messageData] };
+ },
+ processDMOperation: async (dmOperation: DMRestoreEntryOperation) => {
+ 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: false,
+ lastUpdatedTime: time,
+ };
+
+ const entryUpdateInfo: EntryUpdateInfo = {
+ entryInfo: rawEntryInfo,
+ type: updateTypes.UPDATE_ENTRY,
+ id: uuid.v4(),
+ time,
+ };
+
+ return {
+ rawMessageInfos,
+ updateInfos: [entryUpdateInfo],
+ };
+ },
+ canBeProcessed(
+ dmOperation: DMRestoreEntryOperation,
+ 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 { restoreEntrySpec };
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
@@ -43,6 +43,7 @@
CREATE_ENTRY: 'create_entry',
DELETE_ENTRY: 'delete_entry',
EDIT_ENTRY: 'edit_entry',
+ RESTORE_ENTRY: 'restore_entry',
});
export type DMOperationType = $Values<typeof dmOperationTypes>;
@@ -444,6 +445,29 @@
messageID: t.String,
});
+export type DMRestoreEntryOperation = {
+ +type: 'restore_entry',
+ +threadID: string,
+ +creatorID: string,
+ +time: number,
+ +entryID: string,
+ +entryDate: string,
+ +text: string,
+ +messageID: string,
+};
+
+export const dmRestoreEntryOperationValidator: TInterface<DMRestoreEntryOperation> =
+ tShape<DMRestoreEntryOperation>({
+ type: tString(dmOperationTypes.RESTORE_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
@@ -461,7 +485,8 @@
| DMChangeThreadReadStatusOperation
| DMCreateEntryOperation
| DMDeleteEntryOperation
- | DMEditEntryOperation;
+ | DMEditEntryOperation
+ | DMRestoreEntryOperation;
export const dmOperationValidator: TUnion<DMOperation> = t.union([
dmCreateThreadOperationValidator,
dmCreateSidebarOperationValidator,
@@ -480,6 +505,7 @@
dmCreateEntryOperationValidator,
dmDeleteEntryOperationValidator,
dmEditEntryOperationValidator,
+ dmRestoreEntryOperationValidator,
]);
export type DMOperationResult = {

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 26, 11:07 PM (9 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2709402
Default Alt Text
D13342.diff (5 KB)

Event Timeline