Chats: get streaming working again

This commit is contained in:
Alex Gleason 2020-08-26 17:29:22 -05:00
parent 4b173f0580
commit b9d7f927a6
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
4 changed files with 13 additions and 8 deletions

View file

@ -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;
}

View file

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

View file

@ -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:

View file

@ -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;
}