Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3307280
D13316.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
D13316.diff
View Options
diff --git a/lib/shared/dm-ops/create-entry-spec.js b/lib/shared/dm-ops/create-entry-spec.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/dm-ops/create-entry-spec.js
@@ -0,0 +1,90 @@
+// @flow
+
+import uuid from 'uuid';
+
+import type {
+ DMOperationSpec,
+ ProcessDMOperationUtilities,
+} from './dm-op-spec.js';
+import type { DMCreateEntryOperation } 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: DMCreateEntryOperation) {
+ const { threadID, creatorID, time, entryID, entryDate, text } = dmOperation;
+ return {
+ type: messageTypes.CREATE_ENTRY,
+ threadID,
+ creatorID,
+ time,
+ entryID,
+ date: entryDate,
+ text,
+ };
+}
+
+const createEntrySpec: DMOperationSpec<DMCreateEntryOperation> = Object.freeze({
+ notificationsCreationData: async (dmOperation: DMCreateEntryOperation) => {
+ const messageData = createMessageDataFromDMOperation(dmOperation);
+ return { messageDatas: [messageData] };
+ },
+ processDMOperation: async (dmOperation: DMCreateEntryOperation) => {
+ const { threadID, creatorID, time, entryID, entryDate, text, messageID } =
+ dmOperation;
+
+ const messageData = createMessageDataFromDMOperation(dmOperation);
+ const rawMessageInfos = [
+ rawMessageInfoFromMessageData(messageData, messageID),
+ ];
+
+ const date = dateFromString(entryDate);
+ 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: DMCreateEntryOperation,
+ 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 { createEntrySpec };
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
@@ -5,6 +5,7 @@
import { changeThreadReadStatusSpec } from './change-thread-read-status-spec.js';
import { changeThreadSettingsSpec } from './change-thread-settings-spec.js';
import { changeThreadSubscriptionSpec } from './change-thread-subscription.js';
+import { createEntrySpec } from './create-entry-spec.js';
import { createSidebarSpec } from './create-sidebar-spec.js';
import { createThreadSpec } from './create-thread-spec.js';
import type { DMOperationSpec } from './dm-op-spec.js';
@@ -34,4 +35,5 @@
[dmOperationTypes.CHANGE_THREAD_SETTINGS]: changeThreadSettingsSpec,
[dmOperationTypes.CHANGE_THREAD_SUBSCRIPTION]: changeThreadSubscriptionSpec,
[dmOperationTypes.CHANGE_THREAD_READ_STATUS]: changeThreadReadStatusSpec,
+ [dmOperationTypes.CREATE_ENTRY]: createEntrySpec,
});
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
@@ -40,6 +40,7 @@
CHANGE_THREAD_SETTINGS: 'change_thread_settings',
CHANGE_THREAD_SUBSCRIPTION: 'change_thread_subscription',
CHANGE_THREAD_READ_STATUS: 'change_thread_read_status',
+ CREATE_ENTRY: 'create_entry',
});
export type DMOperationType = $Values<typeof dmOperationTypes>;
@@ -372,6 +373,29 @@
| DMSendTextMessageOperation
| DMSendMultimediaMessageOperation;
+export type DMCreateEntryOperation = {
+ +type: 'create_entry',
+ +threadID: string,
+ +creatorID: string,
+ +time: number,
+ +entryID: string,
+ +entryDate: string,
+ +text: string,
+ +messageID: string,
+};
+
+export const dmCreateEntryOperationValidator: TInterface<DMCreateEntryOperation> =
+ tShape<DMCreateEntryOperation>({
+ type: tString(dmOperationTypes.CREATE_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
@@ -386,7 +410,8 @@
| DMRemoveMembersOperation
| DMChangeThreadSettingsOperation
| DMChangeThreadSubscriptionOperation
- | DMChangeThreadReadStatusOperation;
+ | DMChangeThreadReadStatusOperation
+ | DMCreateEntryOperation;
export const dmOperationValidator: TUnion<DMOperation> = t.union([
dmCreateThreadOperationValidator,
dmCreateSidebarOperationValidator,
@@ -402,6 +427,7 @@
dmChangeThreadSettingsOperationValidator,
dmChangeThreadSubscriptionOperationValidator,
dmChangeThreadReadStatusOperationValidator,
+ dmCreateEntryOperationValidator,
]);
export type DMOperationResult = {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 20, 1:26 AM (6 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2540911
Default Alt Text
D13316.diff (5 KB)
Attached To
Mode
D13316: [lib] DMOperationSpec for create entry operation
Attached
Detach File
Event Timeline
Log In to Comment