- 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,81 +1,73 @@
import { import {
selectRoom, selectSpace, selectRoom, selectSpace, openJoinAlias,
} from '../client/action/navigation'; } from '../client/action/navigation';
import matrixClient from '../client/initMatrix';
import navigation from '../client/state/navigation';
import navigation from '../client/state/navigation'; import cons from '../client/state/cons';
import cons from '../client/state/cons';
async function joinRoom(roomAlias) {
async function joinRoom(roomAlias) { openJoinAlias(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; const listeners = [];
await matrixClient.matrixClient.joinRoom(roomAlias);
const state = await matrixClient.matrixClient.roomState(room.room_id); export function handleUriFragmentChange() {
const isSpace = state.find((e) => e.type === 'm.room.create').content.type === 'm.space'; if (window.location.hash === ''
if (isSpace) selectSpace(room.room_id);
else selectRoom(room.room_id);
}
const listeners = [];
export function handleUriFragmentChange() {
if (window.location.hash === ''
|| window.location.hash === '#' || window.location.hash === '#'
|| window.location.hash === '#/') return; || window.location.hash === '#/') return;
// Room must be selected AFTER client finished loading // Room must be selected AFTER client finished loading
const a = window.location.hash.split('/');
// a[0] always is #
// if no trailing '/' would be used for hash we would have to remove it
// relevant array items start at index 1
if (a[1] === 'join') {
joinRoom(a[2]);
return;
}
// /<room|home|spaceid>...
if (a.length >= 2) {
if (a[1] === 'room' || a[1][0] !== '!') a[1] = cons.tabs.HOME;
selectSpace(a[1]);
}
// /<room|spaceid>/<roomid?>/<eventid?>
if (a.length >= 3) {
if (a[2][0] !== '!') selectRoom(null);
else if (a[3] && a[3][0] === '$') selectRoom(a[2], a[3]);
else selectRoom(a[2]);
}
}
listeners.push(
window.addEventListener('hashchange', handleUriFragmentChange),
navigation.on(cons.events.navigation.ROOM_SELECTED, (selectedRoom, _previousRoom, eventId) => {
const a = window.location.hash.split('/'); const a = window.location.hash.split('/');
// a[0] always is # if (!eventId) a.length = 3;
// if no trailing '/' would be used for hash we would have to remove it else a[3] = eventId;
// relevant array items start at index 1 if (!selectRoom) a.length = 2;
else a[2] = selectedRoom;
if (a[1] === 'join') { if (a[1] === 'join') a[1] = cons.tabs.HOME;
joinRoom(a[2]); window.location.hash = a.join('/');
return; }),
}
navigation.on(cons.events.navigation.SPACE_SELECTED, (spaceSelected) => {
// /<room|home|spaceid>... const strp = window.location.hash.split('/');
if (a.length >= 2) { strp[1] = spaceSelected ?? 'room';
if (a[1] === 'room' || a[1][0] !== '!') a[1] = cons.tabs.HOME; window.location.hash = strp.join('/');
}),
selectSpace(a[1]);
} navigation.on(cons.actions.navigation.OPEN_NAVIGATION, () => {
const h = window.location.hash.split('/');
// /<room|spaceid>/<roomid?>/<eventid?> h.length = 2;
if (a.length >= 3) { window.location.hash = h.join('/');
if (a[2][0] !== '!') selectRoom(null); }),
else if (a[3] && a[3][0] === '$') selectRoom(a[2], a[3]); );
else selectRoom(a[2]);
} export function destructUrlHandling() {
} listeners.forEach((l) => navigation.removeListener(l));
}
listeners.push(
window.addEventListener('hashchange', handleUriFragmentChange),
navigation.on(cons.events.navigation.ROOM_SELECTED, (selectedRoom, _previousRoom, eventId) => {
const a = window.location.hash.split('/');
if (!eventId) a.length = 3;
else a[3] = eventId;
if (!selectRoom) a.length = 2;
else a[2] = selectedRoom;
window.location.hash = a.join('/');
}),
navigation.on(cons.events.navigation.SPACE_SELECTED, (spaceSelected) => {
const strp = window.location.hash.split('/');
strp[1] = spaceSelected ?? 'room';
window.location.hash = strp.join('/');
}),
navigation.on(cons.actions.navigation.OPEN_NAVIGATION, () => {
const h = window.location.hash.split('/');
h.length = 2;
window.location.hash = h.join('/');
}),
);
export function destructUrlHandling() {
listeners.forEach((l) => navigation.removeListener(l));
}