- Use proper openJoinAlias

- Avoid requests to join the just joined room
This commit is contained in:
C0ffeeCode 2022-05-12 10:37:17 +02:00
parent 48dcfb0aa9
commit 473d97312e
No known key found for this signature in database
GPG key ID: 211B3EF9F31E56FE

View file

@ -1,25 +1,17 @@
import {
selectRoom, selectSpace,
} from '../client/action/navigation';
import matrixClient from '../client/initMatrix';
selectRoom, selectSpace, openJoinAlias,
} from '../client/action/navigation';
import navigation from '../client/state/navigation';
import cons from '../client/state/cons';
import navigation from '../client/state/navigation';
import cons from '../client/state/cons';
async function joinRoom(roomAlias) {
const room = await matrixClient.matrixClient.getRoomSummary(roomAlias);
// TODO: Check if already joined, replace this confirm
if (!confirm(`Do you want to join ${room.name} (${roomAlias})?`)) return;
await matrixClient.matrixClient.joinRoom(roomAlias);
const state = await matrixClient.matrixClient.roomState(room.room_id);
const isSpace = state.find((e) => e.type === 'm.room.create').content.type === 'm.space';
if (isSpace) selectSpace(room.room_id);
else selectRoom(room.room_id);
}
async function joinRoom(roomAlias) {
openJoinAlias(roomAlias);
}
const listeners = [];
const listeners = [];
export function handleUriFragmentChange() {
export function handleUriFragmentChange() {
if (window.location.hash === ''
|| window.location.hash === '#'
|| window.location.hash === '#/') return;
@ -48,9 +40,9 @@ import {
else if (a[3] && a[3][0] === '$') selectRoom(a[2], a[3]);
else selectRoom(a[2]);
}
}
}
listeners.push(
listeners.push(
window.addEventListener('hashchange', handleUriFragmentChange),
navigation.on(cons.events.navigation.ROOM_SELECTED, (selectedRoom, _previousRoom, eventId) => {
@ -59,6 +51,7 @@ import {
else a[3] = eventId;
if (!selectRoom) a.length = 2;
else a[2] = selectedRoom;
if (a[1] === 'join') a[1] = cons.tabs.HOME;
window.location.hash = a.join('/');
}),
@ -73,9 +66,8 @@ import {
h.length = 2;
window.location.hash = h.join('/');
}),
);
);
export function destructUrlHandling() {
export function destructUrlHandling() {
listeners.forEach((l) => navigation.removeListener(l));
}
}