Chats: use semantic names for action properties

loading-indicator-on-tls^2
Alex Gleason 2020-08-26 19:53:54 -05:00
rodzic 9a3aab27c9
commit 02b3b08999
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
6 zmienionych plików z 16 dodań i 16 usunięć

Wyświetl plik

@ -22,7 +22,7 @@ export function fetchChats() {
return (dispatch, getState) => { return (dispatch, getState) => {
dispatch({ type: CHATS_FETCH_REQUEST }); dispatch({ type: CHATS_FETCH_REQUEST });
return api(getState).get('/api/v1/pleroma/chats').then(({ data }) => { 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 => { }).catch(error => {
dispatch({ type: CHATS_FETCH_FAIL, error }); dispatch({ type: CHATS_FETCH_FAIL, error });
}); });
@ -33,7 +33,7 @@ export function fetchChatMessages(chatId) {
return (dispatch, getState) => { return (dispatch, getState) => {
dispatch({ type: CHAT_MESSAGES_FETCH_REQUEST, chatId }); dispatch({ type: CHAT_MESSAGES_FETCH_REQUEST, chatId });
return api(getState).get(`/api/v1/pleroma/chats/${chatId}/messages`).then(({ data }) => { 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 => { }).catch(error => {
dispatch({ type: CHAT_MESSAGES_FETCH_FAIL, chatId, error }); dispatch({ type: CHAT_MESSAGES_FETCH_FAIL, chatId, error });
}); });
@ -44,7 +44,7 @@ export function sendChatMessage(chatId, params) {
return (dispatch, getState) => { return (dispatch, getState) => {
dispatch({ type: CHAT_MESSAGE_SEND_REQUEST, chatId, params }); dispatch({ type: CHAT_MESSAGE_SEND_REQUEST, chatId, params });
return api(getState).post(`/api/v1/pleroma/chats/${chatId}/messages`, params).then(({ data }) => { 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 => { }).catch(error => {
dispatch({ type: CHAT_MESSAGE_SEND_FAIL, chatId, error }); dispatch({ type: CHAT_MESSAGE_SEND_FAIL, chatId, error });
}); });

Wyświetl plik

@ -55,7 +55,7 @@ export function connectTimelineStream(timelineId, path, pollingRefresh = null, a
dispatch(fetchFilters()); dispatch(fetchFilters());
break; break;
case 'pleroma:chat_update': 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; break;
} }
}, },

Wyświetl plik

@ -47,9 +47,9 @@ export default function accounts(state = initialState, action) {
username: action.username, username: action.username,
})); }));
case CHATS_FETCH_SUCCESS: case CHATS_FETCH_SUCCESS:
return importAccountsFromChats(state, action.data); return importAccountsFromChats(state, action.chats);
case STREAMING_CHAT_UPDATE: case STREAMING_CHAT_UPDATE:
return importAccountsFromChats(state, [action.payload]); return importAccountsFromChats(state, [action.chat]);
default: default:
return state; return state;
} }

Wyświetl plik

@ -31,13 +31,13 @@ const importLastMessages = (state, chats) =>
export default function chatMessageLists(state = initialState, action) { export default function chatMessageLists(state = initialState, action) {
switch(action.type) { switch(action.type) {
case CHATS_FETCH_SUCCESS: case CHATS_FETCH_SUCCESS:
return importLastMessages(state, action.data); return importLastMessages(state, action.chats);
case STREAMING_CHAT_UPDATE: case STREAMING_CHAT_UPDATE:
return importMessages(state, [action.payload.last_message]); return importMessages(state, [action.chat.last_message]);
case CHAT_MESSAGES_FETCH_SUCCESS: 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: case CHAT_MESSAGE_SEND_SUCCESS:
return updateList(state, action.chatId, [action.data.id]); return updateList(state, action.chatId, [action.chatMessage.id]);
default: default:
return state; return state;
} }

Wyświetl plik

@ -23,13 +23,13 @@ const importLastMessages = (state, chats) =>
export default function chatMessages(state = initialState, action) { export default function chatMessages(state = initialState, action) {
switch(action.type) { switch(action.type) {
case CHATS_FETCH_SUCCESS: case CHATS_FETCH_SUCCESS:
return importLastMessages(state, fromJS(action.data)); return importLastMessages(state, fromJS(action.chats));
case CHAT_MESSAGES_FETCH_SUCCESS: case CHAT_MESSAGES_FETCH_SUCCESS:
return importMessages(state, fromJS(action.data)); return importMessages(state, fromJS(action.chatMessages));
case CHAT_MESSAGE_SEND_SUCCESS: case CHAT_MESSAGE_SEND_SUCCESS:
return importMessage(state, fromJS(action.data)); return importMessage(state, fromJS(action.chatMessage));
case STREAMING_CHAT_UPDATE: case STREAMING_CHAT_UPDATE:
return importLastMessages(state, fromJS([action.payload])); return importLastMessages(state, fromJS([action.chat]));
default: default:
return state; return state;
} }

Wyświetl plik

@ -13,9 +13,9 @@ const initialState = ImmutableMap();
export default function chats(state = initialState, action) { export default function chats(state = initialState, action) {
switch(action.type) { switch(action.type) {
case CHATS_FETCH_SUCCESS: case CHATS_FETCH_SUCCESS:
return importChats(state, action.data); return importChats(state, action.chats);
case STREAMING_CHAT_UPDATE: case STREAMING_CHAT_UPDATE:
return importChats(state, [action.payload]); return importChats(state, [action.chat]);
default: default:
return state; return state;
} }