From 08ca779fe1819ea5a8c74e29854ed940a2e6deca Mon Sep 17 00:00:00 2001 From: Mikunj Date: Fri, 9 Nov 2018 14:27:49 +1100 Subject: [PATCH] Fixed up friend request message display --- _locales/en/messages.json | 33 +++++++++ js/models/conversations.js | 9 +-- js/models/messages.js | 23 ++++++- stylesheets/_modules.scss | 29 ++++++++ ts/components/conversation/FriendRequest.tsx | 71 +++++++++++++++----- 5 files changed, 141 insertions(+), 24 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 5f03599fa..2e0f1c161 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1577,5 +1577,38 @@ "example": "Alice, Bob" } } + }, + "friendRequestPending": { + "message": "$name$ sent you a friend request", + "description": + "Shown in the conversation history when the user recieves a friend request", + "placeholders": { + "name": { + "content": "$1", + "example": "Bob" + } + } + }, + "friendRequestAccepted": { + "message": "You accepted $name$'s friend request", + "description": + "Shown in the conversation history when the user accepts a friend request", + "placeholders": { + "name": { + "content": "$1", + "example": "Bob" + } + } + }, + "friendRequestDeclined": { + "message": "You declined $name$'s friend request", + "description": + "Shown in the conversation history when the user declines a friend request", + "placeholders": { + "name": { + "content": "$1", + "example": "Bob" + } + } } } diff --git a/js/models/conversations.js b/js/models/conversations.js index 6ffcc480b..09f993fcd 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -567,7 +567,7 @@ }, // This will add a message which will allow the user to reply to a friend request // TODO: Maybe add callbacks for accept and decline? - async addFriendRequest() { + async addFriendRequest(body, type = 'incoming') { if (this.isMe()) { window.log.info( 'refusing to send friend request to ourselves' @@ -591,10 +591,11 @@ sent_at: lastMessage, received_at: timestamp, unread: 1, - source: this.id, - target: this.ourNumber, + from: this.id, + to: this.ourNumber, status: 'pending', - type: 'incoming', + requestType: type, + body, }; const id = await window.Signal.Data.saveMessage(message, { diff --git a/js/models/messages.js b/js/models/messages.js index 6cb97cedf..d56f48b02 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -296,16 +296,35 @@ return {}; }, getPropsForFriendRequest() { - const source = this.get('source'); - const target = this.get('target'); + const source = this.get('from'); + const target = this.get('to'); const status = this.get('status') || 'pending'; const type = this.get('requestType') || 'incoming'; + //TODO: Not sure how we go about confirming and deleting message on server side + // I.e do we send a network request from the model? or call a function in the conversation to send the new status + const onAccept = async () => { + this.set({ status: 'accepted' }); + await window.Signal.Data.saveMessage(this.attributes, { + Message: Whisper.Message, + }); + }; + + const onDecline = async () => { + this.set({ status: 'declined' }); + await window.Signal.Data.saveMessage(this.attributes, { + Message: Whisper.Message, + }); + }; + return { + text: this.createNonBreakingLastSeparator(this.get('body')), source: this.findAndFormatContact(source), target: this.findAndFormatContact(target), status, type, + onAccept, + onDecline, } }, findContact(phoneNumber) { diff --git a/stylesheets/_modules.scss b/stylesheets/_modules.scss index 785991e37..07472eb0d 100644 --- a/stylesheets/_modules.scss +++ b/stylesheets/_modules.scss @@ -1023,6 +1023,35 @@ color: $color-white-07; } +// Module: Friend Request +.module-friend-request__buttonContainer { + margin-top: 8px; + justify-content: space-around; + border-top: 1px solid $color-white-07; + padding-top: 4px; +} + +.module-friend-request__buttonContainer button { + flex: 0.5; + padding: 8px; + background-color: transparent; + border: 0; + overflow: hidden; + outline:none; + color: $color-white; +} + +.module-friend-request__buttonContainer button:first-of-type { + border-right: 1px solid $color-white-07; +} + +.module-friend-request__text { + padding-top: 6px; + padding-bottom: 4px; + color: $color-white-08; +} + + // Module: Contact Detail .module-contact-detail { diff --git a/ts/components/conversation/FriendRequest.tsx b/ts/components/conversation/FriendRequest.tsx index 03dd58504..cf08c09b0 100644 --- a/ts/components/conversation/FriendRequest.tsx +++ b/ts/components/conversation/FriendRequest.tsx @@ -4,6 +4,7 @@ import React from 'react'; import { ContactName } from './ContactName'; import { Intl } from '../Intl'; import { Localizer } from '../../types/Util'; +import { MessageBody } from './MessageBody'; interface Contact { phoneNumber: string; @@ -12,61 +13,95 @@ interface Contact { } interface Props { + text?: string; type: 'incoming' | 'outgoing'; source: Contact; target: Contact; i18n: Localizer; status: 'pending' | 'accepted' | 'declined'; + onAccept: () => void; + onDecline: () => void; } export class FriendRequest extends React.Component { public getStringId() { const { status } = this.props; - return 'youMarkedAsNotVerified'; - switch (status) { case 'pending': return 'friendRequestPending'; case 'accepted': return 'friendRequestAccepted'; case 'declined': - return 'friendRequestDeclined' + return 'friendRequestDeclined'; default: - // throw missingCaseError(status); + throw new Error(`Invalid friend request status: ${status}`); } } + public renderText() { + const { text, i18n } = this.props; + + if (!text) { + return null; + } + + return ( +
+ +
+ ); + } + + public renderContents() { const { source, i18n } = this.props; const id = this.getStringId(); return ( - + , + ]} i18n={i18n} - key="external-1" - name={source.name} - profileName={source.profileName} - phoneNumber={source.phoneNumber} - module="module-friend-request__contact" - />, - ]} - i18n={i18n} - /> + /> + {this.renderText()} + + ); } + public renderButtons() { + const { onAccept, onDecline } = this.props; + return ( +
+ + +
+ ) + } + public render() { - const { type } = this.props; + const { type, status} = this.props; return (
{this.renderContents()} + {(status === 'pending') && this.renderButtons()}