Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unable to leave thread #45136

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6927,12 +6927,20 @@ function canJoinChat(report: OnyxInputOrEntry<Report>, parentReportAction: OnyxI
* Whether the user can leave a report
*/
function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boolean {
if (isRootGroupChat(report)) {
return true;
}

if (isPolicyExpenseChat(report) && !report?.isOwnPolicyExpenseChat && !PolicyUtils.isPolicyAdmin(policy)) {
return true;
}

if (report?.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) {
return false;
}

// Anyone viewing these chat types is already a participant and therefore cannot leave
if (isSelfDM(report) || isRootGroupChat(report)) {
if (isSelfDM(report)) {
return false;
}

Expand Down
17 changes: 9 additions & 8 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
const chatRoomSubtitle = useMemo(() => ReportUtils.getChatRoomSubtitle(report), [report, policy]);
const isSystemChat = useMemo(() => ReportUtils.isSystemChat(report), [report]);
const isGroupChat = useMemo(() => ReportUtils.isGroupChat(report), [report]);
const isRootGroupChat = useMemo(() => ReportUtils.isRootGroupChat(report), [report]);
const isThread = useMemo(() => ReportUtils.isThread(report), [report]);
const participants = useMemo(() => {
const shouldExcludeHiddenParticipants = !isGroupChat && !isSystemChat;
Expand Down Expand Up @@ -224,13 +225,13 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD

const leaveChat = useCallback(() => {
Navigation.dismissModal();
if (isChatRoom) {
const isWorkspaceMemberLeavingWorkspaceRoom = (report.visibility === CONST.REPORT.VISIBILITY.RESTRICTED || isPolicyExpenseChat) && isPolicyEmployee;
Report.leaveRoom(report.reportID, isWorkspaceMemberLeavingWorkspaceRoom);
if (isRootGroupChat) {
Report.leaveGroupChat(report.reportID);
return;
}
Report.leaveGroupChat(report.reportID);
}, [isChatRoom, isPolicyEmployee, isPolicyExpenseChat, report.reportID, report.visibility]);
const isWorkspaceMemberLeavingWorkspaceRoom = (report.visibility === CONST.REPORT.VISIBILITY.RESTRICTED || isPolicyExpenseChat) && isPolicyEmployee;
Report.leaveRoom(report.reportID, isWorkspaceMemberLeavingWorkspaceRoom);
}, [isPolicyEmployee, isPolicyExpenseChat, isRootGroupChat, report.reportID, report.visibility]);

const unapproveExpenseReportOrShowModal = useCallback(() => {
if (PolicyUtils.hasAccountingConnections(policy)) {
Expand All @@ -241,8 +242,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
IOU.unapproveExpenseReport(moneyRequestReport);
}, [moneyRequestReport, policy]);

const shouldShowLeaveButton =
!isThread && (isGroupChat || (isChatRoom && ReportUtils.canLeaveChat(report, policy)) || (isPolicyExpenseChat && !report.isOwnPolicyExpenseChat && !isPolicyAdmin));
const shouldShowLeaveButton = ReportUtils.canLeaveChat(report, policy);

const reportName = ReportUtils.isDeprecatedGroupDM(report) || isGroupChat ? ReportUtils.getGroupChatName(undefined, false, report) : ReportUtils.getReportName(report);

Expand Down Expand Up @@ -389,7 +389,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
icon: Expensicons.Exit,
isAnonymousAction: true,
action: () => {
if (ReportUtils.getParticipantsAccountIDsForDisplay(report, false, true).length === 1 && isGroupChat) {
if (ReportUtils.getParticipantsAccountIDsForDisplay(report, false, true).length === 1 && isRootGroupChat) {
setIsLastMemberLeavingGroupModalVisible(true);
return;
}
Expand All @@ -413,6 +413,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
isSelfDM,
isArchivedRoom,
isGroupChat,
isRootGroupChat,
isDefaultRoom,
isChatThread,
isPolicyEmployee,
Expand Down
Loading