Skip to content

Commit

Permalink
tweak(phone/call): remove call notification
Browse files Browse the repository at this point in the history
This is not the NotificationAlert. Since we force the call modal while in a call, there is no reason to keep an alert up
  • Loading branch information
itschip committed Mar 31, 2022
1 parent 913058d commit bc9c7bf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 43 deletions.
37 changes: 10 additions & 27 deletions phone/src/os/call/hooks/useCallNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const NOTIFICATION_ID = 'call:current';
export const useCallNotifications = () => {
const [t] = useTranslation();
const history = useHistory();
const { addNotificationAlert, removeId, addNotification } = useNotifications();
const { addNotificationAlert, removeId } = useNotifications();
const { getDisplayByNumber } = useContactActions();
const contacts = useContacts();

Expand All @@ -32,7 +32,7 @@ export const useCallNotifications = () => {
const callNotificationBase = {
app: 'CALL',
id: NOTIFICATION_ID,
cantClose: true,
cantClose: false,
icon,
onClick: () => history.push('/call'),
notificationIcon,
Expand All @@ -50,41 +50,24 @@ export const useCallNotifications = () => {
return;
}

if (call?.is_accepted) {
if (!call.isTransmitter && !call.is_accepted) {
play();
removeId(NOTIFICATION_ID);
addNotification({
addNotificationAlert({
...callNotificationBase,
title: t('DIALER.MESSAGES.INCOMING_CALL_TITLE', {
transmitter: contactDisplay(call.transmitter) || call.transmitter,
}),
keepWhenPhoneClosed: true,
content: (
<CallNotification>
{t('DIALER.MESSAGES.CURRENT_CALL_WITH', {
{t('DIALER.MESSAGES.TRANSMITTER_IS_CALLING', {
transmitter: contactDisplay(call.transmitter) || call.transmitter,
})}
</CallNotification>
),
title: t('DIALER.MESSAGES.CURRENT_CALL_TITLE'),
});
}
if (!call?.isTransmitter && !call?.is_accepted) {
play();
removeId(NOTIFICATION_ID);
addNotificationAlert(
{
...callNotificationBase,
title: t('DIALER.MESSAGES.INCOMING_CALL_TITLE', {
transmitter: contactDisplay(call.transmitter) || call.transmitter,
}),
keepWhenPhoneClosed: false,
content: (
<CallNotification>
{t('DIALER.MESSAGES.TRANSMITTER_IS_CALLING', {
transmitter: contactDisplay(call.transmitter) || call.transmitter,
})}
</CallNotification>
),
},
(n) => addNotification(n),
);
}
};

return { setNotification, clearNotification };
Expand Down
9 changes: 4 additions & 5 deletions resources/client/calls/cl_calls.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {
InitializeCallDTO,
StartCallEventData,
TransmitterNumDTO,
} from '../../../typings/call';
import { IAlertProps } from '../../../typings/alerts';
} from '@typings/call';
import { IAlertProps } from '@typings/alerts';
import { CallService } from './cl_calls.service';
import { animationService } from '../animations/animation.controller';
import { emitNetTyped, onNetTyped } from '../../server/utils/miscUtils';
import { RegisterNuiCB, RegisterNuiProxy } from '../cl_utils';
import { ClUtils } from '../client';
import { ServerPromiseResp } from '../../../typings/common';
import { ServerPromiseResp } from '@typings/common';
import { NuiCallbackFunc } from '@project-error/pe-utils';

const callService = new CallService();
Expand Down Expand Up @@ -45,7 +45,7 @@ export const initializeCallHandler = async (data: InitializeCallDTO, cb?: NuiCal
// Will trigger whenever somebody initializes a call to any number
RegisterNuiCB<InitializeCallDTO>(CallEvents.INITIALIZE_CALL, initializeCallHandler);

onNetTyped<StartCallEventData>(CallEvents.START_CALL, (data) => {
onNetTyped<StartCallEventData>(CallEvents.START_CALL, async (data) => {
const { transmitter, isTransmitter, receiver, isUnavailable } = data;
callService.handleStartCall(transmitter, receiver, isTransmitter, isUnavailable);
});
Expand Down Expand Up @@ -80,7 +80,6 @@ RegisterNuiCB<EndCallDTO>(CallEvents.END_CALL, async (data, cb) => {
data,
);
if (serverRes.status === 'error') return console.error(serverRes.errorMsg);
callService.handleEndCall();
cb({});
} catch (e) {
console.error(e);
Expand Down
11 changes: 5 additions & 6 deletions resources/client/calls/cl_calls.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { checkHasPhone } from '../cl_main';
import { IAlertProps } from '../../../typings/alerts';
import { ActiveCall, CallEvents, CallRejectReasons } from '../../../typings/call';
import { IAlertProps } from '@typings/alerts';
import { ActiveCall, CallEvents, CallRejectReasons } from '@typings/call';
import { Sound } from '../sounds/client-sound.class';
import KvpService from '../settings/client-kvp.service';

const exp = global.exports;

Expand Down Expand Up @@ -61,8 +60,8 @@ export class CallService {
// we don't want to reset our UI if we're in a call already or if we're currently starting a call that hasn't been canceled
if (this.isInCall() || !this.isCurrentPendingCall(receiver)) return;
if (this.callSound) this.callSound.stop();
this.openCallModal(false);
this.currentPendingCall = null;
this.openCallModal(false);
CallService.sendCallAction(CallEvents.SET_CALL_INFO, null);

const hangUpSound = new Sound(this.hangUpSoundName, this.hangUpSoundSet);
Expand Down Expand Up @@ -104,7 +103,7 @@ export class CallService {

handleCallAccepted(callData: ActiveCall) {
this.currentCall = callData.channelId;
if (this.callSound) this.callSound.stop(); // incase we're the one who accepts, we won't have the a callSound for now....plz help, I need sound name aaaaaaaa
if (this.callSound) this.callSound.stop();
exp['pma-voice'].setCallChannel(callData.channelId);
CallService.sendCallAction<ActiveCall>(CallEvents.SET_CALL_INFO, callData);
}
Expand All @@ -113,9 +112,9 @@ export class CallService {
if (this.callSound) this.callSound.stop();
this.currentCall = 0;
exp['pma-voice'].setCallChannel(0);
this.openCallModal(false);
this.currentPendingCall = null;

this.openCallModal(false);
CallService.sendCallAction<null>(CallEvents.SET_CALL_INFO, null);

const hangUpSound = new Sound(this.hangUpSoundName, this.hangUpSoundSet);
Expand Down
10 changes: 5 additions & 5 deletions resources/server/calls/calls.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class CallsService {
}

// At this point we return back to the client that the player contacted
// is technically available and therefore intialization process ic omplete
// is technically available and therefore initialization process ic complete
resp({
status: 'ok',
data: {
Expand Down Expand Up @@ -214,8 +214,8 @@ class CallsService {
}

// player who is calling and recieved the rejection.
emitNet(CallEvents.WAS_REJECTED, currentCall.transmitterSource, currentCall);
emitNet(CallEvents.WAS_REJECTED, currentCall.receiverSource, currentCall);
emitNet(CallEvents.WAS_REJECTED, currentCall.transmitterSource, currentCall);

// Update our database
await this.callsDB.updateCall(currentCall, false, endCallTimeUnix);
Expand Down Expand Up @@ -250,19 +250,19 @@ class CallsService {
if (currentCall.is_accepted) {
emitNet(
CallEvents.WAS_ENDED,
currentCall.transmitterSource,
currentCall.receiverSource,
currentCall.transmitterSource,
currentCall,
);
emitNet(
CallEvents.WAS_ENDED,
currentCall.receiverSource,
currentCall.transmitterSource,
currentCall.transmitterSource,
currentCall,
);
} else {
emitNet(CallEvents.WAS_REJECTED, currentCall.transmitterSource, currentCall);
emitNet(CallEvents.WAS_REJECTED, currentCall.receiverSource, currentCall);
emitNet(CallEvents.WAS_REJECTED, currentCall.transmitterSource, currentCall);
}
}
// player who is calling (transmitter)
Expand Down

0 comments on commit bc9c7bf

Please sign in to comment.