fix: usernames

This commit is contained in:
cha0s 2020-07-18 18:42:33 -05:00
parent 7d342d4383
commit 9d52d98e8a
3 changed files with 11 additions and 6 deletions

View File

@ -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(),
}));

View File

@ -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]));

View File

@ -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) => {