App icon indicating copy to clipboard operation
App copied to clipboard

[$250] Notification – Have no sound for notification received

Open IuliiaHerets opened this issue 1 year ago • 4 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 9.0.72-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: N/A If this was caught during regression testing, add the test name, ID and link from TestRail: N/A Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team

Action Performed:

  1. Go to https://staging.new.expensify.com/
  2. Log in as user A
  3. Open chat with user B
  4. As user B send message to user A
  5. Notice that user A receive a notification

Expected Result:

Notification is with sound

Actual Result:

Notification is without sound

Workaround:

Unknown

Platforms:

  • [ ] Android: Standalone
  • [ ] Android: HybridApp
  • [ ] Android: mWeb Chrome
  • [ ] iOS: Standalone
  • [ ] iOS: HybridApp
  • [ ] iOS: mWeb Safari
  • [x] MacOS: Chrome / Safari
  • [x] MacOS: Desktop

Screenshots/Videos

View all open jobs on GitHub

https://github.com/user-attachments/assets/81254557-0a12-412a-96f8-0300b73a586e

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021866271667566111224
  • Upwork Job ID: 1866271667566111224
  • Last Price Increase: 2024-12-10
Issue OwnerCurrent Issue Owner: @jayeshmangwani

IuliiaHerets avatar Dec 06 '24 13:12 IuliiaHerets

