From 435e193c93822ca3d8c050b0a43829cc48e85e38 Mon Sep 17 00:00:00 2001 From: Alan Friedman Date: Mon, 27 May 2019 16:06:01 -0400 Subject: [PATCH] Rename actions and functions --- client/src/actions/room.js | 16 ++++------- client/src/components/Chat/Chat.test.js | 4 +-- client/src/components/Chat/index.js | 12 ++++---- client/src/components/FileTransfer/index.js | 4 +-- client/src/components/Home/index.js | 18 +++++------- client/src/containers/Chat/index.js | 4 +-- client/src/containers/Home/index.js | 10 +++---- client/src/reducers/activities.js | 28 +++++++++---------- client/src/reducers/app.js | 2 +- client/src/reducers/room.js | 31 +++++++-------------- client/src/reducers/user.js | 2 +- client/src/stylesheets/app.sass | 2 +- server/src/socket.js | 12 ++++---- 13 files changed, 61 insertions(+), 84 deletions(-) diff --git a/client/src/actions/room.js b/client/src/actions/room.js index 83b0d96..48e076c 100644 --- a/client/src/actions/room.js +++ b/client/src/actions/room.js @@ -6,11 +6,11 @@ import { } from 'utils/message' import { getSocket } from 'utils/socket' -export const receiveSocketMessage = payload => async (dispatch, getState) => { +export const receiveEncryptedMessage = payload => async (dispatch, getState) => { const state = getState() const message = await processMessage(payload, state) - // Pass current state to all HANDLE_SOCKET_MESSAGE reducers for convenience, since each may have different needs - dispatch({ type: `HANDLE_SOCKET_MESSAGE_${message.type}`, payload: { payload: message.payload, state } }) + // Pass current state to all RECEIVE_ENCRYPTED_MESSAGE reducers for convenience, since each may have different needs + dispatch({ type: `RECEIVE_ENCRYPTED_MESSAGE_${message.type}`, payload: { payload: message.payload, state } }) } export const createUser = payload => async (dispatch) => { @@ -52,11 +52,11 @@ export const onFileTransfer = payload => async (dispatch) => { dispatch({ type: 'PREFLIGHT_FILE_TRANSFER', payload }) } -export const sendSocketMessage = payload => async (dispatch, getState) => { +export const sendEncryptedMessage = payload => async (dispatch, getState) => { const state = getState() const msg = await prepareMessage(payload, state) - dispatch({ type: `SEND_SOCKET_MESSAGE_${msg.original.type}`, payload: msg.original.payload }) - getSocket().emit('PAYLOAD', msg.toSend) + dispatch({ type: `SEND_ENCRYPTED_MESSAGE_${msg.original.type}`, payload: msg.original.payload }) + getSocket().emit('ENCRYPTED_MESSAGE', msg.toSend) } export const toggleLockRoom = () => async (dispatch, getState) => { @@ -94,10 +94,6 @@ export const clearActivities = () => async (dispatch) => { dispatch({ type: 'CLEAR_ACTIVITIES' }) } -export const onConnected = payload => async (dispatch) => { - dispatch({ type: 'CONNECTED', payload }) -} - export const sendUserDisconnect = () => async () => { getSocket().emit('USER_DISCONNECT') } diff --git a/client/src/components/Chat/Chat.test.js b/client/src/components/Chat/Chat.test.js index a33de83..a1b6235 100644 --- a/client/src/components/Chat/Chat.test.js +++ b/client/src/components/Chat/Chat.test.js @@ -3,11 +3,11 @@ import { mount } from 'enzyme' import toJson from 'enzyme-to-json' import { Chat } from './index.js' -const sendSocketMessage = jest.fn() +const sendEncryptedMessage = jest.fn() test('Chat Component', () => { const component = mount( - {}} focusChat={false} userId="foo" username="user" showNotice={() => {}} clearActivities={() => {}} sendSocketMessage={sendSocketMessage} /> + {}} focusChat={false} userId="foo" username="user" showNotice={() => {}} clearActivities={() => {}} sendEncryptedMessage={sendEncryptedMessage} /> ) const componentJSON = toJson(component) diff --git a/client/src/components/Chat/index.js b/client/src/components/Chat/index.js index f2ba71d..1148fe0 100644 --- a/client/src/components/Chat/index.js +++ b/client/src/components/Chat/index.js @@ -51,7 +51,7 @@ export class Chat extends Component { }) } - this.props.sendSocketMessage({ + this.props.sendEncryptedMessage({ type: 'CHANGE_USERNAME', payload: { id: this.props.userId, @@ -85,7 +85,7 @@ export class Chat extends Component { return false } - this.props.sendSocketMessage({ + this.props.sendEncryptedMessage({ type: 'USER_ACTION', payload: { action: actionMessage, @@ -216,8 +216,8 @@ export class Chat extends Component { return } } else { - this.props.sendSocketMessage({ - type: 'SEND_MESSAGE', + this.props.sendEncryptedMessage({ + type: 'TEXT_MESSAGE', payload: { text: message, timestamp: Date.now(), @@ -256,7 +256,7 @@ export class Chat extends Component { placeholder="Type here" onChange={this.handleInputChange.bind(this)} />
- + {touchSupport &&