2018-07-20 18:51:25 +02:00
|
|
|
/*
|
|
|
|
|
Copyright 2018 New Vector Ltd
|
2019-12-19 17:45:24 -07:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2018-07-20 18:51:25 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2018-08-14 12:53:16 +02:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2018-07-20 18:51:25 +02:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-12-09 09:10:23 +00:00
|
|
|
import * as puppeteer from "puppeteer";
|
|
|
|
|
|
2021-12-06 09:59:06 +11:00
|
|
|
import { measureStart, measureStop } from '../util';
|
|
|
|
|
import { ElementSession } from "../session";
|
2021-06-15 15:06:00 +01:00
|
|
|
|
2021-12-06 09:59:06 +11:00
|
|
|
export async function openRoomDirectory(session: ElementSession): Promise<void> {
|
2020-07-17 15:22:18 -06:00
|
|
|
const roomDirectoryButton = await session.query('.mx_LeftPanel_exploreButton');
|
2019-09-10 16:27:02 +02:00
|
|
|
await roomDirectoryButton.click();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 09:59:06 +11:00
|
|
|
export async function findSublist(session: ElementSession, name: string): Promise<puppeteer.ElementHandle> {
|
2021-04-19 15:07:11 +01:00
|
|
|
return await session.query(`.mx_RoomSublist[aria-label="${name}" i]`);
|
2020-07-07 16:34:42 -06:00
|
|
|
}
|
|
|
|
|
|
2021-12-06 09:59:06 +11:00
|
|
|
export async function createRoom(session: ElementSession, roomName: string, encrypted = false): Promise<void> {
|
2019-09-10 16:27:02 +02:00
|
|
|
session.log.step(`creates room "${roomName}"`);
|
|
|
|
|
|
2020-07-07 16:38:24 -06:00
|
|
|
const roomsSublist = await findSublist(session, "rooms");
|
2020-07-17 15:46:46 -06:00
|
|
|
const addRoomButton = await roomsSublist.$(".mx_RoomSublist_auxButton");
|
2019-03-29 12:27:48 +01:00
|
|
|
await addRoomButton.click();
|
2019-03-29 13:59:42 +01:00
|
|
|
|
2022-04-01 10:36:10 -04:00
|
|
|
const createRoomButton = await session.query('.mx_AccessibleButton[aria-label="New room"]');
|
2020-08-13 16:55:48 +01:00
|
|
|
await createRoomButton.click();
|
|
|
|
|
|
2019-09-20 17:22:43 +02:00
|
|
|
const roomNameInput = await session.query('.mx_CreateRoomDialog_name input');
|
2018-08-14 12:53:16 +02:00
|
|
|
await session.replaceInputText(roomNameInput, roomName);
|
2018-07-20 18:51:25 +02:00
|
|
|
|
2020-04-16 16:27:43 -06:00
|
|
|
if (!encrypted) {
|
|
|
|
|
const encryptionToggle = await session.query('.mx_CreateRoomDialog_e2eSwitch .mx_ToggleSwitch');
|
|
|
|
|
await encryptionToggle.click();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-16 15:35:31 +02:00
|
|
|
const createButton = await session.query('.mx_Dialog_primary');
|
2018-08-14 12:53:16 +02:00
|
|
|
await createButton.click();
|
2018-07-20 18:51:25 +02:00
|
|
|
|
2019-04-16 15:35:31 +02:00
|
|
|
await session.query('.mx_MessageComposer');
|
2018-08-14 12:53:16 +02:00
|
|
|
session.log.done();
|
2019-03-29 12:27:48 +01:00
|
|
|
}
|
2020-01-10 10:13:41 -07:00
|
|
|
|
2021-12-06 09:59:06 +11:00
|
|
|
export async function createDm(session: ElementSession, invitees: string[]): Promise<void> {
|
2020-04-17 14:31:33 -06:00
|
|
|
session.log.step(`creates DM with ${JSON.stringify(invitees)}`);
|
|
|
|
|
|
2021-06-15 15:06:00 +01:00
|
|
|
await measureStart(session, "mx_CreateDM");
|
|
|
|
|
|
2020-07-07 16:38:24 -06:00
|
|
|
const dmsSublist = await findSublist(session, "people");
|
2020-07-17 15:46:46 -06:00
|
|
|
const startChatButton = await dmsSublist.$(".mx_RoomSublist_auxButton");
|
2020-04-17 15:06:59 -06:00
|
|
|
await startChatButton.click();
|
2020-04-17 14:31:33 -06:00
|
|
|
|
2020-11-03 15:16:52 +00:00
|
|
|
const inviteesEditor = await session.query('.mx_InviteDialog_editor input');
|
2020-04-17 14:31:33 -06:00
|
|
|
for (const target of invitees) {
|
|
|
|
|
await session.replaceInputText(inviteesEditor, target);
|
|
|
|
|
await session.delay(1000); // give it a moment to figure out a suggestion
|
|
|
|
|
// find the suggestion and accept it
|
2022-06-09 12:45:33 +00:00
|
|
|
const suggestions = await session.queryAll('.mx_InviteDialog_tile_nameStack_userId');
|
2020-04-17 14:31:33 -06:00
|
|
|
const suggestionTexts = await Promise.all(suggestions.map(s => session.innerText(s)));
|
|
|
|
|
const suggestionIndex = suggestionTexts.indexOf(target);
|
|
|
|
|
if (suggestionIndex === -1) {
|
|
|
|
|
throw new Error(`failed to find a suggestion in the DM dialog to invite ${target} with`);
|
|
|
|
|
}
|
|
|
|
|
await suggestions[suggestionIndex].click();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// press the go button and hope for the best
|
|
|
|
|
const goButton = await session.query('.mx_InviteDialog_goButton');
|
|
|
|
|
await goButton.click();
|
|
|
|
|
|
|
|
|
|
await session.query('.mx_MessageComposer');
|
|
|
|
|
session.log.done();
|
2021-06-15 15:06:00 +01:00
|
|
|
|
|
|
|
|
await measureStop(session, "mx_CreateDM");
|
2020-04-17 14:31:33 -06:00
|
|
|
}
|