Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,7 @@ const CONST = {
LIST_SCROLLING_DEBOUNCE_TIME: 200,
PUSHER_PING_PONG: 'pusher_ping_pong',
LOCATION_UPDATE_INTERVAL: 5000,
PLAY_SOUND_MESSAGE_DEBOUNCE_TIME: 500,
},
PRIORITY_MODE: {
GSD: 'gsd',
Expand Down
13 changes: 12 additions & 1 deletion src/libs/actions/User.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {isBefore} from 'date-fns';
import debounce from 'lodash/debounce';
import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
Expand Down Expand Up @@ -1041,9 +1042,19 @@ function subscribeToUserEvents() {
applyOnyxUpdatesReliably(updates);
});

// Debounce the playSoundForMessageType function to avoid playing sounds too often, for example when a user comeback after offline and alot of messages come in
// See https://github.com/Expensify/App/issues/57961 for more details
const debouncedPlaySoundForMessageType = debounce(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can add a comment explaining why we need to debounce it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@daledah Friendly bump!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the delay, I updated.

(pushJSONMessage: OnyxServerUpdate[]) => {
playSoundForMessageType(pushJSONMessage);
},
CONST.TIMING.PLAY_SOUND_MESSAGE_DEBOUNCE_TIME,
{trailing: true},
);

// Handles Onyx updates coming from Pusher through the mega multipleEvents.
PusherUtils.subscribeToMultiEvent(Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE, (pushJSON: OnyxServerUpdate[]) => {
playSoundForMessageType(pushJSON);
debouncedPlaySoundForMessageType(pushJSON);

return SequentialQueue.getCurrentRequest().then(() => {
// If we don't have the currentUserAccountID (user is logged out) or this is not the
Expand Down