From 8877a7658a9144377e58997c126bbfccef159cf7 Mon Sep 17 00:00:00 2001 From: HF Date: Wed, 29 Apr 2020 17:55:44 +0200 Subject: [PATCH 1/3] add chat channels --- src/actions/index.js | 9 ++++++ src/actions/types.js | 5 ++- src/client.js | 4 +-- src/components/Chat.jsx | 18 +++++------ src/components/ChatInput.jsx | 46 ++++++++++++++++++++++----- src/core/ChatProvider.js | 60 ++++++++++++++++++++++------------- src/core/constants.js | 3 ++ src/reducers/gui.js | 9 ++++++ src/reducers/user.js | 24 +++++++++++--- src/socket/APISocketServer.js | 21 ++++++++---- src/socket/ProtocolClient.js | 12 ++++--- src/socket/SocketServer.js | 44 +++++++++++++++++++++---- src/socket/WebSocketEvents.js | 2 +- src/socket/websockets.js | 5 +-- src/store/audio.js | 6 ++++ 15 files changed, 198 insertions(+), 70 deletions(-) diff --git a/src/actions/index.js b/src/actions/index.js index 622a8ea..1253846 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -189,12 +189,14 @@ export function receiveChatMessage( name: string, text: string, country: string, + channel: number, ): Action { return { type: 'RECEIVE_CHAT_MESSAGE', name, text, country, + channel, }; } @@ -620,6 +622,13 @@ export function showChatModal(): Action { return showModal('CHAT'); } +export function setChatChannel(channelId: number): Action { + return { + type: 'SET_CHAT_CHANNEL', + channelId, + }; +} + export function hideModal(): Action { return { type: 'HIDE_MODAL', diff --git a/src/actions/types.js b/src/actions/types.js index 26f2bcc..9975f45 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -56,8 +56,11 @@ export type Action = | { type: 'RECEIVE_CHAT_MESSAGE', name: string, text: string, - country: string } + country: string, + channel: number, + } | { type: 'RECEIVE_CHAT_HISTORY', data: Array } + | { type: 'SET_CHAT_CHANNEL', channelId: number } | { type: 'RECEIVE_ME', name: string, waitSeconds: number, diff --git a/src/client.js b/src/client.js index 4fe2ea2..772ee50 100644 --- a/src/client.js +++ b/src/client.js @@ -43,8 +43,8 @@ function init() { ProtocolClient.on('onlineCounter', ({ online }) => { store.dispatch(receiveOnline(online)); }); - ProtocolClient.on('chatMessage', (name, text, country) => { - store.dispatch(receiveChatMessage(name, text, country)); + ProtocolClient.on('chatMessage', (name, text, country, channelId) => { + store.dispatch(receiveChatMessage(name, text, country, channelId)); }); ProtocolClient.on('chatHistory', (data) => { store.dispatch(receiveChatHistory(data)); diff --git a/src/components/Chat.jsx b/src/components/Chat.jsx index 4feb0f2..ac6650d 100644 --- a/src/components/Chat.jsx +++ b/src/components/Chat.jsx @@ -12,13 +12,7 @@ import ChatInput from './ChatInput'; import { colorFromText, splitCoordsInString } from '../core/utils'; -function onError() { - this.onerror = null; - this.src = './cf/xx.gif'; -} - - -const Chat = ({ chatMessages }) => { +const Chat = ({ chatMessages, chatChannel }) => { const listRef = useRef(); const { stayScrolled } = useStayScrolled(listRef, { initialScroll: Infinity, @@ -32,7 +26,7 @@ const Chat = ({ chatMessages }) => {