This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 828
End jitsi call when member is banned #8879
Merged
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
364e403
Jitsi call is ended when member is banned
b3ee671
Merge branch 'develop' into member-ban-ends-jitsi
a4f76ef
cypress tests for widget PIP close on leave/kick/ban
500bb2a
copyright updated
ca50cf1
Merge branch 'develop' into member-ban-ends-jitsi
f8e5add
Merge branch 'develop' into member-ban-ends-jitsi
Fox32 c4aa496
Merge branch 'develop' into member-ban-ends-jitsi
Fox32 95b48b8
import changes
26f9f6e
Merge remote-tracking branch 'origin/member-ban-ends-jitsi' into memb…
4af1c32
import changes, lint fixed
b1f6c59
Merge branch 'develop' into member-ban-ends-jitsi
Fox32 7e77285
Merge branch 'develop' into member-ban-ends-jitsi
Fox32 cab3a68
import changes
19779b7
Merge branch 'develop' into member-ban-ends-jitsi
Fox32 1007885
smaller spec changes to fix problems
2176470
Merge remote-tracking branch 'origin/member-ban-ends-jitsi' into memb…
a84f1b8
Merge branch 'develop' into member-ban-ends-jitsi
Fox32 b1e1dc6
Merge branch 'develop' into member-ban-ends-jitsi
Fox32 f897274
stale import removed, win.matrixcs.RoomStateEvent.Events is used
6411c63
Merge remote-tracking branch 'origin/member-ban-ends-jitsi' into memb…
2249f5b
Merge branch 'develop' into member-ban-ends-jitsi
Fox32 25e69ed
Merge branch 'develop' into member-ban-ends-jitsi
Fox32 01439ac
Merge branch 'develop' into member-ban-ends-jitsi
Fox32 ba2239d
fixed problem with kick, smaller test optimisations
7a80fef
Merge branch 'develop' into member-ban-ends-jitsi
Fox32 46c0326
comment removed
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
/// <reference types="cypress" /> | ||
|
||
import { IWidget } from "matrix-widget-api/src/interfaces/IWidget"; | ||
import { MatrixClient, MatrixEvent, RoomStateEvent } from "matrix-js-sdk/src/matrix"; | ||
|
||
import { SynapseInstance } from "../../plugins/synapsedocker"; | ||
import { UserCredentials } from "../../support/login"; | ||
|
||
const DEMO_WIDGET_ID = "demo-widget-id"; | ||
const DEMO_WIDGET_NAME = "Demo Widget"; | ||
const DEMO_WIDGET_TYPE = "demo"; | ||
const ROOM_NAME = "Demo"; | ||
|
||
const DEMO_WIDGET_HTML = ` | ||
<html lang="en"> | ||
<head> | ||
<title>Demo Widget</title> | ||
<script> | ||
window.onmessage = ev => { | ||
if (ev.data.action === 'capabilities') { | ||
window.parent.postMessage(Object.assign({ | ||
response: { | ||
capabilities: [] | ||
}, | ||
}, ev.data), '*'); | ||
} | ||
}; | ||
</script> | ||
</head> | ||
<body> | ||
<button id="demo">Demo</button> | ||
</body> | ||
</html> | ||
`; | ||
|
||
// mostly copied from src/utils/WidgetUtils.waitForRoomWidget with small modifications | ||
function waitForRoomWidget(matrixClient: MatrixClient, widgetId: string, roomId: string, add: boolean): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
function eventsInIntendedState(evList) { | ||
const widgetPresent = evList.some((ev) => { | ||
return ev.getContent() && ev.getContent()['id'] === widgetId; | ||
}); | ||
if (add) { | ||
return widgetPresent; | ||
} else { | ||
return !widgetPresent; | ||
} | ||
} | ||
|
||
const room = matrixClient.getRoom(roomId); | ||
|
||
const startingWidgetEvents = room.currentState.getStateEvents('im.vector.modular.widgets'); | ||
if (eventsInIntendedState(startingWidgetEvents)) { | ||
resolve(); | ||
return; | ||
} | ||
|
||
function onRoomStateEvents(ev: MatrixEvent) { | ||
if (ev.getRoomId() !== roomId || ev.getType() !== "im.vector.modular.widgets") return; | ||
|
||
const currentWidgetEvents = room.currentState.getStateEvents('im.vector.modular.widgets'); | ||
|
||
if (eventsInIntendedState(currentWidgetEvents)) { | ||
matrixClient.removeListener(RoomStateEvent.Events, onRoomStateEvents); | ||
resolve(); | ||
} | ||
} | ||
|
||
matrixClient.on(RoomStateEvent.Events, onRoomStateEvents); | ||
}); | ||
} | ||
|
||
describe("Widget PIP", () => { | ||
let synapse: SynapseInstance; | ||
let user: UserCredentials; | ||
let bot: MatrixClient; | ||
let demoWidgetUrl: string; | ||
|
||
function roomCreateAddWidgetPip(userRemove: 'leave' | 'kick' | 'ban') { | ||
cy.createRoom({ | ||
name: ROOM_NAME, | ||
invite: [bot.getUserId()], | ||
}).then(roomId => { | ||
// sets bot to Admin and user to Moderator | ||
cy.getClient().then(matrixClient => { | ||
return matrixClient.sendStateEvent(roomId, 'm.room.power_levels', { | ||
users: { | ||
[user.userId]: 50, | ||
[bot.getUserId()]: 100, | ||
}, | ||
}); | ||
}).as('powerLevelsChanged'); | ||
|
||
// bot joins the room | ||
cy.botJoinRoom(bot, roomId).as('botJoined'); | ||
|
||
// open the room | ||
cy.viewRoomByName(ROOM_NAME); | ||
|
||
// setup widget via state event | ||
cy.getClient().then(matrixClient => { | ||
const content: IWidget = { | ||
id: DEMO_WIDGET_ID, | ||
creatorUserId: 'somebody', | ||
type: DEMO_WIDGET_TYPE, | ||
name: DEMO_WIDGET_NAME, | ||
url: demoWidgetUrl, | ||
}; | ||
matrixClient.sendStateEvent(roomId, 'im.vector.modular.widgets', content, DEMO_WIDGET_ID); | ||
}); | ||
|
||
cy.all([ | ||
cy.get<string>("@powerLevelsChanged"), | ||
cy.get<string>("@botJoined"), | ||
]).then(() => { | ||
cy.window().then(async win => { | ||
// wait for widget state event | ||
await waitForRoomWidget(win.mxMatrixClientPeg.get(), DEMO_WIDGET_ID, roomId, true); | ||
|
||
// activate widget in pip mode | ||
win.mxActiveWidgetStore.setWidgetPersistence(DEMO_WIDGET_ID, roomId, true); | ||
|
||
// checks that pip window is opened | ||
cy.get(".mx_CallView_pip").should("exist"); | ||
|
||
// checks that widget is opened in pip | ||
cy.accessIframe(`iframe[title="${DEMO_WIDGET_NAME}"]`).within({}, () => { | ||
cy.get("#demo").should('exist'); | ||
}); | ||
|
||
const userId = user.userId; | ||
if (userRemove == 'leave') { | ||
cy.getClient().then(async matrixClient => { | ||
await matrixClient.leave(roomId); | ||
}); | ||
} else if (userRemove == 'kick') { | ||
await bot.kick(roomId, userId); | ||
} else if (userRemove == 'ban') { | ||
await bot.ban(roomId, userId); | ||
} | ||
|
||
// checks that pip window is closed | ||
cy.get(".mx_CallView_pip").should("not.exist"); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
beforeEach(() => { | ||
cy.startSynapse("default").then(data => { | ||
synapse = data; | ||
|
||
cy.initTestUser(synapse, "Mike").then(_user => { | ||
user = _user; | ||
}); | ||
cy.getBot(synapse, { displayName: "Bot" }).then(_bot => { | ||
bot = _bot; | ||
}); | ||
}); | ||
cy.serveHtmlFile(DEMO_WIDGET_HTML).then(url => { | ||
demoWidgetUrl = url; | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
cy.stopSynapse(synapse); | ||
cy.stopWebServers(); | ||
}); | ||
|
||
it('should be closed on leave', () => { | ||
roomCreateAddWidgetPip('leave'); | ||
}); | ||
|
||
it('should be closed on kick', () => { | ||
roomCreateAddWidgetPip('kick'); | ||
}); | ||
|
||
it('should be closed on ban', () => { | ||
roomCreateAddWidgetPip('ban'); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not copyright to us - it's copyright to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point :) updated, thanks