From 8beeef4d10b1234375e5715f3af8fa104a5ecee1 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Mon, 7 May 2018 15:44:19 -0700 Subject: [PATCH] Show contact name when you reply to message with a contact --- js/models/conversations.js | 10 +++++++++- ts/components/conversation/EmbeddedContact.tsx | 9 ++------- ts/types/Contact.ts | 5 +++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index ace96f3d8d..6741f012e3 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -711,13 +711,21 @@ }, async makeQuote(quotedMessage) { + const { getName } = Signal.Types.Contact; const contact = quotedMessage.getContact(); const attachments = quotedMessage.get('attachments'); + const body = quotedMessage.get('body'); + const embeddedContact = quotedMessage.get('contact'); + const embeddedContactName = + embeddedContact && embeddedContact.length > 0 + ? getName(embeddedContact[0]) + : ''; + return { author: contact.id, id: quotedMessage.get('sent_at'), - text: quotedMessage.get('body'), + text: body || embeddedContactName, attachments: await Promise.all( (attachments || []).map(async attachment => { const { contentType } = attachment; diff --git a/ts/components/conversation/EmbeddedContact.tsx b/ts/components/conversation/EmbeddedContact.tsx index 7c3736088c..370423d6b3 100644 --- a/ts/components/conversation/EmbeddedContact.tsx +++ b/ts/components/conversation/EmbeddedContact.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Contact } from '../../types/Contact'; +import { Contact, getName } from '../../types/Contact'; interface Props { contact: Contact; @@ -13,11 +13,6 @@ function getInitials(name: string): string { return name.trim()[0] || '#'; } -function getName(contact: Contact): string { - const { name, organization } = contact; - return (name && name.displayName) || organization || ''; -} - export class EmbeddedContact extends React.Component { public renderAvatar() { const { contact } = this.props; @@ -26,7 +21,7 @@ export class EmbeddedContact extends React.Component { const path = avatar && avatar.avatar && avatar.avatar.path; if (!path) { const name = getName(contact); - const initials = getInitials(name); + const initials = getInitials(name || ''); return (
{initials}
diff --git a/ts/types/Contact.ts b/ts/types/Contact.ts index 114e32fc17..1592125846 100644 --- a/ts/types/Contact.ts +++ b/ts/types/Contact.ts @@ -97,3 +97,8 @@ export function contactSelector( })), }); } + +export function getName(contact: Contact): string | null { + const { name, organization } = contact; + return (name && name.displayName) || organization || null; +}