Chats: make streaming mostly work
This commit is contained in:
parent
c0dc4a69cd
commit
dbafbbc065
2 changed files with 27 additions and 3 deletions
|
@ -9,6 +9,7 @@ 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';
|
||||
|
||||
|
@ -52,6 +53,9 @@ export function connectTimelineStream(timelineId, path, pollingRefresh = null, a
|
|||
case 'filters_changed':
|
||||
dispatch(fetchFilters());
|
||||
break;
|
||||
case 'pleroma:chat_update':
|
||||
dispatch(importFetchedChat(JSON.parse(data.payload)));
|
||||
break;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -2,16 +2,36 @@ import {
|
|||
CHAT_MESSAGES_FETCH_SUCCESS,
|
||||
CHAT_MESSAGE_SEND_SUCCESS,
|
||||
} from 'soapbox/actions/chats';
|
||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||
import { CHAT_IMPORT, CHATS_IMPORT } from 'soapbox/actions/importer';
|
||||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
||||
|
||||
const initialState = ImmutableMap();
|
||||
|
||||
const insertMessage = (state, chatId, message) => {
|
||||
const newMessages = state.get(chatId, ImmutableList()).insert(0, message);
|
||||
return state.set(chatId, newMessages);
|
||||
};
|
||||
|
||||
const importMessage = (state, message) => {
|
||||
const chatId = message.get('chat_id');
|
||||
return insertMessage(state, chatId, message);
|
||||
};
|
||||
|
||||
const importLastMessages = (state, chats) =>
|
||||
state.withMutations(mutable =>
|
||||
chats.forEach(chat => importMessage(mutable, chat.get('last_message'))));
|
||||
|
||||
export default function chatMessages(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case CHAT_IMPORT:
|
||||
return importMessage(state, fromJS(action.chat.last_message));
|
||||
case CHATS_IMPORT:
|
||||
return importLastMessages(state, fromJS(action.chats));
|
||||
case CHAT_MESSAGES_FETCH_SUCCESS:
|
||||
return state.set(action.chatId, fromJS(action.data));
|
||||
case CHAT_MESSAGE_SEND_SUCCESS:
|
||||
return state.set(action.chatId, state.get(action.chatId).insert(0, fromJS(action.data)));
|
||||
// TODO: Prevent conflicts
|
||||
// case CHAT_MESSAGE_SEND_SUCCESS:
|
||||
// return insertMessage(state, action.chatId, fromJS(action.data));
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue