From b9d7f927a6771a63ebad92713941e487274f06ec Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 26 Aug 2020 17:29:22 -0500 Subject: [PATCH] Chats: get streaming working again --- app/soapbox/actions/importer/normalizer.js | 1 + app/soapbox/actions/streaming.js | 5 +++-- app/soapbox/reducers/chat_message_lists.js | 6 +++--- app/soapbox/reducers/chat_messages.js | 9 ++++++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/soapbox/actions/importer/normalizer.js b/app/soapbox/actions/importer/normalizer.js index 697e72107..c867e52e1 100644 --- a/app/soapbox/actions/importer/normalizer.js +++ b/app/soapbox/actions/importer/normalizer.js @@ -85,6 +85,7 @@ export function normalizeChat(chat, normalOldChat) { const normalChat = { ...chat }; normalChat.account = chat.account.id; + normalChat.last_message = chat.last_message.id; return normalChat; } diff --git a/app/soapbox/actions/streaming.js b/app/soapbox/actions/streaming.js index 2b7836666..8c6a1651d 100644 --- a/app/soapbox/actions/streaming.js +++ b/app/soapbox/actions/streaming.js @@ -9,10 +9,11 @@ import { import { updateNotificationsQueue, expandNotifications } from './notifications'; import { updateConversations } from './conversations'; import { fetchFilters } from './filters'; -import { importFetchedChat } from './importer'; import { getSettings } from 'soapbox/actions/settings'; import messages from 'soapbox/locales/messages'; +export const STREAMING_CHAT_UPDATE = 'STREAMING_CHAT_UPDATE'; + const validLocale = locale => Object.keys(messages).includes(locale); const getLocale = state => { @@ -54,7 +55,7 @@ export function connectTimelineStream(timelineId, path, pollingRefresh = null, a dispatch(fetchFilters()); break; case 'pleroma:chat_update': - dispatch(importFetchedChat(JSON.parse(data.payload))); + dispatch({ type: STREAMING_CHAT_UPDATE, payload: JSON.parse(data.payload) }); break; } }, diff --git a/app/soapbox/reducers/chat_message_lists.js b/app/soapbox/reducers/chat_message_lists.js index d13f02ef3..e19ee2bdd 100644 --- a/app/soapbox/reducers/chat_message_lists.js +++ b/app/soapbox/reducers/chat_message_lists.js @@ -2,7 +2,7 @@ import { CHAT_MESSAGES_FETCH_SUCCESS, CHAT_MESSAGE_SEND_SUCCESS, } from 'soapbox/actions/chats'; -import { CHAT_MESSAGES_IMPORT } from 'soapbox/actions/importer'; +import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming'; import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable'; const initialState = ImmutableMap(); @@ -25,8 +25,8 @@ const importMessages = (state, chatMessages) => ( export default function chatMessageLists(state = initialState, action) { switch(action.type) { - case CHAT_MESSAGES_IMPORT: - return importMessages(state, action.chatMessages); + case STREAMING_CHAT_UPDATE: + return importMessages(state, [action.payload.last_message]); case CHAT_MESSAGES_FETCH_SUCCESS: return updateList(state, action.chatId, action.data.map(chat => chat.id).reverse()); case CHAT_MESSAGE_SEND_SUCCESS: diff --git a/app/soapbox/reducers/chat_messages.js b/app/soapbox/reducers/chat_messages.js index d7f9b3c29..96ff24c8d 100644 --- a/app/soapbox/reducers/chat_messages.js +++ b/app/soapbox/reducers/chat_messages.js @@ -1,8 +1,9 @@ import { + CHATS_FETCH_SUCCESS, CHAT_MESSAGES_FETCH_SUCCESS, CHAT_MESSAGE_SEND_SUCCESS, } from 'soapbox/actions/chats'; -import { CHATS_IMPORT } from 'soapbox/actions/importer'; +import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming'; import { Map as ImmutableMap, fromJS } from 'immutable'; const initialState = ImmutableMap(); @@ -21,12 +22,14 @@ const importLastMessages = (state, chats) => export default function chatMessages(state = initialState, action) { switch(action.type) { - case CHATS_IMPORT: - return importLastMessages(state, fromJS(action.chats)); + case CHATS_FETCH_SUCCESS: + return importLastMessages(state, fromJS(action.data)); case CHAT_MESSAGES_FETCH_SUCCESS: return importMessages(state, fromJS(action.data)); case CHAT_MESSAGE_SEND_SUCCESS: return importMessage(state, fromJS(action.data)); + case STREAMING_CHAT_UPDATE: + return importLastMessages(state, fromJS([action.payload])); default: return state; }