You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-10 09:22:25 +03:00
Add slash command to switch to a room's virtual room (#7839)
* Add slash command to switch to a room's virtual room * Update to new interface * Return null if no virtual user * Throw newTranslateableError * Types * Disable tovirtual if virtual rooms not supported
This commit is contained in:
@@ -42,13 +42,20 @@ export default class VoipUserMapper {
|
||||
return results[0].userid;
|
||||
}
|
||||
|
||||
public async getOrCreateVirtualRoomForRoom(roomId: string): Promise<string> {
|
||||
private async getVirtualUserForRoom(roomId: string): Promise<string | null> {
|
||||
const userId = DMRoomMap.shared().getUserIdForRoomId(roomId);
|
||||
if (!userId) return null;
|
||||
|
||||
const virtualUser = await this.userToVirtualUser(userId);
|
||||
if (!virtualUser) return null;
|
||||
|
||||
return virtualUser;
|
||||
}
|
||||
|
||||
public async getOrCreateVirtualRoomForRoom(roomId: string): Promise<string | null> {
|
||||
const virtualUser = await this.getVirtualUserForRoom(roomId);
|
||||
if (!virtualUser) return null;
|
||||
|
||||
const virtualRoomId = await ensureVirtualRoomExists(MatrixClientPeg.get(), virtualUser, roomId);
|
||||
MatrixClientPeg.get().setRoomAccountData(virtualRoomId, VIRTUAL_ROOM_EVENT_TYPE, {
|
||||
native_room: roomId,
|
||||
@@ -59,6 +66,17 @@ export default class VoipUserMapper {
|
||||
return virtualRoomId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ID of the virtual room for a room, or null if the room has no
|
||||
* virtual room
|
||||
*/
|
||||
public async getVirtualRoomForRoom(roomId: string): Promise<Room | null> {
|
||||
const virtualUser = await this.getVirtualUserForRoom(roomId);
|
||||
if (!virtualUser) return null;
|
||||
|
||||
return findDMForUser(MatrixClientPeg.get(), virtualUser);
|
||||
}
|
||||
|
||||
public nativeRoomForVirtualRoom(roomId: string): string {
|
||||
const cachedNativeRoomId = this.virtualToNativeRoomIdCache.get(roomId);
|
||||
if (cachedNativeRoomId) {
|
||||
|
||||
Reference in New Issue
Block a user