Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3357103
D13185.id43755.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D13185.id43755.diff
View Options
diff --git a/web/chat/thread-menu.react.js b/web/chat/thread-menu.react.js
--- a/web/chat/thread-menu.react.js
+++ b/web/chat/thread-menu.react.js
@@ -1,6 +1,8 @@
// @flow
+import invariant from 'invariant';
import * as React from 'react';
+import uuid from 'uuid';
import {
leaveThreadActionTypes,
@@ -10,16 +12,24 @@
import SWMansionIcon from 'lib/components/swmansion-icon.react.js';
import { usePromoteSidebar } from 'lib/hooks/promote-sidebar.react.js';
import { childThreadInfos } from 'lib/selectors/thread-selectors.js';
+import {
+ type OutboundDMOperationSpecification,
+ dmOperationSpecificationTypes,
+} from 'lib/shared/dm-ops/dm-op-utils.js';
+import { useProcessAndSendDMOperation } from 'lib/shared/dm-ops/process-dm-ops.js';
import {
threadIsChannel,
useThreadHasPermission,
viewerIsMember,
} from 'lib/shared/thread-utils.js';
+import { type DMLeaveThreadOperation } from 'lib/types/dm-ops.js';
import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
import { threadPermissions } from 'lib/types/thread-permission-types.js';
import {
threadTypes,
threadTypeIsSidebar,
+ threadTypeIsThick,
+ thickThreadTypes,
} from 'lib/types/thread-types-enum.js';
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
@@ -196,14 +206,51 @@
const dispatchActionPromise = useDispatchActionPromise();
const callLeaveThread = useLeaveThread();
+ const processAndSendDMOperation = useProcessAndSendDMOperation();
+ const viewerID = useSelector(
+ state => state.currentUserInfo && state.currentUserInfo.id,
+ );
const onConfirmLeaveThread = React.useCallback(() => {
- void dispatchActionPromise(
- leaveThreadActionTypes,
- callLeaveThread({ threadID: threadInfo.id }),
- );
+ if (threadTypeIsThick(threadInfo.type)) {
+ invariant(viewerID, 'viewerID should be set');
+ const op: DMLeaveThreadOperation = {
+ type: 'leave_thread',
+ editorID: viewerID,
+ time: Date.now(),
+ messageID: uuid.v4(),
+ threadID: threadInfo.id,
+ };
+ const opSpecification: OutboundDMOperationSpecification = {
+ type: dmOperationSpecificationTypes.OUTBOUND,
+ op,
+ recipients: {
+ type: 'all_thread_members',
+ threadID:
+ threadInfo.type === thickThreadTypes.THICK_SIDEBAR &&
+ threadInfo.parentThreadID
+ ? threadInfo.parentThreadID
+ : threadInfo.id,
+ },
+ };
+ void processAndSendDMOperation(opSpecification);
+ } else {
+ void dispatchActionPromise(
+ leaveThreadActionTypes,
+ callLeaveThread({ threadID: threadInfo.id }),
+ );
+ }
popModal();
- }, [callLeaveThread, popModal, dispatchActionPromise, threadInfo.id]);
+ }, [
+ threadInfo.type,
+ threadInfo.id,
+ threadInfo.parentThreadID,
+ popModal,
+ viewerID,
+ processAndSendDMOperation,
+ dispatchActionPromise,
+ callLeaveThread,
+ ]);
const onClickLeaveThread = React.useCallback(
() =>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 10:25 PM (21 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2577190
Default Alt Text
D13185.id43755.diff (3 KB)
Attached To
Mode
D13185: [web] implement leaving DM thread
Attached
Detach File
Event Timeline
Log In to Comment