-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Write platform specific mute settings to backend #50493
Changes from 6 commits
1e138f9
2595cb8
e7d6547
414b756
172368d
97b8937
91db435
266996a
173b49d
d7361f8
683d536
d072b8f
d4a4ec5
a442467
be2f50a
cb4e58e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type Platform from '@libs/getPlatform/types'; | ||
|
||
type TogglePlatformMuteParams = { | ||
authToken: string; | ||
platform: Platform; | ||
}; | ||
|
||
export default TogglePlatformMuteParams; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -52,11 +54,13 @@ import * as Session from './Session'; | |
|
||
let currentUserAccountID = -1; | ||
let currentEmail = ''; | ||
let authToken = ''; | ||
Onyx.connect({ | ||
key: ONYXKEYS.SESSION, | ||
callback: (value) => { | ||
currentUserAccountID = value?.accountID ?? -1; | ||
currentEmail = value?.email ?? ''; | ||
authToken = value?.authToken ?? ''; | ||
}, | ||
}); | ||
|
||
|
@@ -982,8 +986,31 @@ function clearUserErrorMessage() { | |
Onyx.merge(ONYXKEYS.USER, {error: ''}); | ||
} | ||
|
||
function setMuteAllSounds(isMutedAllSounds: boolean) { | ||
Onyx.merge(ONYXKEYS.USER, {isMutedAllSounds}); | ||
function togglePlatformMute(platform: Platform, mutedPlatforms: Platform[]) { | ||
const isPlatformMuted = mutedPlatforms?.includes(platform); | ||
const newMutedPlatforms = isPlatformMuted ? mutedPlatforms.filter((mutedPlatform) => mutedPlatform !== platform) : [...mutedPlatforms, platform]; | ||
|
||
const optimisticData: OnyxUpdate[] = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.SET, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it better to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For NVPs, the server uses SET, so it's probably best to use SET here as well. That will keep things consistent. |
||
key: ONYXKEYS.NVP_MUTED_PLATFORMS, | ||
value: newMutedPlatforms, | ||
}, | ||
]; | ||
const failureData: OnyxUpdate[] = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.SET, | ||
key: ONYXKEYS.NVP_MUTED_PLATFORMS, | ||
value: mutedPlatforms, | ||
}, | ||
]; | ||
|
||
const parameters: TogglePlatformMuteParams = {authToken, platform}; | ||
|
||
API.write(WRITE_COMMANDS.TOGGLE_PLATFORM_MUTE, parameters, { | ||
optimisticData, | ||
failureData, | ||
}); | ||
} | ||
|
||
/** | ||
|
@@ -1358,7 +1385,7 @@ export { | |
subscribeToUserEvents, | ||
updatePreferredSkinTone, | ||
setShouldUseStagingServer, | ||
setMuteAllSounds, | ||
togglePlatformMute, | ||
clearUserErrorMessage, | ||
joinScreenShare, | ||
clearScreenShareRequest, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry. I guess this was something I didn't explicitly say. It's actually an object like this:
and if a platform is muted, it is removed from the object entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!