Triggered auto assignment to @RachCHopkins (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

melvin-bot[bot] avatar Dec 06 '24 13:12 melvin-bot[bot]

Can repro!

RachCHopkins avatar Dec 10 '24 00:12 RachCHopkins

Job added to Upwork: https://www.upwork.com/jobs/~021866271667566111224

melvin-bot[bot] avatar Dec 10 '24 00:12 melvin-bot[bot]

Triggered auto assignment to Contributor-plus team member for initial proposal review - @jayeshmangwani (External)

melvin-bot[bot] avatar Dec 10 '24 00:12 melvin-bot[bot]

Edited by proposal-police: This proposal was edited at 2024-12-24 09:19:58 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue

Browser notifications in New Expensify are displaying without sound when new messages arrive.

What is the root cause of that problem?

  1. Chrome on macOS has a known bug preventing notification sounds from working
  2. Current implementation uses silent: true by default in BrowserNotifications.ts
  3. Different browsers handle notification sounds inconsistently, leading to potential double-sound issues in some browsers

What changes do you think we should make in order to solve the problem?

  1. Use consistent silent: true approach with custom sound implementation:
notificationCache[notificationID] = new Notification(title, {
    body,
    icon: String(icon),
    data,
    silent: true,  // Prevent browser-native sounds
    tag,
});
if (!silent) {
    playSound(SOUNDS.RECEIVE);  // Play our custom sound
}
  1. Update default behavior in BrowserNotifications.ts:
// Change from
push(title, body, icon, data, onClick, true);

// To
push(title, body, icon, data, onClick, false);  // Enable sound by default

This solution ensures consistent notification sounds across all web platforms while avoiding double-sound issues in browsers like Safari.

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

N/A

What alternative solutions did you explore? (Optional)

adding silent: true to the new Notification.

notificationCache[notificationID] = new Notification(title, {
        body,
        icon: String(icon),
        data,
        silent: true,
        tag,
});

If this is a bug from the Chrome web browser and it's fixed, we could expect double notifications but with this, only our custom sound via playSound(SOUNDS.RECEIVE) will play and the default browser notification sound will be suppressed.

Result (Sound on)

https://github.com/user-attachments/assets/d841fe52-51f3-4e8c-b6da-16c673baab1a

MobileMage avatar Dec 11 '24 23:12 MobileMage

Proposal

Please re-state the problem that we are trying to solve in this issue.

  • Notification is without sound

What is the root cause of that problem?

  • In web, if we want to show notification with sound, we call something like:
        new Notification(title, {
            silent: false,
        });

The silent read-only property of the Notification interface specifies whether the notification should be silent, i.e., no sounds or vibrations should be issued regardless of the device settings. This is controlled via the silent option of the Notification() constructor.

  • But the Chrome notification sounds stopped working on MacBook, this bug are reported in here. In Safari, it still works well.

  • Even if the above issue is fixed, the notification still cannot have sound in case the message is not the modified expense message because we are usiing silent: true in:

https://github.com/Expensify/App/blob/082e14b9bc1259c329c7cd186ee8f21c0397f6fb/src/libs/Notification/LocalNotification/BrowserNotifications.ts#L125

The 6th param is true.

What changes do you think we should make in order to solve the problem?

  1. Solution to fix the 1st problem, where the notification sound does not work in macOS Chrome:
  • Since this issue occurs only on macOS Chrome and not on all platforms, we should consistently use silent: true and play our custom sound separately. Why always use silent: true? If we set silent: false in Safari (where the issue doesn't occur), the notification will produce two sounds: the default sound triggered by silent: false and our custom sound. This duplication can lead to an undesirable user experience.

Based on that, the logic:

https://github.com/Expensify/App/blob/082e14b9bc1259c329c7cd186ee8f21c0397f6fb/src/libs/Notification/LocalNotification/BrowserNotifications.ts#L64-L70 can be:

        notificationCache[notificationID] = new Notification(title, {
            body,
            icon: String(icon),
            data,
            silent: true,
            tag,
        });
        if (!silent) {
            playSound(SOUNDS.RECEIVE); // The sound can be decided later.
        }
  1. Solution to fix the 2nd problem, has no sound when the message received is not expense modified message.
  • We just need to update the 6th param in:

https://github.com/Expensify/App/blob/082e14b9bc1259c329c7cd186ee8f21c0397f6fb/src/libs/Notification/LocalNotification/BrowserNotifications.ts#L125

from true to false, or just need to remove that param since its default value is already false.

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

  • We need to create a test for the function push with the two test cases are when the silent param is true or false. If it is false, need to make sure there is no sound is triggred.

What alternative solutions did you explore? (Optional)

  • In MacOS Chrome, we call:
        if (!silent) {
            playSound(SOUNDS.RECEIVE); // The sound can be decided later.
        }
  • With other platforms, leave it as it is.
        if (!silent && Browser.getBrowser() === CONST.BROWSER.CHROME && !Browser.isMobile()) {
            // Play custom sound here
        }

truph01 avatar Dec 12 '24 05:12 truph01

@RachCHopkins, @jayeshmangwani Whoops! This issue is 2 days overdue. Let's get this updated quick!

melvin-bot[bot] avatar Dec 13 '24 09:12 melvin-bot[bot]

Not overdue, testing the above 2 proposals

jayeshmangwani avatar Dec 13 '24 09:12 jayeshmangwani

@JoshIri360 and @truph01 , did you receive the notification sound on desktop in the current version?

jayeshmangwani avatar Dec 13 '24 11:12 jayeshmangwani

No I didn't, tested in chrome and safari.

MobileMage avatar Dec 13 '24 12:12 MobileMage

No I didn't, tested in chrome and safari.

Thanks! So we don’t get sound on the web (Chrome + Safari) or desktop either, right? Just confirming so I can test solutions on those platforms.

jayeshmangwani avatar Dec 13 '24 12:12 jayeshmangwani

No I didn't, tested in chrome and safari.

Thanks! So we don’t get sound on the web (Chrome + Safari) or desktop either, right? Just confirming so I can test solutions on those platforms.

Yes, exactly.

MobileMage avatar Dec 13 '24 12:12 MobileMage

@jayeshmangwani In Macos Safari, it works well. The issue only appears in Macos Chrome. But you need to hard-code the 6th param to false:

https://github.com/Expensify/App/blob/082e14b9bc1259c329c7cd186ee8f21c0397f6fb/src/libs/Notification/LocalNotification/BrowserNotifications.ts#L125

before testing the sound notification if you want the sound is triggered by sending a message.

truph01 avatar Dec 14 '24 04:12 truph01

Thanks for the explanation @truph01. I feel that your proposal is quite similar to @JoshIri360, I’ve already tested their proposal, and it works fine on Safari, Chrome, and desktop.

jayeshmangwani avatar Dec 14 '24 06:12 jayeshmangwani

it works fine on Safari, Chrome, and desktop.

In safari, that solution can introduce the bug when the sound is triggered 2 times. Did you encounter it? @jayeshmangwani

truph01 avatar Dec 14 '24 06:12 truph01

No @truph01 , I have tested it a few times on Safari and only received one notification sound.

jayeshmangwani avatar Dec 14 '24 06:12 jayeshmangwani

I have tested it a few times on Safari and only received one notification sound.

That means this bug appears in both Chrome and Safari from your side, right?

truph01 avatar Dec 14 '24 06:12 truph01

Yes, that’s correct, which is why I asked for confirmation earlier. For me, neither Safari nor Chrome is producing any sound.

jayeshmangwani avatar Dec 14 '24 06:12 jayeshmangwani

Here is the video from my side, the sound is triggered in Safari:

https://github.com/user-attachments/assets/8cecc9f9-fbc5-4721-acb0-c21d9195e59b

truph01 avatar Dec 14 '24 06:12 truph01

Can you share the notification setting from your device, please? Here is mine:

image

truph01 avatar Dec 14 '24 06:12 truph01