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

Use platform specific mute setting for sounds #52088

Merged
merged 7 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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: 8 additions & 2 deletions src/libs/Sound/BaseSound.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
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;

Onyx.connect({
key: ONYXKEYS.USER,
callback: (val) => (isMuted = !!val?.isMutedAllSounds),
key: ONYXKEYS.NVP_MUTED_PLATFORMS,
callback: (val) => {
const platform = Browser.isMobile() ? CONST.PLATFORM.MOBILEWEB : getPlatform();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't very DRY, should we maybe spin this out into a function (it will avoid problems in future too)?

isMuted = !!val?.[platform];
},
});

const SOUNDS = {
Expand Down
10 changes: 7 additions & 3 deletions src/pages/iou/request/step/IOURequestStepScan/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -74,7 +76,9 @@ 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];
const [cameraPermissionStatus, setCameraPermissionStatus] = useState<string | null>(null);
const [didCapturePhoto, setDidCapturePhoto] = useState(false);
const [isLoadingReceipt, setIsLoadingReceipt] = useState(false);
Expand Down Expand Up @@ -489,7 +493,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
Expand Down Expand Up @@ -535,7 +539,7 @@ function IOURequestStepScan({
didCapturePhoto,
flash,
hasFlash,
user?.isMutedAllSounds,
isPlatformMuted,
translate,
transactionID,
isEditing,
Expand Down
3 changes: 0 additions & 3 deletions src/types/onyx/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading