Chats: use semantic names for action properties
This commit is contained in:
parent
9a3aab27c9
commit
02b3b08999
6 changed files with 16 additions and 16 deletions
|
@ -22,7 +22,7 @@ export function fetchChats() {
|
|||
return (dispatch, getState) => {
|
||||
dispatch({ type: CHATS_FETCH_REQUEST });
|
||||
return api(getState).get('/api/v1/pleroma/chats').then(({ data }) => {
|
||||
dispatch({ type: CHATS_FETCH_SUCCESS, data });
|
||||
dispatch({ type: CHATS_FETCH_SUCCESS, chats: data });
|
||||
}).catch(error => {
|
||||
dispatch({ type: CHATS_FETCH_FAIL, error });
|
||||
});
|
||||
|
@ -33,7 +33,7 @@ export function fetchChatMessages(chatId) {
|
|||
return (dispatch, getState) => {
|
||||
dispatch({ type: CHAT_MESSAGES_FETCH_REQUEST, chatId });
|
||||
return api(getState).get(`/api/v1/pleroma/chats/${chatId}/messages`).then(({ data }) => {
|
||||
dispatch({ type: CHAT_MESSAGES_FETCH_SUCCESS, chatId, data });
|
||||
dispatch({ type: CHAT_MESSAGES_FETCH_SUCCESS, chatId, chatMessages: data });
|
||||
}).catch(error => {
|
||||
dispatch({ type: CHAT_MESSAGES_FETCH_FAIL, chatId, error });
|
||||
});
|
||||
|
@ -44,7 +44,7 @@ export function sendChatMessage(chatId, params) {
|
|||
return (dispatch, getState) => {
|
||||
dispatch({ type: CHAT_MESSAGE_SEND_REQUEST, chatId, params });
|
||||
return api(getState).post(`/api/v1/pleroma/chats/${chatId}/messages`, params).then(({ data }) => {
|
||||
dispatch({ type: CHAT_MESSAGE_SEND_SUCCESS, chatId, data });
|
||||
dispatch({ type: CHAT_MESSAGE_SEND_SUCCESS, chatId, chatMessage: data });
|
||||
}).catch(error => {
|
||||
dispatch({ type: CHAT_MESSAGE_SEND_FAIL, chatId, error });
|
||||
});
|
||||
|
|
|
@ -55,7 +55,7 @@ export function connectTimelineStream(timelineId, path, pollingRefresh = null, a
|
|||
dispatch(fetchFilters());
|
||||
break;
|
||||
case 'pleroma:chat_update':
|
||||
dispatch({ type: STREAMING_CHAT_UPDATE, payload: JSON.parse(data.payload) });
|
||||
dispatch({ type: STREAMING_CHAT_UPDATE, chat: JSON.parse(data.payload) });
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
|
|
@ -47,9 +47,9 @@ export default function accounts(state = initialState, action) {
|
|||
username: action.username,
|
||||
}));
|
||||
case CHATS_FETCH_SUCCESS:
|
||||
return importAccountsFromChats(state, action.data);
|
||||
return importAccountsFromChats(state, action.chats);
|
||||
case STREAMING_CHAT_UPDATE:
|
||||
return importAccountsFromChats(state, [action.payload]);
|
||||
return importAccountsFromChats(state, [action.chat]);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -31,13 +31,13 @@ const importLastMessages = (state, chats) =>
|
|||
export default function chatMessageLists(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case CHATS_FETCH_SUCCESS:
|
||||
return importLastMessages(state, action.data);
|
||||
return importLastMessages(state, action.chats);
|
||||
case STREAMING_CHAT_UPDATE:
|
||||
return importMessages(state, [action.payload.last_message]);
|
||||
return importMessages(state, [action.chat.last_message]);
|
||||
case CHAT_MESSAGES_FETCH_SUCCESS:
|
||||
return updateList(state, action.chatId, action.data.map(chat => chat.id).reverse());
|
||||
return updateList(state, action.chatId, action.chatMessages.map(chat => chat.id).reverse());
|
||||
case CHAT_MESSAGE_SEND_SUCCESS:
|
||||
return updateList(state, action.chatId, [action.data.id]);
|
||||
return updateList(state, action.chatId, [action.chatMessage.id]);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -23,13 +23,13 @@ const importLastMessages = (state, chats) =>
|
|||
export default function chatMessages(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case CHATS_FETCH_SUCCESS:
|
||||
return importLastMessages(state, fromJS(action.data));
|
||||
return importLastMessages(state, fromJS(action.chats));
|
||||
case CHAT_MESSAGES_FETCH_SUCCESS:
|
||||
return importMessages(state, fromJS(action.data));
|
||||
return importMessages(state, fromJS(action.chatMessages));
|
||||
case CHAT_MESSAGE_SEND_SUCCESS:
|
||||
return importMessage(state, fromJS(action.data));
|
||||
return importMessage(state, fromJS(action.chatMessage));
|
||||
case STREAMING_CHAT_UPDATE:
|
||||
return importLastMessages(state, fromJS([action.payload]));
|
||||
return importLastMessages(state, fromJS([action.chat]));
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -13,9 +13,9 @@ const initialState = ImmutableMap();
|
|||
export default function chats(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case CHATS_FETCH_SUCCESS:
|
||||
return importChats(state, action.data);
|
||||
return importChats(state, action.chats);
|
||||
case STREAMING_CHAT_UPDATE:
|
||||
return importChats(state, [action.payload]);
|
||||
return importChats(state, [action.chat]);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue