From f45e0030c48b5484dc9f631dc212ed62b820727a Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 13 Nov 2018 10:30:36 +1100 Subject: [PATCH] Added status display and retry send to friend request. --- js/models/messages.js | 8 +-- ts/components/conversation/FriendRequest.tsx | 66 ++++++++++++++++---- 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/js/models/messages.js b/js/models/messages.js index 8870c3ff8..238b23ea7 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -295,8 +295,6 @@ return {}; }, getPropsForFriendRequest() { - const source = this.get('from'); - const target = this.get('to'); const friendStatus = this.get('friendStatus') || 'pending'; const direction = this.get('direction') || 'incoming'; const conversation = this.getConversation(); @@ -327,19 +325,19 @@ }; const onDelete = async () => { + // Delete the whole conversation window.Whisper.events.trigger('deleteConversation', conversation); }; return { text: this.createNonBreakingLastSeparator(this.get('body')), - source: this.findAndFormatContact(source), - target: this.findAndFormatContact(target), status: this.getMessagePropStatus(), direction, friendStatus, onAccept, onDecline, onDelete, + onRetrySend: () => this.retrySend(), } }, findContact(phoneNumber) { @@ -424,7 +422,7 @@ const isOutgoing = this.isOutgoing() || isOutgoingFriendRequest; // Only return the status on outgoing messages - if (!isOutgoing()) { + if (!isOutgoing) { return null; } diff --git a/ts/components/conversation/FriendRequest.tsx b/ts/components/conversation/FriendRequest.tsx index 8f7f07fe8..1f768e615 100644 --- a/ts/components/conversation/FriendRequest.tsx +++ b/ts/components/conversation/FriendRequest.tsx @@ -1,25 +1,19 @@ import React from 'react'; -// import classNames from 'classnames'; +import classNames from 'classnames'; import { Localizer } from '../../types/Util'; import { MessageBody } from './MessageBody'; -interface Contact { - phoneNumber: string; - profileName?: string; - name?: string; -} - interface Props { text?: string; direction: 'incoming' | 'outgoing'; - source: Contact; - target: Contact; + status: string; i18n: Localizer; friendStatus: 'pending' | 'accepted' | 'declined'; onAccept: () => void; onDecline: () => void; onDelete: () => void; + onRetrySend: () => void; } export class FriendRequest extends React.Component { @@ -56,7 +50,7 @@ export class FriendRequest extends React.Component { } public renderButtons() { - const { friendStatus, direction, onAccept, onDecline, onDelete } = this.props; + const { friendStatus, direction, status, onAccept, onDecline, onDelete, onRetrySend } = this.props; if (direction === 'incoming') { if (friendStatus === 'pending') { @@ -73,21 +67,71 @@ export class FriendRequest extends React.Component { ); } + } else { + // Render the retry button if we errored + if (status === 'error') { + return ( +
+ +
+ ); + } } return null; } + public renderError(isCorrectSide: boolean) { + const { status, direction } = this.props; + + if (!isCorrectSide || status !== 'error') { + return null; + } + + return ( +
+
+
+ ); + } + + // Renders 'sending', 'read' icons + public renderMetadata() { + const { direction, status } = this.props; + if (direction !== 'outgoing' || status === 'error') return null; + + return ( +
+ +
+
+ ); + } + public render() { const { direction } = this.props; - + + // const showRetry = status === 'error' && direction === 'outgoing'; return (
+ {this.renderError(direction === 'incoming')}
{this.renderContents()} + {this.renderMetadata()} {this.renderButtons()}
+ {this.renderError(direction === 'outgoing')}
); }