Fix replies to image-only messages

This commit is contained in:
Evan Hahn 2021-04-02 16:35:28 -05:00 committed by Josh Perez
parent b95dd207ca
commit 2d35fa8f57
2 changed files with 59 additions and 33 deletions

View file

@ -115,7 +115,7 @@ export type PropsData = {
attachments?: Array<AttachmentType>; attachments?: Array<AttachmentType>;
quote?: { quote?: {
text: string; text: string;
attachment?: QuotedAttachmentType; rawAttachment?: QuotedAttachmentType;
isFromMe: boolean; isFromMe: boolean;
sentAt: number; sentAt: number;
authorId: string; authorId: string;
@ -1030,7 +1030,7 @@ export class Message extends React.PureComponent<Props, State> {
i18n={i18n} i18n={i18n}
onClick={clickHandler} onClick={clickHandler}
text={quote.text} text={quote.text}
rawAttachment={quote.attachment} rawAttachment={quote.rawAttachment}
isIncoming={direction === 'incoming'} isIncoming={direction === 'incoming'}
authorPhoneNumber={quote.authorPhoneNumber} authorPhoneNumber={quote.authorPhoneNumber}
authorProfileName={quote.authorProfileName} authorProfileName={quote.authorProfileName}

View file

@ -22,6 +22,7 @@ import { OwnProps as SmartMessageDetailPropsType } from '../state/smart/MessageD
import { CallbackResultType } from '../textsecure/SendMessage'; import { CallbackResultType } from '../textsecure/SendMessage';
import { ExpirationTimerOptions } from '../util/ExpirationTimerOptions'; import { ExpirationTimerOptions } from '../util/ExpirationTimerOptions';
import { missingCaseError } from '../util/missingCaseError'; import { missingCaseError } from '../util/missingCaseError';
import { ColorType } from '../types/Colors';
import { CallMode } from '../types/Calling'; import { CallMode } from '../types/Calling';
import { BodyRangesType } from '../types/Util'; import { BodyRangesType } from '../types/Util';
import { PropsDataType as GroupsV2Props } from '../components/conversation/GroupV2Change'; import { PropsDataType as GroupsV2Props } from '../components/conversation/GroupV2Change';
@ -965,9 +966,9 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
} }
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
createNonBreakingLastSeparator(text: string): string | undefined { private createNonBreakingLastSeparator(text: string): string {
if (!text) { if (!text) {
return undefined; return '';
} }
const nbsp = '\xa0'; const nbsp = '\xa0';
@ -1085,10 +1086,10 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
})); }));
} }
getPropsForQuote(): WhatIsThis { getPropsForQuote(): PropsData['quote'] {
const quote = this.get('quote'); const quote = this.get('quote');
if (!quote) { if (!quote) {
return null; return undefined;
} }
const { format } = PhoneNumber; const { format } = PhoneNumber;
@ -1103,15 +1104,15 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
text, text,
} = quote; } = quote;
const contact = const contact: ConversationModel | undefined =
(author || authorUuid) && author || authorUuid
window.ConversationController.get( ? window.ConversationController.get(
window.ConversationController.ensureContactIds({ window.ConversationController.ensureContactIds({
e164: author, e164: author,
uuid: authorUuid, uuid: authorUuid,
}) })
); )
const authorColor = contact ? contact.getColor() : 'grey'; : undefined;
let reallyNotFound = referencedMessageNotFound; let reallyNotFound = referencedMessageNotFound;
// Is the quote really without a reference? Check with our in memory store // Is the quote really without a reference? Check with our in memory store
@ -1142,31 +1143,56 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
} }
} }
const authorPhoneNumber = format(author, { let authorColor: ColorType;
let authorId: string;
let authorName: undefined | string;
let authorPhoneNumber: undefined | string;
let authorProfileName: undefined | string;
let authorTitle: string;
let isFromMe: boolean;
if (contact && contact.isPrivate()) {
const contactPhoneNumber = contact.get('e164');
authorColor = contact.getColor();
authorId = contact.id;
authorName = contact.get('name');
authorPhoneNumber = contactPhoneNumber
? format(contactPhoneNumber, {
ourRegionCode: regionCode, ourRegionCode: regionCode,
}); })
const authorProfileName = contact ? contact.getProfileName() : null; : undefined;
const authorName = contact ? contact.get('name') : null; authorProfileName = contact.getProfileName();
const authorTitle = contact ? contact.getTitle() : null; authorTitle = contact.getTitle();
const isFromMe = contact ? contact.isMe() : false; isFromMe = contact.isMe();
} else {
window.log.warn(
'getPropsForQuote: contact was missing. This may indicate a bookkeeping error or bad data from another client. Returning a placeholder contact.'
);
authorColor = 'grey';
authorId = 'placeholder-contact';
authorTitle = window.i18n('unknownContact');
isFromMe = false;
}
const firstAttachment = quote.attachments && quote.attachments[0]; const firstAttachment = quote.attachments && quote.attachments[0];
return { return {
text: this.createNonBreakingLastSeparator(text), authorColor,
attachment: firstAttachment authorId,
? this.processQuoteAttachment(firstAttachment) authorName,
: null,
bodyRanges: this.processBodyRanges(bodyRanges),
isFromMe,
sentAt,
authorId: contact ? contact.id : undefined,
authorPhoneNumber, authorPhoneNumber,
authorProfileName, authorProfileName,
authorTitle, authorTitle,
authorName, bodyRanges: this.processBodyRanges(bodyRanges),
authorColor, isFromMe,
rawAttachment: firstAttachment
? this.processQuoteAttachment(firstAttachment)
: undefined,
referencedMessageNotFound: reallyNotFound, referencedMessageNotFound: reallyNotFound,
onClick: () => this.trigger('scroll-to-message'), sentAt: Number(sentAt),
text: this.createNonBreakingLastSeparator(text),
}; };
} }