From 2f578b400d31c63b369000c1a33660696430d02f Mon Sep 17 00:00:00 2001 From: c3024 Date: Wed, 6 Nov 2024 09:30:05 +0530 Subject: [PATCH 1/7] use platform specific mute setting for sounds --- src/libs/Sound/BaseSound.ts | 8 ++++++-- .../iou/request/step/IOURequestStepScan/index.native.tsx | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libs/Sound/BaseSound.ts b/src/libs/Sound/BaseSound.ts index e7fc5fadd259..aa1cf93e4a59 100644 --- a/src/libs/Sound/BaseSound.ts +++ b/src/libs/Sound/BaseSound.ts @@ -1,11 +1,15 @@ import Onyx from 'react-native-onyx'; +import getPlatform from '@libs/getPlatform'; import ONYXKEYS from '@src/ONYXKEYS'; let isMuted = false; Onyx.connect({ - key: ONYXKEYS.USER, - callback: (val) => (isMuted = !!val?.isMutedAllSounds), + key: ONYXKEYS.NVP_MUTED_PLATFORMS, + callback: (val) => { + const platform = getPlatform(); + isMuted = !!val?.[platform]; + }, }); const SOUNDS = { diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index d3f0c9cb496d..bf8ad43a6790 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -27,9 +27,11 @@ import useLocalize from '@hooks/useLocalize'; import usePolicy from '@hooks/usePolicy'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; +import * as Browser from '@libs/Browser'; import * as FileUtils from '@libs/fileDownload/FileUtils'; import getPhotoSource from '@libs/fileDownload/getPhotoSource'; import getCurrentPosition from '@libs/getCurrentPosition'; +import getPlatform from '@libs/getPlatform'; import * as IOUUtils from '@libs/IOUUtils'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; @@ -75,6 +77,9 @@ function IOURequestStepScan({ const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID ?? -1}`); const [user] = useOnyx(ONYXKEYS.USER); + const platform = Browser.isMobile() ? CONST.PLATFORM.MOBILEWEB : getPlatform(); + const [mutedPlatforms = {}] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS); + const isPlatformMuted = mutedPlatforms[platform]; const [cameraPermissionStatus, setCameraPermissionStatus] = useState(null); const [didCapturePhoto, setDidCapturePhoto] = useState(false); const [isLoadingReceipt, setIsLoadingReceipt] = useState(false); @@ -489,7 +494,7 @@ function IOURequestStepScan({ camera?.current ?.takePhoto({ flash: flash && hasFlash ? 'on' : 'off', - enableShutterSound: !user?.isMutedAllSounds, + enableShutterSound: !isPlatformMuted, }) .then((photo: PhotoFile) => { // Store the receipt on the transaction object in Onyx @@ -535,7 +540,7 @@ function IOURequestStepScan({ didCapturePhoto, flash, hasFlash, - user?.isMutedAllSounds, + isPlatformMuted, translate, transactionID, isEditing, From fa7b68483750c976f1b5158642978ce4c369f8e3 Mon Sep 17 00:00:00 2001 From: c3024 Date: Wed, 6 Nov 2024 09:33:38 +0530 Subject: [PATCH 2/7] remove unused `user` --- src/pages/iou/request/step/IOURequestStepScan/index.native.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index bf8ad43a6790..85eb4ea409fe 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -76,7 +76,6 @@ function IOURequestStepScan({ const policy = usePolicy(report?.policyID); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID ?? -1}`); - const [user] = useOnyx(ONYXKEYS.USER); const platform = Browser.isMobile() ? CONST.PLATFORM.MOBILEWEB : getPlatform(); const [mutedPlatforms = {}] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS); const isPlatformMuted = mutedPlatforms[platform]; From 68f1166658b4ad2d7ce1ca93337a5aaa5ca42cfa Mon Sep 17 00:00:00 2001 From: c3024 Date: Wed, 6 Nov 2024 10:17:16 +0530 Subject: [PATCH 3/7] mobileweb specific mute setting --- src/libs/Sound/BaseSound.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/Sound/BaseSound.ts b/src/libs/Sound/BaseSound.ts index aa1cf93e4a59..7d672d13fb6a 100644 --- a/src/libs/Sound/BaseSound.ts +++ b/src/libs/Sound/BaseSound.ts @@ -1,5 +1,7 @@ import Onyx from 'react-native-onyx'; +import * as Browser from '@libs/Browser'; import getPlatform from '@libs/getPlatform'; +import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; let isMuted = false; @@ -7,7 +9,7 @@ let isMuted = false; Onyx.connect({ key: ONYXKEYS.NVP_MUTED_PLATFORMS, callback: (val) => { - const platform = getPlatform(); + const platform = Browser.isMobile() ? CONST.PLATFORM.MOBILEWEB : getPlatform(); isMuted = !!val?.[platform]; }, }); From 6de5680bf95f40721933442b35ea6cfcce354e30 Mon Sep 17 00:00:00 2001 From: c3024 Date: Wed, 6 Nov 2024 17:00:55 +0530 Subject: [PATCH 4/7] remove unused onyx prop --- src/types/onyx/User.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/types/onyx/User.ts b/src/types/onyx/User.ts index 56b7a83d1618..eb5f1d888c46 100644 --- a/src/types/onyx/User.ts +++ b/src/types/onyx/User.ts @@ -6,9 +6,6 @@ type User = { /** Whether we should use the staging version of the secure API server */ shouldUseStagingServer?: boolean; - /** Whether user muted all sounds in application */ - isMutedAllSounds?: boolean; - /** Is the user account validated? */ validated: boolean; From ce167141b6e6b159427d722ef1aa34593c4aa7c2 Mon Sep 17 00:00:00 2001 From: c3024 Date: Wed, 6 Nov 2024 20:09:16 +0530 Subject: [PATCH 5/7] dry mWeb platform --- src/libs/Sound/BaseSound.ts | 4 +--- src/libs/getPlatform/index.ts | 6 +++++- .../iou/request/step/IOURequestStepScan/index.native.tsx | 3 +-- src/pages/settings/Preferences/PreferencesPage.tsx | 3 +-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libs/Sound/BaseSound.ts b/src/libs/Sound/BaseSound.ts index 7d672d13fb6a..1b1853eb30a6 100644 --- a/src/libs/Sound/BaseSound.ts +++ b/src/libs/Sound/BaseSound.ts @@ -1,7 +1,5 @@ import Onyx from 'react-native-onyx'; -import * as Browser from '@libs/Browser'; import getPlatform from '@libs/getPlatform'; -import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; let isMuted = false; @@ -9,7 +7,7 @@ let isMuted = false; Onyx.connect({ key: ONYXKEYS.NVP_MUTED_PLATFORMS, callback: (val) => { - const platform = Browser.isMobile() ? CONST.PLATFORM.MOBILEWEB : getPlatform(); + const platform = getPlatform(true); isMuted = !!val?.[platform]; }, }); diff --git a/src/libs/getPlatform/index.ts b/src/libs/getPlatform/index.ts index 5f5b45ac6e7d..1454b5f76ab3 100644 --- a/src/libs/getPlatform/index.ts +++ b/src/libs/getPlatform/index.ts @@ -1,6 +1,10 @@ import CONST from '@src/CONST'; import type Platform from './types'; +import * as Browser from '@libs/Browser'; -export default function getPlatform(): Platform { +export default function getPlatform(treatMWebDifferently = false): Platform { + if (treatMWebDifferently && Browser.isMobile()) { + return CONST.PLATFORM.MOBILEWEB; + } return CONST.PLATFORM.WEB; } diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 85eb4ea409fe..02eae422ae3c 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -27,7 +27,6 @@ import useLocalize from '@hooks/useLocalize'; import usePolicy from '@hooks/usePolicy'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as Browser from '@libs/Browser'; import * as FileUtils from '@libs/fileDownload/FileUtils'; import getPhotoSource from '@libs/fileDownload/getPhotoSource'; import getCurrentPosition from '@libs/getCurrentPosition'; @@ -76,7 +75,7 @@ function IOURequestStepScan({ const policy = usePolicy(report?.policyID); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID ?? -1}`); - const platform = Browser.isMobile() ? CONST.PLATFORM.MOBILEWEB : getPlatform(); + const platform = getPlatform(true); const [mutedPlatforms = {}] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS); const isPlatformMuted = mutedPlatforms[platform]; const [cameraPermissionStatus, setCameraPermissionStatus] = useState(null); diff --git a/src/pages/settings/Preferences/PreferencesPage.tsx b/src/pages/settings/Preferences/PreferencesPage.tsx index 5dee30518533..6616d342aa3c 100755 --- a/src/pages/settings/Preferences/PreferencesPage.tsx +++ b/src/pages/settings/Preferences/PreferencesPage.tsx @@ -13,7 +13,6 @@ import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as Browser from '@libs/Browser'; import getPlatform from '@libs/getPlatform'; import LocaleUtils from '@libs/LocaleUtils'; import Navigation from '@libs/Navigation/Navigation'; @@ -25,7 +24,7 @@ import ROUTES from '@src/ROUTES'; function PreferencesPage() { const [priorityMode] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE); - const platform = Browser.isMobile() ? CONST.PLATFORM.MOBILEWEB : getPlatform(); + const platform = getPlatform(true); const [mutedPlatforms = {}] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS); const isPlatformMuted = mutedPlatforms[platform]; const [user] = useOnyx(ONYXKEYS.USER); From 44caeb11a19076811ed26b6136f2eeaa69cc1b4b Mon Sep 17 00:00:00 2001 From: c3024 Date: Wed, 6 Nov 2024 20:10:17 +0530 Subject: [PATCH 6/7] prettier --- src/libs/getPlatform/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/getPlatform/index.ts b/src/libs/getPlatform/index.ts index 1454b5f76ab3..423411c4d07a 100644 --- a/src/libs/getPlatform/index.ts +++ b/src/libs/getPlatform/index.ts @@ -1,6 +1,6 @@ +import * as Browser from '@libs/Browser'; import CONST from '@src/CONST'; import type Platform from './types'; -import * as Browser from '@libs/Browser'; export default function getPlatform(treatMWebDifferently = false): Platform { if (treatMWebDifferently && Browser.isMobile()) { From 070eebcfca1a4cec29faada72965cc7c2aee784e Mon Sep 17 00:00:00 2001 From: c3024 Date: Wed, 6 Nov 2024 22:24:26 +0530 Subject: [PATCH 7/7] rename param --- src/libs/getPlatform/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/getPlatform/index.ts b/src/libs/getPlatform/index.ts index 423411c4d07a..aedb4610673e 100644 --- a/src/libs/getPlatform/index.ts +++ b/src/libs/getPlatform/index.ts @@ -2,8 +2,8 @@ import * as Browser from '@libs/Browser'; import CONST from '@src/CONST'; import type Platform from './types'; -export default function getPlatform(treatMWebDifferently = false): Platform { - if (treatMWebDifferently && Browser.isMobile()) { +export default function getPlatform(shouldMobileWebBeDistinctFromWeb = false): Platform { + if (shouldMobileWebBeDistinctFromWeb && Browser.isMobile()) { return CONST.PLATFORM.MOBILEWEB; } return CONST.PLATFORM.WEB;