Skip to content

Commit

Permalink
feat(channel-web): allow to disable notification sound (#4535)
Browse files Browse the repository at this point in the history
* feat(channel-web): allow to disable notification sound

* allow setting the variable globally in channel config

* remove default value

* test comment

* use equals instead of lodash
  • Loading branch information
davidvitora committed Feb 24, 2021
1 parent 9a53f86 commit c759dc3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions modules/channel-web/src/backend/api.ts
Expand Up @@ -153,6 +153,7 @@ export default async (bp: typeof sdk, db: Database) => {
details: botInfo.details,
languages: botInfo.languages,
extraStylesheet: config.extraStylesheet,
disableNotificationSound: config.disableNotificationSound,
security,
lazySocket: config.lazySocket
})
Expand Down
6 changes: 6 additions & 0 deletions modules/channel-web/src/config.ts
Expand Up @@ -82,4 +82,10 @@ export interface Config {
* @default false
*/
lazySocket: boolean

/**
* If true, chat will no longer play the notification sound for new messages.
* @default false
*/
disableNotificationSound: boolean
}
8 changes: 7 additions & 1 deletion modules/channel-web/src/views/lite/main.tsx
Expand Up @@ -259,7 +259,13 @@ class Web extends React.Component<MainProps> {
}

async playSound() {
if (this.state.played) {
// Preference for config object
const disableNotificationSound =
this.config.disableNotificationSound === undefined
? this.props.config.disableNotificationSound
: this.config.disableNotificationSound

if (this.state.played || disableNotificationSound) {
return
}

Expand Down
5 changes: 4 additions & 1 deletion modules/channel-web/src/views/lite/store/index.ts
Expand Up @@ -208,7 +208,10 @@ class RootStore {
runInAction('-> setBotInfo', () => {
this.botInfo = botInfo
})
this.mergeConfig({ extraStylesheet: botInfo.extraStylesheet })
this.mergeConfig({
extraStylesheet: botInfo.extraStylesheet,
disableNotificationSound: botInfo.disableNotificationSound
})
}

@action.bound
Expand Down
2 changes: 2 additions & 0 deletions modules/channel-web/src/views/lite/typings.d.ts
Expand Up @@ -180,6 +180,8 @@ export interface Config {
reference: string
/** If true, Websocket is created when the Webchat is opened. Bot cannot be proactive. */
lazySocket?: boolean
/** If true, chat will no longer play the notification sound for new messages. */
disableNotificationSound?: boolean
/** Refers to a specific webchat reference in parent window. Useful when using multiple chat window */
chatId?: string
/** CSS class to be applied to iframe */
Expand Down
3 changes: 3 additions & 0 deletions src/e2e/modules/webchat.test.ts
Expand Up @@ -64,4 +64,7 @@ describe('Module - Channel Web', () => {
await clickOn('#btn-convo-add')
await expect(await getMessageCount(page)).toBe(0)
})

// puppetter doesn`t have a way of testing sound playback from javascript objects
// it('Test disable sound notification', async () => {})
})

0 comments on commit c759dc3

Please sign in to comment.