Skip to content

Commit

Permalink
Cherry picks for 0.28.2 (#793)
Browse files Browse the repository at this point in the history
* [MM-58773] Fix broken notifications test (#784)

* fix broken notifications test

* one more

* ci e2e isn't behaving the way local e2e is behaving...

* ci e2e isn't behaving the way local e2e is behaving...

* reload and wait after patching

* timeouts are not necessary

* remove redundant reload; move one reload earlier for consistency

(cherry picked from commit 2df639b)

* [MM-59027] Fix: Ringing not stopping after leave or /call end (#792)

(cherry picked from commit 81f89b6)
  • Loading branch information
cpoile authored Jun 21, 2024
1 parent 8841f5c commit 9e5cae2
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 39 deletions.
54 changes: 51 additions & 3 deletions e2e/tests/notifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ test.describe('notifications', () => {

test('dm channel, global desktop none', async ({page, request}) => {
await apiPatchNotifyProps(request, {desktop: 'none'});
await page.reload();
const devPage = new PlaywrightDevPage(page);
await devPage.goto();
await page.evaluate(() => {
window.e2eDesktopNotificationsRejected = [];
window.e2eNotificationsSoundedAt = [];
Expand All @@ -128,8 +128,8 @@ test.describe('notifications', () => {

test('dm channel, global sound false', async ({page, request}) => {
await apiPatchNotifyProps(request, {desktop: 'mentions', calls_desktop_sound: 'false'});
await page.reload();
const devPage = new PlaywrightDevPage(page);
await devPage.goto();
await page.evaluate(() => {
window.e2eDesktopNotificationsRejected = [];
window.e2eNotificationsSoundedAt = [];
Expand Down Expand Up @@ -192,6 +192,7 @@ test.describe('notifications', () => {

test('gm channel, global desktop none', async ({page, request}) => {
await apiPatchNotifyProps(request, {desktop: 'none'});
await page.reload();
const devPage = new PlaywrightDevPage(page);
await devPage.goto();
await page.evaluate(() => {
Expand All @@ -217,6 +218,7 @@ test.describe('notifications', () => {

test('gm channel, global desktop sound false', async ({page, request}) => {
await apiPatchNotifyProps(request, {desktop: 'mentions', calls_desktop_sound: 'false'});
await page.reload();
const devPage = new PlaywrightDevPage(page);
await page.evaluate(() => {
window.e2eDesktopNotificationsRejected = [];
Expand Down Expand Up @@ -627,6 +629,7 @@ test.describe('notifications', () => {
});

await apiPutStatus(request, 'dnd');
await page.reload();

// we need to be 'hidden' so that our desktop notifications are sent
const devPage = new PlaywrightDevPage(page);
Expand Down Expand Up @@ -661,8 +664,8 @@ test.describe('notifications', () => {
auto_responder_active: 'true',
auto_responder_message: 'ooo',
});
await page.reload();
const devPage = new PlaywrightDevPage(page);
await devPage.goto();
await page.evaluate(() => {
window.e2eDesktopNotificationsRejected = [];
window.e2eDesktopNotificationsSent = [];
Expand Down Expand Up @@ -854,4 +857,49 @@ test.describe('notifications', () => {
await user1.leaveCall();
await devPage.leaveCall();
});

test('ringing stops on last leave, and /call end', async ({page}) => {
await page.evaluate(() => {
window.e2eDesktopNotificationsRejected = [];
window.e2eDesktopNotificationsSent = [];
window.e2eNotificationsSoundedAt = [];
window.e2eNotificationsSoundStoppedAt = [];
});

const devPage = new PlaywrightDevPage(page);

const user1 = await startDMWith(userStorages[1], usernames[0]);
await user1.startCall();

let notification = page.getByTestId('call-incoming');
await expect(notification).toBeVisible();
await expect(notification).toContainText(`${usernames[1]} is inviting you to a call`);

// Ringing
await devPage.expectNotifications(1, 0, 1, 0);

await user1.leaveCall();

notification = page.getByTestId('call-incoming');
await expect(notification).toBeHidden();

// Stopped ringing
await devPage.expectNotifications(1, 0, 1, 1);

await user1.startCall();

notification = page.getByTestId('call-incoming');
await expect(notification).toBeVisible();
await expect(notification).toContainText(`${usernames[1]} is inviting you to a call`);

// Ringing
await devPage.expectNotifications(2, 0, 2, 1);

await user1.slashCallEnd();
notification = page.getByTestId('call-incoming');
await expect(notification).toBeHidden();

// Stopped ringing
await devPage.expectNotifications(2, 0, 2, 2);
});
});
51 changes: 31 additions & 20 deletions webapp/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
import {getThread} from 'mattermost-redux/selectors/entities/threads';
import {getCurrentUserId, getUser, isCurrentUserSystemAdmin} from 'mattermost-redux/selectors/entities/users';
import {ActionFuncAsync, DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions';
import {ActionFunc, ActionFuncAsync, DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions';
import {MessageDescriptor} from 'react-intl';
import {AnyAction, Dispatch} from 'redux';
import {batchActions} from 'redux-batched-actions';
Expand All @@ -26,7 +26,7 @@ import {logErr} from 'src/log';
import RestClient from 'src/rest_client';
import {
callDismissedNotification,
calls,
calls, channelIDForCurrentCall,
hostChangeAtForCurrentCall,
idForCurrentCall,
incomingCalls,
Expand Down Expand Up @@ -133,7 +133,7 @@ export const getCallsConfig = (): ActionFuncAsync<CallsConfig> => {

export const getCallActive = async (channelID: string) => {
try {
const res = await RestClient.fetch<{active: boolean}>(
const res = await RestClient.fetch<{ active: boolean }>(
`${getPluginPath()}/calls/${channelID}/active`,
{method: 'get'},
);
Expand Down Expand Up @@ -401,9 +401,6 @@ export function incomingCallOnChannel(channelID: string, callID: string, callerI

export const userLeft = (channelID: string, userID: string, sessionID: string) => {
return (dispatch: DispatchFunc, getState: GetStateFunc) => {
// save for later
const callID = calls(getState())[channelID]?.ID || '';

dispatch({
type: USER_LEFT,
data: {
Expand All @@ -415,24 +412,38 @@ export const userLeft = (channelID: string, userID: string, sessionID: string) =
});

if (numSessionsInCallInChannel(getState(), channelID) === 0) {
dispatch({
type: CALL_END,
data: {
channelID,
callID,
},
});
dispatch(callEnd(channelID));
}
};
};

export const callEnd = (channelID: string) => {
return (dispatch: DispatchFunc, getState: GetStateFunc) => {
if (channelIDForCurrentCall(getState()) === channelID) {
window.callsClient?.disconnect();
}

const callID = calls(getState())[channelID]?.ID || '';

dispatch({
type: CALL_END,
data: {
channelID,
callID,
},
});

dispatch(removeIncomingCallNotification(callID));
};
};

export const dismissIncomingCallNotification = (channelID: string, callID: string) => {
return async (dispatch: DispatchFunc) => {
return (dispatch: DispatchFunc) => {
RestClient.fetch(
`${getPluginPath()}/calls/${channelID}/dismiss-notification`,
{method: 'post'},
).catch((e) => logErr(e));
await dispatch(removeIncomingCallNotification(callID));
dispatch(removeIncomingCallNotification(callID));
dispatch({
type: DISMISS_CALL,
data: {
Expand All @@ -442,8 +453,8 @@ export const dismissIncomingCallNotification = (channelID: string, callID: strin
};
};

export const removeIncomingCallNotification = (callID: string): ActionFuncAsync => {
return async (dispatch: DispatchFunc) => {
export const removeIncomingCallNotification = (callID: string): ActionFunc => {
return (dispatch: DispatchFunc) => {
dispatch(stopRingingForCall(callID));
dispatch({
type: REMOVE_INCOMING_CALL,
Expand All @@ -456,7 +467,7 @@ export const removeIncomingCallNotification = (callID: string): ActionFuncAsync
};

export const ringForCall = (callID: string, sound: string) => {
return async (dispatch: DispatchFunc) => {
return (dispatch: DispatchFunc) => {
notificationSounds?.ring(sound);

// window.e2eNotificationsSoundedAt is added when running the e2e tests
Expand All @@ -478,8 +489,8 @@ export const ringForCall = (callID: string, sound: string) => {
};
};

export const stopRingingForCall = (callID: string): ActionFuncAsync => {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
export const stopRingingForCall = (callID: string): ActionFunc => {
return (dispatch: DispatchFunc, getState: GetStateFunc) => {
if (ringingForCall(getState(), callID)) {
notificationsStopRinging();
}
Expand Down
2 changes: 0 additions & 2 deletions webapp/src/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,6 @@ const incomingCalls = (state: IncomingCallNotification[] = [], action: IncomingC
return [...state, {...action.data}];
case REMOVE_INCOMING_CALL:
return state.filter((ic) => ic.callID !== action.data.callID);
case CALL_END:
return state.filter((ic) => ic.callID !== action.data.callID);
default:
return state;
}
Expand Down
16 changes: 2 additions & 14 deletions webapp/src/websocket_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {getChannel} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentUserId, getUser} from 'mattermost-redux/selectors/entities/users';
import {generateId} from 'mattermost-redux/utils/helpers';
import {
callEnd,
incomingCallOnChannel,
loadCallState,
loadProfilesByIdsIfMissing,
Expand All @@ -50,7 +51,6 @@ import {
} from 'src/types/types';

import {
CALL_END,
CALL_HOST,
CALL_LIVE_CAPTIONS_STATE,
CALL_RECORDING_STATE,
Expand Down Expand Up @@ -94,19 +94,7 @@ import {
// state mutating operations.
export function handleCallEnd(store: Store, ev: WebSocketMessage<EmptyData>) {
const channelID = ev.data.channelID || ev.broadcast.channel_id;
if (channelIDForCurrentCall(store.getState()) === channelID) {
window.callsClient?.disconnect();
}

const callID = calls(store.getState())[channelID]?.ID || '';

store.dispatch({
type: CALL_END,
data: {
channelID,
callID,
},
});
store.dispatch(callEnd(channelID));
}

// NOTE: it's important this function is kept synchronous in order to guarantee the order of
Expand Down

0 comments on commit 9e5cae2

Please sign in to comment.