diff --git a/src/client/chat--submitMessage.jsx b/src/client/chat--submitMessage.jsx index d4086be..98aba06 100644 --- a/src/client/chat--submitMessage.jsx +++ b/src/client/chat--submitMessage.jsx @@ -25,7 +25,7 @@ export default function ChatSubmitMessage() { dispatch(submitMessage({ channel, message, - owner: 'r/anonymous' === channel ? user.id : 0, + owner: '/r/anonymous' === channel ? 0 : user.id, timestamp: Date.now(), uuid: uuidv4(), })); diff --git a/src/client/store/effects.js b/src/client/store/effects.js index 49412aa..8ec3340 100644 --- a/src/client/store/effects.js +++ b/src/client/store/effects.js @@ -19,8 +19,11 @@ import { import {socket} from '~/client/hooks/useSocket'; const effects = { - [join]: ({dispatch}, {payload: {users}}) => { - dispatch(fetchUsernames(users)); + [join]: ({dispatch}, {payload: {messages, users}}) => { + const ids = new Set(); + Object.values(messages).map((message) => message.owner).forEach((id) => ids.add(id)); + users.forEach((id) => ids.add(id)); + dispatch(fetchUsernames(Array.from(ids.keys()))); }, [joined]: ({dispatch}, {payload: {id}}) => { dispatch(fetchUsernames([id])); diff --git a/src/server/entry.js b/src/server/entry.js index 11a8f7a..977bc11 100644 --- a/src/server/entry.js +++ b/src/server/entry.js @@ -75,11 +75,13 @@ const chatUsers = async (req) => { const entries = await Promise.all( toHydrate.map((channel) => channelState(req, joinChannel(channel))), ); - const chatUsers = []; + const chatUsers = new Set(); for (let i = 0; i < toHydrate.length; i++) { - chatUsers.push(...entries[i].users); + const {messages, users} = entries[i]; + Object.values(messages).map((message) => message.owner).forEach((id) => chatUsers.add(id)); + users.forEach((id) => chatUsers.add(id)); } - return chatUsers; + return Array.from(chatUsers.keys()); }; export const appChatState = async (req) => {