diff --git a/app/soapbox/actions/chats.js b/app/soapbox/actions/chats.js index a3e743c87..729dc128e 100644 --- a/app/soapbox/actions/chats.js +++ b/app/soapbox/actions/chats.js @@ -34,20 +34,20 @@ export function fetchChats() { }; } -export function fetchChatMessages(chatId) { +export function fetchChatMessages(chatId, maxId = null) { 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, chatMessages: data }); + dispatch({ type: CHAT_MESSAGES_FETCH_REQUEST, chatId, maxId }); + return api(getState).get(`/api/v1/pleroma/chats/${chatId}/messages`, { params: { max_id: maxId } }).then(({ data }) => { + dispatch({ type: CHAT_MESSAGES_FETCH_SUCCESS, chatId, maxId, chatMessages: data }); }).catch(error => { - dispatch({ type: CHAT_MESSAGES_FETCH_FAIL, chatId, error }); + dispatch({ type: CHAT_MESSAGES_FETCH_FAIL, chatId, maxId, error }); }); }; } export function sendChatMessage(chatId, params) { return (dispatch, getState) => { - const uuid = uuidv4(); + const uuid = `末_${Date.now()}_${uuidv4()}`; const me = getState().get('me'); dispatch({ type: CHAT_MESSAGE_SEND_REQUEST, chatId, params, uuid, me }); return api(getState).post(`/api/v1/pleroma/chats/${chatId}/messages`, params).then(({ data }) => { diff --git a/app/soapbox/features/chats/chat_room.js b/app/soapbox/features/chats/chat_room.js index 4a8c480ea..f3e81cc12 100644 --- a/app/soapbox/features/chats/chat_room.js +++ b/app/soapbox/features/chats/chat_room.js @@ -58,11 +58,11 @@ class ChatRoom extends ImmutablePureComponent { componentDidUpdate(prevProps) { const markReadConditions = [ - () => this.props.chat !== undefined, + () => this.props.chat, () => this.props.chat.get('unread') > 0, ]; - if (markReadConditions.every(c => c() === true)) + if (markReadConditions.every(c => c())) this.markRead(); } diff --git a/app/soapbox/features/chats/components/chat_box.js b/app/soapbox/features/chats/components/chat_box.js index 40123ca25..12b28d513 100644 --- a/app/soapbox/features/chats/components/chat_box.js +++ b/app/soapbox/features/chats/components/chat_box.js @@ -5,7 +5,6 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import { injectIntl, defineMessages } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { - fetchChatMessages, sendChatMessage, markChatRead, } from 'soapbox/actions/chats'; @@ -81,11 +80,6 @@ class ChatBox extends ImmutablePureComponent { onSetInputRef(el); }; - componentDidMount() { - const { dispatch, chatId } = this.props; - dispatch(fetchChatMessages(chatId)); - } - componentDidUpdate(prevProps) { const markReadConditions = [ () => this.props.chat !== undefined, @@ -98,12 +92,12 @@ class ChatBox extends ImmutablePureComponent { } render() { - const { chatMessageIds, intl } = this.props; + const { chatMessageIds, chatId, intl } = this.props; if (!chatMessageIds) return null; return (