From 9547a7042dfa3f641a1defb9f89aa123e6d6cead Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 10 Mar 2022 21:09:12 -0600 Subject: [PATCH] Normalize chat in reducer, not action --- app/soapbox/actions/importer/normalizer.js | 10 ---------- app/soapbox/reducers/chats.js | 11 ++++++++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/soapbox/actions/importer/normalizer.js b/app/soapbox/actions/importer/normalizer.js index a294f4680..d61932957 100644 --- a/app/soapbox/actions/importer/normalizer.js +++ b/app/soapbox/actions/importer/normalizer.js @@ -40,13 +40,3 @@ export function normalizeAccount(account) { return account; } - -export function normalizeChat(chat, normalOldChat) { - const normalChat = { ...chat }; - const { account, last_message: lastMessage } = chat; - - if (account) normalChat.account = account.id; - if (lastMessage) normalChat.last_message = lastMessage.id; - - return normalChat; -} diff --git a/app/soapbox/reducers/chats.js b/app/soapbox/reducers/chats.js index 85447adc0..430251210 100644 --- a/app/soapbox/reducers/chats.js +++ b/app/soapbox/reducers/chats.js @@ -9,9 +9,18 @@ import { CHAT_READ_SUCCESS, CHAT_READ_REQUEST, } from 'soapbox/actions/chats'; -import { normalizeChat } from 'soapbox/actions/importer/normalizer'; import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming'; +const normalizeChat = (chat, normalOldChat) => { + const normalChat = { ...chat }; + const { account, last_message: lastMessage } = chat; + + if (account) normalChat.account = account.id; + if (lastMessage) normalChat.last_message = lastMessage.id; + + return normalChat; +}; + const importChat = (state, chat) => state.setIn(['items', chat.id], fromJS(normalizeChat(chat))); const importChats = (state, chats, next) =>