Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3356901
D13185.id43721.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D13185.id43721.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,23 @@
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,
} from 'lib/types/thread-types-enum.js';
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
@@ -196,14 +205,48 @@
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)) {
+ // TODO: This should also handle leaving sidebars (ENG-9098)
+ 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: 'some_users',
+ userIDs: threadInfo.members.map(member => member.id),
+ },
+ };
+ void processAndSendDMOperation(opSpecification);
+ } else {
+ void dispatchActionPromise(
+ leaveThreadActionTypes,
+ callLeaveThread({ threadID: threadInfo.id }),
+ );
+ }
popModal();
- }, [callLeaveThread, popModal, dispatchActionPromise, threadInfo.id]);
+ }, [
+ threadInfo.type,
+ threadInfo.id,
+ threadInfo.members,
+ dispatchActionPromise,
+ callLeaveThread,
+ popModal,
+ viewerID,
+ processAndSendDMOperation,
+ ]);
const onClickLeaveThread = React.useCallback(
() =>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 9:20 PM (20 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2577355
Default Alt Text
D13185.id43721.diff (2 KB)
Attached To
Mode
D13185: [web] implement leaving DM thread
Attached
Detach File
Event Timeline
Log In to Comment