Page MenuHomePhabricator

D13163.id43627.diff
No OneTemporary

D13163.id43627.diff

diff --git a/lib/shared/dm-ops/change-thread-status-spec.js b/lib/shared/dm-ops/change-thread-status-spec.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/dm-ops/change-thread-status-spec.js
@@ -0,0 +1,51 @@
+// @flow
+
+import uuid from 'uuid';
+
+import type {
+ DMOperationSpec,
+ ProcessDMOperationUtilities,
+} from './dm-op-spec';
+import type { DMChangeThreadStatusOperation } from '../../types/dm-ops';
+import { updateTypes } from '../../types/update-types-enum.js';
+
+const changeThreadStatusSpec: DMOperationSpec<DMChangeThreadStatusOperation> =
+ Object.freeze({
+ processDMOperation: async (dmOperation: DMChangeThreadStatusOperation) => {
+ const { threadID, unread, time } = dmOperation;
+ const updateInfos = [
+ {
+ type: updateTypes.UPDATE_THREAD_READ_STATUS,
+ id: uuid.v4(),
+ time,
+ threadID,
+ unread,
+ },
+ ];
+ return {
+ rawMessageInfos: [],
+ updateInfos,
+ };
+ },
+ canBeProcessed(
+ dmOperation: DMChangeThreadStatusOperation,
+ viewerID: string,
+ utilities: ProcessDMOperationUtilities,
+ ) {
+ const { creatorID, threadID } = dmOperation;
+ if (viewerID !== creatorID) {
+ return { isProcessingPossible: false, reason: { type: 'invalid' } };
+ }
+
+ if (!utilities.threadInfos[threadID]) {
+ return {
+ isProcessingPossible: false,
+ reason: { type: 'missing_thread', threadID },
+ };
+ }
+
+ return { isProcessingPossible: true };
+ },
+ });
+
+export { changeThreadStatusSpec };
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
@@ -4,6 +4,7 @@
import { addViewerToThreadMembersSpec } from './add-viewer-to-thread-members-spec.js';
import { changeThreadSettingsAndAddViewerSpec } from './change-thread-settings-and-add-viewer-spec.js';
import { changeThreadSettingsSpec } from './change-thread-settings-spec.js';
+import { changeThreadStatusSpec } from './change-thread-status-spec.js';
import { createSidebarSpec } from './create-sidebar-spec.js';
import { createThreadSpec } from './create-thread-spec.js';
import type { DMOperationSpec } from './dm-op-spec.js';
@@ -31,4 +32,5 @@
[dmOperationTypes.CHANGE_THREAD_SETTINGS]: changeThreadSettingsSpec,
[dmOperationTypes.CHANGE_THREAD_SETTINGS_AND_ADD_VIEWER]:
changeThreadSettingsAndAddViewerSpec,
+ [dmOperationTypes.CHANGE_THREAD_STATUS]: changeThreadStatusSpec,
});
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
@@ -30,6 +30,7 @@
CHANGE_THREAD_SETTINGS: 'change_thread_settings',
CHANGE_THREAD_SETTINGS_AND_ADD_VIEWER:
'change_thread_settings_and_add_viewer',
+ CHANGE_THREAD_STATUS: 'change_thread_status',
});
export type DMOperationType = $Values<typeof dmOperationTypes>;
@@ -314,6 +315,22 @@
...dmChangeThreadSettingsBaseValidatorShape,
});
+export type DMChangeThreadStatusOperation = {
+ +type: 'change_thread_status',
+ +time: number,
+ +threadID: string,
+ +creatorID: string,
+ +unread: boolean,
+};
+export const dmChangeThreadStatusOperationValidator: TInterface<DMChangeThreadStatusOperation> =
+ tShape<DMChangeThreadStatusOperation>({
+ type: tString(dmOperationTypes.CHANGE_THREAD_STATUS),
+ time: t.Number,
+ threadID: t.String,
+ creatorID: tUserID,
+ unread: t.Boolean,
+ });
+
export type DMOperation =
| DMCreateThreadOperation
| DMCreateSidebarOperation
@@ -326,7 +343,8 @@
| DMLeaveThreadOperation
| DMRemoveMembersOperation
| DMChangeThreadSettingsOperation
- | DMChangeThreadSettingsAndAddViewerOperation;
+ | DMChangeThreadSettingsAndAddViewerOperation
+ | DMChangeThreadStatusOperation;
export const dmOperationValidator: TUnion<DMOperation> = t.union([
dmCreateThreadOperationValidator,
dmCreateSidebarOperationValidator,
@@ -340,6 +358,7 @@
dmRemoveMembersOperationValidator,
dmChangeThreadSettingsOperationValidator,
dmChangeThreadSettingsAndAddViewerOperationValidator,
+ dmChangeThreadStatusOperationValidator,
]);
export type DMOperationResult = {

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 21, 8:51 PM (19 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2689038
Default Alt Text
D13163.id43627.diff (4 KB)

Event Timeline