From 6c11d1fa58ce853f13d2487e559c5c3f87f597da Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Thu, 14 Dec 2023 11:27:59 +0100 Subject: [PATCH 1/4] Fix for - Unable to leave public room --- src/libs/Permissions.ts | 2 +- src/libs/actions/Report.ts | 44 +++++++++++--------------------------- 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 9cde613ebb5a..239d790581ba 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -3,7 +3,7 @@ import CONST from '@src/CONST'; import Beta from '@src/types/onyx/Beta'; function canUseAllBetas(betas: OnyxEntry): boolean { - return !!betas?.includes(CONST.BETAS.ALL); + return true; } function canUseChronos(betas: OnyxEntry): boolean { diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index bea4ab8aed77..65c03874bd7b 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2054,29 +2054,21 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal // If a workspace member is leaving a workspace room, they don't actually lose the room from Onyx. // Instead, their notification preference just gets set to "hidden". const optimisticData: OnyxUpdate[] = [ - isWorkspaceMemberLeavingWorkspaceRoom - ? { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: { + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: isWorkspaceMemberLeavingWorkspaceRoom + ? { notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, - }, - } - : { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: { - reportID, + } + : { + reportID: null, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS.CLOSED, - chatType: report.chatType, - parentReportID: report.parentReportID, - parentReportActionID: report.parentReportActionID, - policyID: report.policyID, - type: report.type, }, - }, + }, ]; + const successData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -2127,19 +2119,11 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record typeof accountID === 'number', ); - type PersonalDetailsOnyxData = { - optimisticData: OnyxUpdate[]; - successData: OnyxUpdate[]; - failureData: OnyxUpdate[]; - }; - - const logins = inviteeEmails.map((memberLogin) => OptionsListUtils.addSMSDomainIfPhoneNumber(memberLogin)); - const newPersonalDetailsOnyxData = PersonalDetailsUtils.getNewPersonalDetailsOnyxData(logins, inviteeAccountIDs) as PersonalDetailsOnyxData; - const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -2148,11 +2132,8 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record Date: Thu, 14 Dec 2023 11:33:40 +0100 Subject: [PATCH 2/4] Revert some unrelated changes --- src/libs/Permissions.ts | 2 +- src/libs/actions/Report.ts | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 239d790581ba..9cde613ebb5a 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -3,7 +3,7 @@ import CONST from '@src/CONST'; import Beta from '@src/types/onyx/Beta'; function canUseAllBetas(betas: OnyxEntry): boolean { - return true; + return !!betas?.includes(CONST.BETAS.ALL); } function canUseChronos(betas: OnyxEntry): boolean { diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 65c03874bd7b..0c5d2fd0d746 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2119,11 +2119,19 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record typeof accountID === 'number', ); + type PersonalDetailsOnyxData = { + optimisticData: OnyxUpdate[]; + successData: OnyxUpdate[]; + failureData: OnyxUpdate[]; + }; + + const logins = inviteeEmails.map((memberLogin) => OptionsListUtils.addSMSDomainIfPhoneNumber(memberLogin)); + const newPersonalDetailsOnyxData = PersonalDetailsUtils.getNewPersonalDetailsOnyxData(logins, inviteeAccountIDs) as PersonalDetailsOnyxData; + const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -2132,8 +2140,11 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record Date: Thu, 14 Dec 2023 12:06:47 +0100 Subject: [PATCH 3/4] Update notification preference when leaving public/private rooms --- src/libs/Permissions.ts | 2 +- src/libs/actions/Report.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 9cde613ebb5a..239d790581ba 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -3,7 +3,7 @@ import CONST from '@src/CONST'; import Beta from '@src/types/onyx/Beta'; function canUseAllBetas(betas: OnyxEntry): boolean { - return !!betas?.includes(CONST.BETAS.ALL); + return true; } function canUseChronos(betas: OnyxEntry): boolean { diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 0c5d2fd0d746..9977693896ee 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2065,6 +2065,7 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal reportID: null, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS.CLOSED, + notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, }, }, ]; From 592c1b2d6ff97c7536905a33da6e018701fa613f Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Thu, 14 Dec 2023 12:08:18 +0100 Subject: [PATCH 4/4] Remove test code --- src/libs/Permissions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 239d790581ba..9cde613ebb5a 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -3,7 +3,7 @@ import CONST from '@src/CONST'; import Beta from '@src/types/onyx/Beta'; function canUseAllBetas(betas: OnyxEntry): boolean { - return true; + return !!betas?.includes(CONST.BETAS.ALL); } function canUseChronos(betas: OnyxEntry): boolean {