fix: canonical

This commit is contained in:
cha0s 2020-12-11 08:57:12 -06:00
parent 389e4605c5
commit bc715ecc1e
3 changed files with 26 additions and 15 deletions

View File

@ -33,16 +33,21 @@ export default ({config: {'%socket': socket}}) => {
}, },
[submitJoin]: async ({dispatch}, {payload}) => { [submitJoin]: async ({dispatch}, {payload}) => {
const {channel} = payload; const {channel} = payload;
const {canonical, messages, users} = await socket.send(['Join', payload]); try {
const realChannel = canonical ? parseChannel(canonical) : channel; const {canonical, messages, users} = await socket.send(['Join', payload]);
dispatch(join({ const realChannel = canonical ? parseChannel(canonical) : channel;
channel: realChannel, dispatch(join({
messages, channel: realChannel,
users, messages,
})); users,
dispatch(addRecent(realChannel)); }));
if (canonical) { dispatch(addRecent(realChannel));
dispatch(push(`/chat${canonical}`)); if (canonical) {
dispatch(push(`/chat${canonical}`));
}
}
catch (error) {
dispatch(push('/chat'));
} }
}, },
[submitLeave]: async ({dispatch}, {payload}) => { [submitLeave]: async ({dispatch}, {payload}) => {

View File

@ -37,10 +37,15 @@ export default {
req.channel = channel; req.channel = channel;
if (validateChannel(channel)) { if (validateChannel(channel)) {
const rendered = renderChannel(channel); const rendered = renderChannel(channel);
const chat = await ensureCanonical(latus, channel); try {
if (chat.name !== rendered) { const chat = await ensureCanonical(latus, channel);
res.redirect(`/chat${chat.name}`); if (chat.name !== rendered) {
return; res.redirect(`/chat${chat.name}`);
return;
}
}
catch (error) {
res.redirect('/chat');
} }
} }
next(); next();

View File

@ -1,4 +1,5 @@
import {ModelMap} from '@latus/db'; import {ModelMap} from '@latus/db';
import {parseChannel} from '@reddichat/core';
import ensureCanonical from '../ensure-canonical'; import ensureCanonical from '../ensure-canonical';
import joinChannel from '../join-channel'; import joinChannel from '../join-channel';
@ -12,7 +13,7 @@ export default (latus) => class JoinServer extends Join(latus) {
const {req} = socket; const {req} = socket;
const {User} = ModelMap(latus); const {User} = ModelMap(latus);
const chat = await ensureCanonical(latus, channel); const chat = await ensureCanonical(latus, channel);
const canonical = {...channel, name: chat.name}; const canonical = parseChannel(chat.name);
await joinChannel(latus, canonical, socket); await joinChannel(latus, canonical, socket);
const state = await channelState(req, latus, canonical); const state = await channelState(req, latus, canonical);
const usernames = Object.fromEntries(await Promise.all( const usernames = Object.fromEntries(await Promise.all(