Chats: handle null last_message
This commit is contained in:
parent
02b3b08999
commit
c4aae14148
4 changed files with 15 additions and 5 deletions
|
@ -83,9 +83,10 @@ export function normalizePoll(poll) {
|
|||
|
||||
export function normalizeChat(chat, normalOldChat) {
|
||||
const normalChat = { ...chat };
|
||||
const { account, last_message: lastMessage } = chat;
|
||||
|
||||
normalChat.account = chat.account.id;
|
||||
normalChat.last_message = chat.last_message.id;
|
||||
if (account) normalChat.account = account.id;
|
||||
if (lastMessage) normalChat.last_message = lastMessage.id;
|
||||
|
||||
return normalChat;
|
||||
}
|
||||
|
|
|
@ -100,6 +100,7 @@ export default class Header extends ImmutablePureComponent {
|
|||
onBlock={this.handleBlock}
|
||||
onMention={this.handleMention}
|
||||
onDirect={this.handleDirect}
|
||||
onMessage={this.handleMessage}
|
||||
onReblogToggle={this.handleReblogToggle}
|
||||
onReport={this.handleReport}
|
||||
onMute={this.handleMute}
|
||||
|
|
|
@ -26,14 +26,19 @@ const importMessages = (state, chatMessages) => (
|
|||
|
||||
const importLastMessages = (state, chats) =>
|
||||
state.withMutations(mutable =>
|
||||
chats.forEach(chat => importMessage(mutable, chat.last_message)));
|
||||
chats.forEach(chat => {
|
||||
if (chat.last_message) importMessage(mutable, chat.last_message);
|
||||
}));
|
||||
|
||||
export default function chatMessageLists(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case CHATS_FETCH_SUCCESS:
|
||||
return importLastMessages(state, action.chats);
|
||||
case STREAMING_CHAT_UPDATE:
|
||||
if (action.chat.last_message)
|
||||
return importMessages(state, [action.chat.last_message]);
|
||||
else
|
||||
return state;
|
||||
case CHAT_MESSAGES_FETCH_SUCCESS:
|
||||
return updateList(state, action.chatId, action.chatMessages.map(chat => chat.id).reverse());
|
||||
case CHAT_MESSAGE_SEND_SUCCESS:
|
||||
|
|
|
@ -18,7 +18,10 @@ const importMessages = (state, messages) =>
|
|||
|
||||
const importLastMessages = (state, chats) =>
|
||||
state.withMutations(mutable =>
|
||||
chats.forEach(chat => importMessage(mutable, chat.get('last_message'))));
|
||||
chats.forEach(chat => {
|
||||
if (chat.get('last_message'))
|
||||
importMessage(mutable, chat.get('last_message'));
|
||||
}));
|
||||
|
||||
export default function chatMessages(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
|
|
Loading…
Reference in a new issue