diff --git a/src/CONST.ts b/src/CONST.ts index dd048f95d374..dce6f53d47f0 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -542,6 +542,7 @@ const CONST = { ANDROID: 'android', WEB: 'web', DESKTOP: 'desktop', + MOBILEWEB: 'mobileweb', }, PLATFORM_SPECIFIC_KEYS: { CTRL: { diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 427e05052ae3..e14e536154a3 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -1,6 +1,7 @@ import type {ValueOf} from 'type-fest'; import type CONST from './CONST'; import type {OnboardingCompanySizeType, OnboardingPurposeType} from './CONST'; +import type Platform from './libs/getPlatform/types'; import type * as FormTypes from './types/form'; import type * as OnyxTypes from './types/onyx'; import type {Attendee} from './types/onyx/IOU'; @@ -122,6 +123,9 @@ const ONYXKEYS = { /** This NVP contains data associated with HybridApp */ NVP_TRYNEWDOT: 'nvp_tryNewDot', + /** Contains the platforms for which the user muted the sounds */ + NVP_MUTED_PLATFORMS: 'nvp_mutedPlatforms', + /** Contains the user preference for the LHN priority mode */ NVP_PRIORITY_MODE: 'nvp_priorityMode', @@ -903,6 +907,7 @@ type OnyxValuesMapping = { [ONYXKEYS.USER_METADATA]: OnyxTypes.UserMetadata; [ONYXKEYS.STASHED_SESSION]: OnyxTypes.Session; [ONYXKEYS.BETAS]: OnyxTypes.Beta[]; + [ONYXKEYS.NVP_MUTED_PLATFORMS]: Partial>; [ONYXKEYS.NVP_PRIORITY_MODE]: ValueOf; [ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE]: OnyxTypes.BlockedFromConcierge; diff --git a/src/libs/API/parameters/TogglePlatformMuteParams.ts b/src/libs/API/parameters/TogglePlatformMuteParams.ts new file mode 100644 index 000000000000..1517782e18d7 --- /dev/null +++ b/src/libs/API/parameters/TogglePlatformMuteParams.ts @@ -0,0 +1,7 @@ +import type Platform from '@libs/getPlatform/types'; + +type TogglePlatformMuteParams = { + platformToMute: Platform; +}; + +export default TogglePlatformMuteParams; diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index 9f07049736ed..438f64045fc3 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -341,3 +341,4 @@ export type {default as SetInvoicingTransferBankAccountParams} from './SetInvoic export type {default as ConnectPolicyToQuickBooksDesktopParams} from './ConnectPolicyToQuickBooksDesktopParams'; export type {default as UpdateQuickbooksDesktopExpensesExportDestinationTypeParams} from './UpdateQuickbooksDesktopExpensesExportDestinationTypeParams'; export type {default as UpdateQuickbooksDesktopCompanyCardExpenseAccountTypeParams} from './UpdateQuickbooksDesktopCompanyCardExpenseAccountTypeParams'; +export type {default as TogglePlatformMuteParams} from './TogglePlatformMuteParams'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 063be53a2eda..7359264af830 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -75,6 +75,7 @@ const WRITE_COMMANDS = { VALIDATE_SECONDARY_LOGIN: 'ValidateSecondaryLogin', UPDATE_PREFERRED_EMOJI_SKIN_TONE: 'UpdatePreferredEmojiSkinTone', UPDATE_CHAT_PRIORITY_MODE: 'UpdateChatPriorityMode', + TOGGLE_PLATFORM_MUTE: 'TogglePlatformMute', SET_CONTACT_METHOD_AS_DEFAULT: 'SetContactMethodAsDefault', UPDATE_THEME: 'UpdateTheme', UPDATE_STATUS: 'UpdateStatus', @@ -484,6 +485,7 @@ type WriteCommandParameters = { [WRITE_COMMANDS.UPDATE_PREFERRED_EMOJI_SKIN_TONE]: Parameters.UpdatePreferredEmojiSkinToneParams; [WRITE_COMMANDS.UPDATE_CHAT_PRIORITY_MODE]: Parameters.UpdateChatPriorityModeParams; [WRITE_COMMANDS.SET_CONTACT_METHOD_AS_DEFAULT]: Parameters.SetContactMethodAsDefaultParams; + [WRITE_COMMANDS.TOGGLE_PLATFORM_MUTE]: Parameters.TogglePlatformMuteParams; [WRITE_COMMANDS.UPDATE_THEME]: Parameters.UpdateThemeParams; [WRITE_COMMANDS.UPDATE_STATUS]: Parameters.UpdateStatusParams; [WRITE_COMMANDS.CLEAR_STATUS]: null; diff --git a/src/libs/actions/User.ts b/src/libs/actions/User.ts index 754563b57429..eaccbb8497ac 100644 --- a/src/libs/actions/User.ts +++ b/src/libs/actions/User.ts @@ -12,6 +12,7 @@ import type { RequestContactMethodValidateCodeParams, SetContactMethodAsDefaultParams, SetNameValuePairParams, + TogglePlatformMuteParams, UpdateChatPriorityModeParams, UpdateNewsletterSubscriptionParams, UpdatePreferredEmojiSkinToneParams, @@ -23,6 +24,7 @@ import type { import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import DateUtils from '@libs/DateUtils'; import * as ErrorUtils from '@libs/ErrorUtils'; +import type Platform from '@libs/getPlatform/types'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import * as SequentialQueue from '@libs/Network/SequentialQueue'; @@ -978,8 +980,32 @@ function clearUserErrorMessage() { Onyx.merge(ONYXKEYS.USER, {error: ''}); } -function setMuteAllSounds(isMutedAllSounds: boolean) { - Onyx.merge(ONYXKEYS.USER, {isMutedAllSounds}); +function togglePlatformMute(platform: Platform, mutedPlatforms: Partial>) { + const newMutedPlatforms = mutedPlatforms?.[platform] + ? {...mutedPlatforms, [platform]: undefined} // Remove platform if it's muted + : {...mutedPlatforms, [platform]: true}; // Add platform if it's not muted + + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.SET, + key: ONYXKEYS.NVP_MUTED_PLATFORMS, + value: newMutedPlatforms, + }, + ]; + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.SET, + key: ONYXKEYS.NVP_MUTED_PLATFORMS, + value: mutedPlatforms, + }, + ]; + + const parameters: TogglePlatformMuteParams = {platformToMute: platform}; + + API.write(WRITE_COMMANDS.TOGGLE_PLATFORM_MUTE, parameters, { + optimisticData, + failureData, + }); } /** @@ -1354,7 +1380,7 @@ export { subscribeToUserEvents, updatePreferredSkinTone, setShouldUseStagingServer, - setMuteAllSounds, + togglePlatformMute, clearUserErrorMessage, joinScreenShare, clearScreenShareRequest, diff --git a/src/pages/settings/Preferences/PreferencesPage.tsx b/src/pages/settings/Preferences/PreferencesPage.tsx index f2c5f0366640..5dee30518533 100755 --- a/src/pages/settings/Preferences/PreferencesPage.tsx +++ b/src/pages/settings/Preferences/PreferencesPage.tsx @@ -13,6 +13,8 @@ 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'; import * as User from '@userActions/User'; @@ -22,6 +24,10 @@ import ROUTES from '@src/ROUTES'; function PreferencesPage() { const [priorityMode] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE); + + const platform = Browser.isMobile() ? CONST.PLATFORM.MOBILEWEB : getPlatform(); + const [mutedPlatforms = {}] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS); + const isPlatformMuted = mutedPlatforms[platform]; const [user] = useOnyx(ONYXKEYS.USER); const [preferredTheme] = useOnyx(ONYXKEYS.PREFERRED_THEME); @@ -79,8 +85,8 @@ function PreferencesPage() { User.togglePlatformMute(platform, mutedPlatforms)} />