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

Make the ringing sound mutable/disablable #6534

Merged
merged 9 commits into from
Aug 4, 2021
Merged
20 changes: 18 additions & 2 deletions src/CallHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
Copyright 2015, 2016 OpenMarket Ltd
Copyright 2017, 2018 New Vector Ltd
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
Copyright 2019 - 2021 The Matrix.org Foundation C.I.C.
Copyright 2021 Šimon Brandner <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -86,6 +87,8 @@ import { randomUppercaseString, randomLowercaseString } from "matrix-js-sdk/src/
import EventEmitter from 'events';
import SdkConfig from './SdkConfig';
import { ensureDMExists, findDMForUser } from './createRoom';
import { IPushRule, RuleId, TweakName, Tweaks } from "matrix-js-sdk/src/@types/PushRules";
import { PushProcessor } from 'matrix-js-sdk/src/pushprocessor';

export const PROTOCOL_PSTN = 'm.protocol.pstn';
export const PROTOCOL_PSTN_PREFIXED = 'im.vector.protocol.pstn';
Expand Down Expand Up @@ -475,9 +478,22 @@ export default class CallHandler extends EventEmitter {
this.silencedCalls.delete(call.callId);
}

const incomingCallPushRule = (
new PushProcessor(MatrixClientPeg.get()).getPushRuleById(RuleId.IncomingCall) as IPushRule
);
switch (newState) {
case CallState.Ringing:
this.play(AudioID.Ring);
if (
incomingCallPushRule?.enabled &&
incomingCallPushRule.actions.some((a: Tweaks) => (
a.set_tweak === TweakName.Sound &&
a.value === "ring"
))
) {
this.play(AudioID.Ring);
} else {
this.silenceCall(call.callId);
}
break;
case CallState.InviteSent:
this.play(AudioID.Ringback);
Expand Down
12 changes: 5 additions & 7 deletions src/components/views/voip/IncomingCallBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,14 @@ export default class IncomingCallBox extends React.Component<IProps, IState> {
private onAction = (payload: ActionPayload) => {
switch (payload.action) {
case 'call_state': {
const call = CallHandler.sharedInstance().getCallForRoom(payload.room_id);
if (call && call.state === CallState.Ringing) {
const incomingCall = CallHandler.sharedInstance().getCallForRoom(payload.room_id);
if (incomingCall && incomingCall.state === CallState.Ringing) {
this.setState({
incomingCall: call,
silenced: false, // Reset silenced state for new call
incomingCall,
silenced: CallHandler.sharedInstance().isCallSilenced(incomingCall.callId),
});
} else {
this.setState({
incomingCall: null,
});
this.setState({ incomingCall: null });
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export function createTestClient() {
getItem: jest.fn(),
},
},
pushRules: {},
decryptEventIfNeeded: () => Promise.resolve(),
isUserIgnored: jest.fn().mockReturnValue(false),
getCapabilities: jest.fn().mockResolvedValue({}),
Expand Down