Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3356757
D13184.id43720.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D13184.id43720.diff
View Options
diff --git a/native/chat/settings/thread-settings-leave-thread.react.js b/native/chat/settings/thread-settings-leave-thread.react.js
--- a/native/chat/settings/thread-settings-leave-thread.react.js
+++ b/native/chat/settings/thread-settings-leave-thread.react.js
@@ -3,6 +3,7 @@
import invariant from 'invariant';
import * as React from 'react';
import { ActivityIndicator, Text, View } from 'react-native';
+import uuid from 'uuid';
import type { LeaveThreadInput } from 'lib/actions/thread-actions.js';
import {
@@ -11,9 +12,16 @@
} from 'lib/actions/thread-actions.js';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
import { otherUsersButNoOtherAdmins } 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 { identifyInvalidatedThreads } from 'lib/shared/thread-utils.js';
+import type { DMLeaveThreadOperation } from 'lib/types/dm-ops';
import type { LoadingStatus } from 'lib/types/loading-types.js';
import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
+import { threadTypeIsThick } from 'lib/types/thread-types-enum.js';
import type { LeaveThreadPayload } from 'lib/types/thread-types.js';
import {
type DispatchActionPromise,
@@ -64,6 +72,7 @@
+dispatchActionPromise: DispatchActionPromise,
// async functions that hit server APIs
+leaveThread: (input: LeaveThreadInput) => Promise<LeaveThreadPayload>,
+ +leaveDMThread: () => Promise<void>,
// withNavContext
+navContext: ?NavContextType,
};
@@ -114,13 +123,25 @@
onConfirmLeaveThread = () => {
const threadID = this.props.threadInfo.id;
- void this.props.dispatchActionPromise(
- leaveThreadActionTypes,
- this.leaveThread(),
- {
- customKeyName: `${leaveThreadActionTypes.started}:${threadID}`,
- },
- );
+
+ if (threadTypeIsThick(this.props.threadInfo.type)) {
+ // TODO: This should also handle leaving sidebars (ENG-9098)
+ const { navContext } = this.props;
+ invariant(navContext, 'navContext should exist in leaveThread');
+ navContext.dispatch({
+ type: clearThreadsActionType,
+ payload: { threadIDs: [threadID] },
+ });
+ void this.props.leaveDMThread();
+ } else {
+ void this.props.dispatchActionPromise(
+ leaveThreadActionTypes,
+ this.leaveThread(),
+ {
+ customKeyName: `${leaveThreadActionTypes.started}:${threadID}`,
+ },
+ );
+ }
};
async leaveThread(): Promise<LeaveThreadPayload> {
@@ -174,6 +195,36 @@
const dispatchActionPromise = useDispatchActionPromise();
const callLeaveThread = useLeaveThread();
const navContext = React.useContext(NavContext);
+ const processAndSendDMOperation = useProcessAndSendDMOperation();
+ const viewerID = useSelector(
+ state => state.currentUserInfo && state.currentUserInfo.id,
+ );
+
+ const leaveDMThread = React.useCallback(async () => {
+ invariant(viewerID, 'viewerID should be set');
+ const op: DMLeaveThreadOperation = {
+ type: 'leave_thread',
+ editorID: viewerID,
+ time: Date.now(),
+ messageID: uuid.v4(),
+ threadID: props.threadInfo.id,
+ };
+ const opSpecification: OutboundDMOperationSpecification = {
+ type: dmOperationSpecificationTypes.OUTBOUND,
+ op,
+ recipients: {
+ type: 'some_users',
+ userIDs: props.threadInfo.members.map(member => member.id),
+ },
+ };
+ await processAndSendDMOperation(opSpecification);
+ }, [
+ processAndSendDMOperation,
+ props.threadInfo.id,
+ props.threadInfo.members,
+ viewerID,
+ ]);
+
return (
<ThreadSettingsLeaveThread
{...props}
@@ -184,6 +235,7 @@
dispatchActionPromise={dispatchActionPromise}
leaveThread={callLeaveThread}
navContext={navContext}
+ leaveDMThread={leaveDMThread}
/>
);
});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 8:34 PM (22 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2577245
Default Alt Text
D13184.id43720.diff (4 KB)
Attached To
Mode
D13184: [native] implement leaving DM thread
Attached
Detach File
Event Timeline
Log In to Comment