fix: canonical
This commit is contained in:
parent
389e4605c5
commit
bc715ecc1e
25
packages/chat/src/client/effects.js
vendored
25
packages/chat/src/client/effects.js
vendored
|
@ -33,16 +33,21 @@ export default ({config: {'%socket': socket}}) => {
|
|||
},
|
||||
[submitJoin]: async ({dispatch}, {payload}) => {
|
||||
const {channel} = payload;
|
||||
const {canonical, messages, users} = await socket.send(['Join', payload]);
|
||||
const realChannel = canonical ? parseChannel(canonical) : channel;
|
||||
dispatch(join({
|
||||
channel: realChannel,
|
||||
messages,
|
||||
users,
|
||||
}));
|
||||
dispatch(addRecent(realChannel));
|
||||
if (canonical) {
|
||||
dispatch(push(`/chat${canonical}`));
|
||||
try {
|
||||
const {canonical, messages, users} = await socket.send(['Join', payload]);
|
||||
const realChannel = canonical ? parseChannel(canonical) : channel;
|
||||
dispatch(join({
|
||||
channel: realChannel,
|
||||
messages,
|
||||
users,
|
||||
}));
|
||||
dispatch(addRecent(realChannel));
|
||||
if (canonical) {
|
||||
dispatch(push(`/chat${canonical}`));
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
dispatch(push('/chat'));
|
||||
}
|
||||
},
|
||||
[submitLeave]: async ({dispatch}, {payload}) => {
|
||||
|
|
|
@ -37,10 +37,15 @@ export default {
|
|||
req.channel = channel;
|
||||
if (validateChannel(channel)) {
|
||||
const rendered = renderChannel(channel);
|
||||
const chat = await ensureCanonical(latus, channel);
|
||||
if (chat.name !== rendered) {
|
||||
res.redirect(`/chat${chat.name}`);
|
||||
return;
|
||||
try {
|
||||
const chat = await ensureCanonical(latus, channel);
|
||||
if (chat.name !== rendered) {
|
||||
res.redirect(`/chat${chat.name}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
res.redirect('/chat');
|
||||
}
|
||||
}
|
||||
next();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {ModelMap} from '@latus/db';
|
||||
import {parseChannel} from '@reddichat/core';
|
||||
|
||||
import ensureCanonical from '../ensure-canonical';
|
||||
import joinChannel from '../join-channel';
|
||||
|
@ -12,7 +13,7 @@ export default (latus) => class JoinServer extends Join(latus) {
|
|||
const {req} = socket;
|
||||
const {User} = ModelMap(latus);
|
||||
const chat = await ensureCanonical(latus, channel);
|
||||
const canonical = {...channel, name: chat.name};
|
||||
const canonical = parseChannel(chat.name);
|
||||
await joinChannel(latus, canonical, socket);
|
||||
const state = await channelState(req, latus, canonical);
|
||||
const usernames = Object.fromEntries(await Promise.all(
|
||||
|
|
Loading…
Reference in New Issue
Block a user