Skip to content

Commit

Permalink
Display proper text when quoting view once message
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny-signal committed Jun 2, 2021
1 parent 8122706 commit b009967
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 12 deletions.
6 changes: 3 additions & 3 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2226,15 +2226,15 @@
},
"message--getDescription--disappearing-media": {
"message": "View-once Media",
"description": "Shown in notifications and in the left pane after view-once message is deleted."
"description": "Shown in notifications and in the left pane after view-once message is deleted. Also shown when quoting a view once media."
},
"message--getDescription--disappearing-photo": {
"message": "View-once Photo",
"description": "Shown in notifications and in the left pane when a message is a view once photo."
"description": "Shown in notifications and in the left pane when a message is a view once photo. Also shown when quoting a view once photo."
},
"message--getDescription--disappearing-video": {
"message": "View-once Video",
"description": "Shown in notifications and in the left pane when a message is a view once video."
"description": "Shown in notifications and in the left pane when a message is a view once video. Also shown when quoting a view once video."
},
"message--deletedForEveryone": {
"message": "This message was deleted.",
Expand Down
3 changes: 3 additions & 0 deletions stylesheets/_modules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,9 @@ $timer-icons: '55', '50', '45', '40', '35', '30', '25', '20', '15', '10', '05',
.module-quote__icon-container__icon--movie {
@include color-svg('../images/movie.svg', $color-ultramarine);
}
.module-quote__icon-container__icon--view-once {
@include color-svg('../images/icons/v2/view-once-24.svg', $color-ultramarine);
}

.module-quote__generic-file {
display: flex;
Expand Down
4 changes: 3 additions & 1 deletion ts/components/conversation/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export type PropsData = {
authorName?: string;
bodyRanges?: BodyRangesType;
referencedMessageNotFound: boolean;
isViewOnce: boolean;
};
previews: Array<LinkPreviewType>;
isExpired?: boolean;
Expand Down Expand Up @@ -1062,7 +1063,7 @@ export class Message extends React.Component<Props, State> {

const withContentAbove =
conversationType === 'group' && direction === 'incoming';
const { referencedMessageNotFound } = quote;
const { isViewOnce, referencedMessageNotFound } = quote;

const clickHandler = disableScroll
? undefined
Expand All @@ -1087,6 +1088,7 @@ export class Message extends React.Component<Props, State> {
bodyRanges={quote.bodyRanges}
conversationColor={conversationColor}
customColor={customColor}
isViewOnce={isViewOnce}
referencedMessageNotFound={referencedMessageNotFound}
isFromMe={quote.isFromMe}
withContentAbove={withContentAbove}
Expand Down
45 changes: 45 additions & 0 deletions ts/components/conversation/Quote.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const renderInMessage = ({
conversationColor,
isFromMe,
rawAttachment,
isViewOnce,
referencedMessageNotFound,
text: quoteText,
}: Props) => {
Expand All @@ -96,6 +97,7 @@ const renderInMessage = ({
conversationColor,
isFromMe,
rawAttachment,
isViewOnce,
referencedMessageNotFound,
sentAt: Date.now() - 30 * 1000,
text: quoteText,
Expand Down Expand Up @@ -133,6 +135,7 @@ const createProps = (overrideProps: Partial<Props> = {}): Props => ({
'referencedMessageNotFound',
overrideProps.referencedMessageNotFound || false
),
isViewOnce: boolean('isViewOnce', overrideProps.isViewOnce || false),
text: text(
'text',
isString(overrideProps.text)
Expand Down Expand Up @@ -247,6 +250,20 @@ story.add('Image Attachment w/o Thumbnail', () => {
return <Quote {...props} />;
});

story.add('Image Tap-to-View', () => {
const props = createProps({
text: '',
isViewOnce: true,
rawAttachment: {
contentType: IMAGE_PNG,
fileName: 'sax.png',
isVoiceMessage: false,
},
});

return <Quote {...props} />;
});

story.add('Video Only', () => {
const props = createProps({
rawAttachment: {
Expand Down Expand Up @@ -293,6 +310,20 @@ story.add('Video Attachment w/o Thumbnail', () => {
return <Quote {...props} />;
});

story.add('Video Tap-to-View', () => {
const props = createProps({
text: '',
isViewOnce: true,
rawAttachment: {
contentType: VIDEO_MP4,
fileName: 'great-video.mp4',
isVoiceMessage: false,
},
});

return <Quote {...props} />;
});

story.add('Audio Only', () => {
const props = createProps({
rawAttachment: {
Expand Down Expand Up @@ -359,6 +390,20 @@ story.add('Other File Only', () => {
return <Quote {...props} />;
});

story.add('Media Tap-to-View', () => {
const props = createProps({
text: '',
isViewOnce: true,
rawAttachment: {
contentType: AUDIO_MP3,
fileName: 'great-video.mp3',
isVoiceMessage: false,
},
});

return <Quote {...props} />;
});

story.add('Other File Attachment', () => {
const props = createProps({
rawAttachment: {
Expand Down
36 changes: 33 additions & 3 deletions ts/components/conversation/Quote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type Props = {
onClose?: () => void;
text: string;
rawAttachment?: QuotedAttachmentType;
isViewOnce: boolean;
referencedMessageNotFound: boolean;
};

Expand Down Expand Up @@ -83,19 +84,32 @@ function getObjectUrl(thumbnail: Attachment | undefined): string | undefined {

function getTypeLabel({
i18n,
isViewOnce = false,
contentType,
isVoiceMessage,
}: {
i18n: LocalizerType;
isViewOnce?: boolean;
contentType: MIME.MIMEType;
isVoiceMessage: boolean;
}): string | undefined {
if (GoogleChrome.isVideoTypeSupported(contentType)) {
if (isViewOnce) {
return i18n('message--getDescription--disappearing-video');
}
return i18n('video');
}
if (GoogleChrome.isImageTypeSupported(contentType)) {
if (isViewOnce) {
return i18n('message--getDescription--disappearing-photo');
}
return i18n('photo');
}

if (isViewOnce) {
return i18n('message--getDescription--disappearing-media');
}

if (MIME.isAudio(contentType) && isVoiceMessage) {
return i18n('voiceMessage');
}
Expand Down Expand Up @@ -217,7 +231,7 @@ export class Quote extends React.Component<Props, State> {
}

public renderIconContainer(): JSX.Element | null {
const { rawAttachment } = this.props;
const { rawAttachment, isViewOnce } = this.props;
const { imageBroken } = this.state;
const attachment = getAttachment(rawAttachment);

Expand All @@ -228,6 +242,10 @@ export class Quote extends React.Component<Props, State> {
const { contentType, thumbnail } = attachment;
const objectUrl = getObjectUrl(thumbnail);

if (isViewOnce) {
return this.renderIcon('view-once');
}

if (GoogleChrome.isVideoTypeSupported(contentType)) {
return objectUrl && !imageBroken
? this.renderImage(objectUrl, 'play')
Expand All @@ -246,7 +264,14 @@ export class Quote extends React.Component<Props, State> {
}

public renderText(): JSX.Element | null {
const { bodyRanges, i18n, text, rawAttachment, isIncoming } = this.props;
const {
bodyRanges,
i18n,
text,
rawAttachment,
isIncoming,
isViewOnce,
} = this.props;

if (text) {
const quoteText = bodyRanges
Expand Down Expand Up @@ -274,7 +299,12 @@ export class Quote extends React.Component<Props, State> {

const { contentType, isVoiceMessage } = attachment;

const typeLabel = getTypeLabel({ i18n, contentType, isVoiceMessage });
const typeLabel = getTypeLabel({
i18n,
isViewOnce,
contentType,
isVoiceMessage,
});
if (typeLabel) {
return (
<div
Expand Down
1 change: 1 addition & 0 deletions ts/model-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type QuotedMessageType = {
bodyRanges: BodyRangesType;
id: string;
referencedMessageNotFound: boolean;
isViewOnce: boolean;
text: string;
};

Expand Down
5 changes: 3 additions & 2 deletions ts/models/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
trimForDisplay,
verifyAccessKey,
} from '../Crypto';
import { GroupChangeClass } from '../textsecure.d';
import { GroupChangeClass, DataMessageClass } from '../textsecure.d';
import { BodyRangesType } from '../types/Util';
import { getTextWithMentions } from '../util';
import { migrateColor } from '../util/migrateColor';
Expand Down Expand Up @@ -3130,7 +3130,7 @@ export class ConversationModel extends window.Backbone

async makeQuote(
quotedMessage: typeof window.Whisper.MessageType
): Promise<WhatIsThis> {
): Promise<DataMessageClass.Quote> {
const { getName } = Contact;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const contact = quotedMessage.getContact()!;
Expand All @@ -3150,6 +3150,7 @@ export class ConversationModel extends window.Backbone
bodyRanges: quotedMessage.get('bodyRanges'),
id: quotedMessage.get('sent_at'),
text: body || embeddedContactName,
isViewOnce: quotedMessage.isTapToView(),
attachments: quotedMessage.isTapToView()
? [{ contentType: 'image/jpeg', fileName: null }]
: await this.getQuoteAttachment(attachments, preview, sticker),
Expand Down
7 changes: 7 additions & 0 deletions ts/models/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
authorUuid,
bodyRanges,
id: sentAt,
isViewOnce,
referencedMessageNotFound,
text,
} = quote;
Expand Down Expand Up @@ -1342,6 +1343,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
rawAttachment: firstAttachment
? this.processQuoteAttachment(firstAttachment)
: undefined,
isViewOnce,
referencedMessageNotFound: !foundReference,
sentAt: Number(sentAt),
text: this.createNonBreakingLastSeparator(text),
Expand Down Expand Up @@ -3363,10 +3365,15 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
contentType: 'image/jpeg',
},
];
// eslint-disable-next-line no-param-reassign
quote.isViewOnce = true;

return;
}

// eslint-disable-next-line no-param-reassign
quote.isViewOnce = false;

// eslint-disable-next-line no-param-reassign
quote.text = originalMessage.get('body');
if (firstAttachment) {
Expand Down
7 changes: 4 additions & 3 deletions ts/textsecure.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,14 +653,15 @@ export declare namespace DataMessageClass {

// Note: deep nesting
class Quote {
id: ProtoBigNumberType | null;
authorUuid: string | null;
text: string | null;
id?: ProtoBigNumberType | null;
authorUuid?: string | null;
text?: string | null;
attachments?: Array<DataMessageClass.Quote.QuotedAttachment>;
bodyRanges?: Array<DataMessageClass.BodyRange>;

// Added later during processing
referencedMessageNotFound?: boolean;
isViewOnce?: boolean;
}

class BodyRange {
Expand Down

0 comments on commit b009967

Please sign in to comment.