import React from 'react'; import classNames from 'classnames'; import { LocalizerType } from '../../types/Util'; import { MessageBody } from './MessageBody'; import { Timestamp } from './Timestamp'; interface Props { text: string; direction: 'incoming' | 'outgoing'; status: string; friendStatus: 'pending' | 'accepted' | 'declined' | 'expired'; i18n: LocalizerType; isBlocked: boolean; timestamp: number; onAccept: () => void; onDecline: () => void; onDeleteConversation: () => void; onRetrySend: () => void; onBlockUser: () => void; onUnblockUser: () => void; } export class FriendRequest extends React.Component { public getStringId() { const { friendStatus } = this.props; switch (friendStatus) { case 'pending': return 'friendRequestPending'; case 'accepted': return 'friendRequestAccepted'; case 'declined': return 'friendRequestDeclined'; case 'expired': return 'friendRequestExpired'; default: throw new Error(`Invalid friend request status: ${friendStatus}`); } } public renderContents() { const { direction, i18n, text } = this.props; const id = this.getStringId(); return (
{i18n(id)}
); } public renderButtons() { const { i18n, friendStatus, direction, status, onAccept, onDecline, onDeleteConversation, onRetrySend, isBlocked, onBlockUser, onUnblockUser, } = this.props; if (direction === 'incoming') { if (friendStatus === 'pending') { return (
); } else if (friendStatus === 'declined') { const blockTitle = isBlocked ? i18n('unblockUser') : i18n('blockUser'); const blockHandler = isBlocked ? onUnblockUser : onBlockUser; return (
); } } else { // Render the retry button if we errored if (status === 'error' && friendStatus === 'pending') { return (
); } } return null; } public renderError(isCorrectSide: boolean) { const { status, direction } = this.props; if (!isCorrectSide || status !== 'error') { return null; } return (
); } // Renders 'sending', 'read' icons public renderStatusIndicator() { const { direction, status, i18n, text, timestamp } = this.props; if (status === 'error') { return null; } const withImageNoCaption = Boolean(!text); return (
); } public render() { const { direction } = this.props; return (
{this.renderError(direction === 'incoming')}
{this.renderContents()} {this.renderStatusIndicator()} {this.renderButtons()}
{this.renderError(direction === 'outgoing')}
); } }