Page MenuHomePhabricator

D12835.id42607.diff
No OneTemporary

D12835.id42607.diff

diff --git a/lib/shared/dm-ops/add-members-spec.js b/lib/shared/dm-ops/add-members-spec.js
--- a/lib/shared/dm-ops/add-members-spec.js
+++ b/lib/shared/dm-ops/add-members-spec.js
@@ -2,45 +2,81 @@
import uuid from 'uuid';
-import type { DMOperationSpec } from './dm-op-spec.js';
-import type { DMSendEditMessageOperation } from '../../types/dm-ops.js';
+import type {
+ DMOperationSpec,
+ ProcessDMOperationUtilities,
+} from './dm-op-spec.js';
+import type { DMAddMembersOperation } from '../../types/dm-ops.js';
import { messageTypes } from '../../types/message-types-enum.js';
import { updateTypes } from '../../types/update-types-enum.js';
import type { ClientUpdateInfo } from '../../types/update-types.js';
-const sendEditMessageSpec: DMOperationSpec<DMSendEditMessageOperation> =
- Object.freeze({
- processDMOperation: async (
- dmOperation: DMSendEditMessageOperation,
- viewerID: string,
- ) => {
- const { threadID, creatorID, time, messageID, targetMessageID, text } =
- dmOperation;
- const reactionMessage = {
- type: messageTypes.EDIT_MESSAGE,
- id: messageID,
- threadID,
- creatorID,
- time,
- targetMessageID,
- text,
- };
+const addMembersSpec: DMOperationSpec<DMAddMembersOperation> = Object.freeze({
+ processDMOperation: async (
+ dmOperation: DMAddMembersOperation,
+ viewerID: string,
+ utilities: ProcessDMOperationUtilities,
+ ) => {
+ const {
+ editorID,
+ time,
+ messageID,
+ addedUserIDs,
+ threadInfo,
+ rawMessageInfos,
+ truncationStatus,
+ rawEntryInfos,
+ } = dmOperation;
+ const addMembersMessage = {
+ type: messageTypes.ADD_MEMBERS,
+ id: messageID,
+ threadID: threadInfo.id,
+ creatorID: editorID,
+ time,
+ addedUserIDs: [...addedUserIDs],
+ };
- const updateInfos: Array<ClientUpdateInfo> = [];
- if (creatorID !== viewerID) {
- updateInfos.push({
+ const viewerIsAdded = addedUserIDs.includes(viewerID);
+ const updateInfos: Array<ClientUpdateInfo> = [];
+ if (viewerIsAdded) {
+ updateInfos.push(
+ {
+ type: updateTypes.JOIN_THREAD,
+ id: uuid.v4(),
+ time,
+ threadInfo,
+ rawMessageInfos,
+ truncationStatus,
+ rawEntryInfos,
+ },
+ {
type: updateTypes.UPDATE_THREAD_READ_STATUS,
id: uuid.v4(),
time,
- threadID,
+ threadID: threadInfo.id,
unread: true,
+ },
+ );
+ } else {
+ const currentThreadInfo = await utilities.fetchThread(threadInfo.id);
+ if (currentThreadInfo?.thick) {
+ const newThreadInfo = {
+ ...currentThreadInfo,
+ members: threadInfo.members,
+ };
+ updateInfos.push({
+ type: updateTypes.UPDATE_THREAD,
+ id: uuid.v4(),
+ time,
+ threadInfo: newThreadInfo,
});
}
- return {
- rawMessageInfos: [reactionMessage],
- updateInfos,
- };
- },
- });
+ }
+ return {
+ rawMessageInfos: [addMembersMessage],
+ updateInfos,
+ };
+ },
+});
-export { sendEditMessageSpec };
+export { addMembersSpec };
diff --git a/lib/shared/dm-ops/dm-op-spec.js b/lib/shared/dm-ops/dm-op-spec.js
--- a/lib/shared/dm-ops/dm-op-spec.js
+++ b/lib/shared/dm-ops/dm-op-spec.js
@@ -2,10 +2,12 @@
import type { DMOperation, DMOperationResult } from '../../types/dm-ops.js';
import type { RawMessageInfo } from '../../types/message-types.js';
+import type { RawThreadInfo } from '../../types/minimally-encoded-thread-permissions-types.js';
export type ProcessDMOperationUtilities = {
// Needed to fetch sidebar source messages
+fetchMessage: (messageID: string) => Promise<?RawMessageInfo>,
+ fetchThread: (threadID: string) => Promise<?RawThreadInfo>,
};
export type DMOperationSpec<DMOp: DMOperation> = {
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
@@ -1,14 +1,23 @@
// @flow
-import type { TInterface } from 'tcomb';
-import t from 'tcomb';
+import t, { type TInterface } from 'tcomb';
-import type { RawMessageInfo } from './message-types.js';
+import { type RawEntryInfo, rawEntryInfoValidator } from './entry-types.js';
+import type {
+ MessageTruncationStatus,
+ RawMessageInfo,
+} from './message-types.js';
+import {
+ messageTruncationStatusValidator,
+ rawMessageInfoValidator,
+} from './message-types.js';
+import type { ThickRawThreadInfo } from './minimally-encoded-thread-permissions-types.js';
import {
type NonSidebarThickThreadType,
nonSidebarThickThreadTypes,
} from './thread-types-enum.js';
import type { ClientUpdateInfo } from './update-types.js';
+import { threadInfoValidator } from '../permissions/minimally-encoded-thread-permissions-validators.js';
import { values } from '../utils/objects.js';
import { tShape, tString, tUserID } from '../utils/validation-utils.js';
@@ -132,20 +141,26 @@
export type DMAddMembersOperation = {
+type: 'add_members',
- +threadID: string,
+editorID: string,
+time: number,
+messageID: string,
+addedUserIDs: $ReadOnlyArray<string>,
+ +threadInfo: ThickRawThreadInfo,
+ +rawMessageInfos: $ReadOnlyArray<RawMessageInfo>,
+ +truncationStatus: MessageTruncationStatus,
+ +rawEntryInfos: $ReadOnlyArray<RawEntryInfo>,
};
export const dmAddMembersOperation: TInterface<DMAddMembersOperation> =
tShape<DMAddMembersOperation>({
type: tString(dmOperationTypes.ADD_MEMBERS),
- threadID: t.String,
editorID: tUserID,
time: t.Number,
messageID: t.String,
addedUserIDs: t.list(tUserID),
+ threadInfo: threadInfoValidator,
+ rawMessageInfos: t.list(rawMessageInfoValidator),
+ truncationStatus: messageTruncationStatusValidator,
+ rawEntryInfos: t.list(rawEntryInfoValidator),
});
export type DMOperation =

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 9, 8:31 AM (21 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2450967
Default Alt Text
D12835.id42607.diff (5 KB)

Event Timeline