refactor: simplify

This commit is contained in:
cha0s 2020-12-14 13:52:52 -06:00
parent adba33448b
commit 55f8b77a98

View File

@ -8,13 +8,16 @@ export default async (latus, channel, socket) => {
if (!isAnonymous && !req.userId) {
return;
}
const [id, username] = isAnonymous
? [0, 'anonymous']
: [req.user.id, req.user.redditUsername];
const users = await channelUsers(req, channel);
const rendered = renderChannel(channel);
if (-1 === users.indexOf(id)) {
socket.to(rendered).send(['Join', {channel, id, username}]);
if (!isAnonymous) {
const users = await channelUsers(req, channel);
if (-1 === users.indexOf(req.user.id)) {
socket.to(rendered).send(['Join', {
channel,
id: req.user.id,
username: req.user.redditUsername,
}]);
}
}
await socket.join(rendered);
};