2022-05-30 09:18:31 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
|
|
|
|
import { markConversationRead } from 'soapbox/actions/conversations';
|
2022-11-15 08:13:54 -08:00
|
|
|
import StatusContainer from 'soapbox/containers/status-container';
|
2022-05-30 09:18:31 -07:00
|
|
|
import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
|
|
|
|
|
|
|
|
interface IConversation {
|
|
|
|
conversationId: string,
|
|
|
|
onMoveUp: (id: string) => void,
|
|
|
|
onMoveDown: (id: string) => void,
|
|
|
|
}
|
|
|
|
|
|
|
|
const Conversation: React.FC<IConversation> = ({ conversationId, onMoveUp, onMoveDown }) => {
|
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
const { accounts, unread, lastStatusId } = useAppSelector((state) => {
|
2022-06-21 15:29:17 -07:00
|
|
|
const conversation = state.conversations.items.find(x => x.id === conversationId)!;
|
2022-05-30 09:18:31 -07:00
|
|
|
|
|
|
|
return {
|
2022-06-21 15:29:17 -07:00
|
|
|
accounts: conversation.accounts.map((accountId: string) => state.accounts.get(accountId, null)!),
|
|
|
|
unread: conversation.unread,
|
|
|
|
lastStatusId: conversation.last_status || null,
|
2022-05-30 09:18:31 -07:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
const handleClick = () => {
|
|
|
|
if (unread) {
|
|
|
|
dispatch(markConversationRead(conversationId));
|
|
|
|
}
|
|
|
|
|
|
|
|
history.push(`/statuses/${lastStatusId}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleHotkeyMoveUp = () => {
|
|
|
|
onMoveUp(conversationId);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleHotkeyMoveDown = () => {
|
|
|
|
onMoveDown(conversationId);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (lastStatusId === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
// @ts-ignore
|
2022-06-02 12:00:35 -07:00
|
|
|
<StatusContainer
|
2022-05-30 09:18:31 -07:00
|
|
|
id={lastStatusId}
|
|
|
|
unread={unread}
|
|
|
|
otherAccounts={accounts}
|
|
|
|
onMoveUp={handleHotkeyMoveUp}
|
|
|
|
onMoveDown={handleHotkeyMoveDown}
|
|
|
|
onClick={handleClick}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Conversation;
|