Skip to content

Commit

Permalink
Merge pull request #48887 from shubham1206agra/fix-notification-prefe…
Browse files Browse the repository at this point in the history
…rence

Fix notification preference by defaulting to hidden
  • Loading branch information
puneetlath authored Sep 12, 2024
2 parents 56f4ee7 + 593c33a commit 4d0c30d
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 332 deletions.
13 changes: 13 additions & 0 deletions src/hooks/useResponsiveLayout/__mocks__/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function useResponsiveLayout() {
return {
shouldUseNarrowLayout: false,
isSmallScreenWidth: false,
isInNarrowPaneModal: false,
isExtraSmallScreenHeight: false,
isExtraSmallScreenWidth: false,
isMediumScreenWidth: false,
onboardingIsMediumOrLargerScreenWidth: true,
isLargeScreenWidth: true,
isSmallScreen: false,
};
}
13 changes: 13 additions & 0 deletions src/hooks/useResponsiveLayout/__mocks__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function useResponsiveLayout() {
return {
shouldUseNarrowLayout: false,
isSmallScreenWidth: false,
isInNarrowPaneModal: false,
isExtraSmallScreenHeight: false,
isExtraSmallScreenWidth: false,
isMediumScreenWidth: false,
onboardingIsMediumOrLargerScreenWidth: true,
isLargeScreenWidth: true,
isSmallScreen: false,
};
}
7 changes: 5 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1163,8 +1163,11 @@ function getDefaultNotificationPreferenceForReport(report: OnyxEntry<Report>): V
/**
* Get the notification preference given a report
*/
function getReportNotificationPreference(report: OnyxEntry<Report>): ValueOf<typeof CONST.REPORT.NOTIFICATION_PREFERENCE> {
return report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? getDefaultNotificationPreferenceForReport(report);
function getReportNotificationPreference(report: OnyxEntry<Report>, shouldDefaltToHidden = true): ValueOf<typeof CONST.REPORT.NOTIFICATION_PREFERENCE> {
if (!shouldDefaltToHidden) {
return report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? getDefaultNotificationPreferenceForReport(report);
}
return report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
}

const CONCIERGE_ACCOUNT_ID_STRING = CONST.ACCOUNT_ID.CONCIERGE.toString();
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2871,7 +2871,7 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`,
value: {[report.parentReportActionID]: {childReportNotificationPreference: ReportUtils.getReportNotificationPreference(report)}},
value: {[report.parentReportActionID]: {childReportNotificationPreference: ReportUtils.getReportNotificationPreference(report, false)}},
});
}

Expand Down
8 changes: 6 additions & 2 deletions tests/perf-test/SidebarLinks.perf-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ describe('SidebarLinks', () => {

// Initialize the network key for OfflineWithFeedback
Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false});
Onyx.clear().then(waitForBatchedUpdates);
TestHelper.signInWithTestUser(1, '[email protected]', undefined, undefined, 'One').then(waitForBatchedUpdates);
});

afterEach(() => {
Onyx.clear();
});

test('[SidebarLinks] should render Sidebar with 500 reports stored', async () => {
Expand Down Expand Up @@ -87,7 +91,7 @@ describe('SidebarLinks', () => {
* Query for display names of participants [1, 2].
* This will ensure that the sidebar renders a list of items.
*/
await screen.findAllByText('One, Two');
await screen.findAllByText('Email Two');
};

await waitForBatchedUpdates();
Expand Down
5 changes: 4 additions & 1 deletion tests/ui/PaginationTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ async function signInAndGetApp(): Promise<void> {
reportID: REPORT_ID,
reportName: CONST.REPORT.DEFAULT_REPORT_NAME,
lastMessageText: 'Test',
participants: {[USER_B_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}},
participants: {
[USER_B_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS},
[USER_A_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS},
},
lastActorAccountID: USER_B_ACCOUNT_ID,
type: CONST.REPORT.TYPE.CHAT,
});
Expand Down
10 changes: 8 additions & 2 deletions tests/ui/UnreadIndicatorsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ function signInAndGetAppWithUnreadChat(): Promise<void> {
lastReadTime: reportAction3CreatedDate,
lastVisibleActionCreated: reportAction9CreatedDate,
lastMessageText: 'Test',
participants: {[USER_B_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}},
participants: {
[USER_B_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS},
[USER_A_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS},
},
lastActorAccountID: USER_B_ACCOUNT_ID,
type: CONST.REPORT.TYPE.CHAT,
});
Expand Down Expand Up @@ -301,7 +304,10 @@ describe('Unread Indicators', () => {
lastVisibleActionCreated: DateUtils.getDBTime(utcToZonedTime(NEW_REPORT_FIST_MESSAGE_CREATED_DATE, 'UTC').valueOf()),
lastMessageText: 'Comment 1',
lastActorAccountID: USER_C_ACCOUNT_ID,
participants: {[USER_C_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}},
participants: {
[USER_C_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS},
[USER_A_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS},
},
type: CONST.REPORT.TYPE.CHAT,
},
},
Expand Down
Loading

0 comments on commit 4d0c30d

Please sign in to comment.