Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 7d06507

Browse files
authored
Merge pull request #6534 from SimonBrandner/fix/ringing-sound/15591
Make the ringing sound mutable/disablable
2 parents b4b4fb9 + 74e1342 commit 7d06507

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/CallHandler.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/*
22
Copyright 2015, 2016 OpenMarket Ltd
33
Copyright 2017, 2018 New Vector Ltd
4-
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
4+
Copyright 2019 - 2021 The Matrix.org Foundation C.I.C.
5+
Copyright 2021 Šimon Brandner <simon.bra.ag@gmail.com>
56
67
Licensed under the Apache License, Version 2.0 (the "License");
78
you may not use this file except in compliance with the License.
@@ -85,6 +86,8 @@ import { randomUppercaseString, randomLowercaseString } from "matrix-js-sdk/src/
8586
import EventEmitter from 'events';
8687
import SdkConfig from './SdkConfig';
8788
import { ensureDMExists, findDMForUser } from './createRoom';
89+
import { IPushRule, RuleId, TweakName, Tweaks } from "matrix-js-sdk/src/@types/PushRules";
90+
import { PushProcessor } from 'matrix-js-sdk/src/pushprocessor';
8891
import { WidgetLayoutStore, Container } from './stores/widgets/WidgetLayoutStore';
8992
import { getIncomingCallToastKey } from './toasts/IncomingCallToast';
9093
import ToastStore from './stores/ToastStore';
@@ -479,14 +482,28 @@ export default class CallHandler extends EventEmitter {
479482
}
480483

481484
switch (newState) {
482-
case CallState.Ringing:
483-
this.play(AudioID.Ring);
485+
case CallState.Ringing: {
486+
const incomingCallPushRule = (
487+
new PushProcessor(MatrixClientPeg.get()).getPushRuleById(RuleId.IncomingCall) as IPushRule
488+
);
489+
const pushRuleEnabled = incomingCallPushRule?.enabled;
490+
const tweakSetToRing = incomingCallPushRule?.actions.some((action: Tweaks) => (
491+
action.set_tweak === TweakName.Sound &&
492+
action.value === "ring"
493+
));
494+
495+
if (pushRuleEnabled && tweakSetToRing) {
496+
this.play(AudioID.Ring);
497+
} else {
498+
this.silenceCall(call.callId);
499+
}
484500
break;
485-
case CallState.InviteSent:
501+
}
502+
case CallState.InviteSent: {
486503
this.play(AudioID.Ringback);
487504
break;
488-
case CallState.Ended:
489-
{
505+
}
506+
case CallState.Ended: {
490507
const hangupReason = call.hangupReason;
491508
Analytics.trackEvent('voip', 'callEnded', 'hangupReason', hangupReason);
492509
this.removeCallForRoom(mappedRoomId);

src/toasts/IncomingCallToast.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default class IncomingCallToast extends React.Component<IProps, IState> {
4545
super(props);
4646

4747
this.state = {
48-
silenced: false,
48+
silenced: CallHandler.sharedInstance().isCallSilenced(this.props.call.callId),
4949
};
5050
}
5151

@@ -61,7 +61,7 @@ export default class IncomingCallToast extends React.Component<IProps, IState> {
6161
this.setState({ silenced: CallHandler.sharedInstance().isCallSilenced(this.props.call.callId) });
6262
};
6363

64-
private onAnswerClick= (e: React.MouseEvent): void => {
64+
private onAnswerClick = (e: React.MouseEvent): void => {
6565
e.stopPropagation();
6666
dis.dispatch({
6767
action: 'answer',

test/test-utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export function createTestClient() {
9696
getItem: jest.fn(),
9797
},
9898
},
99+
pushRules: {},
99100
decryptEventIfNeeded: () => Promise.resolve(),
100101
isUserIgnored: jest.fn().mockReturnValue(false),
101102
getCapabilities: jest.fn().mockResolvedValue({}),

0 commit comments

Comments
 (0)