From 8f1bb6f087f5b589a44a21b4369a9196a0f03081 Mon Sep 17 00:00:00 2001 From: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com> Date: Tue, 2 Feb 2021 11:09:53 -0600 Subject: [PATCH] Don't render links (or link previews) for blocked or unapproved conversations --- stylesheets/_modules.scss | 8 +++ .../conversation/Message.stories.tsx | 35 ++++++++++ ts/components/conversation/Message.tsx | 68 ++++++++++++------- .../conversation/MessageDetail.stories.tsx | 2 + ts/components/conversation/Quote.stories.tsx | 2 + ts/models/messages.ts | 5 ++ ts/util/lint/exceptions.json | 18 ++--- 7 files changed, 105 insertions(+), 33 deletions(-) diff --git a/stylesheets/_modules.scss b/stylesheets/_modules.scss index 14bc179e03..7b03988a37 100644 --- a/stylesheets/_modules.scss +++ b/stylesheets/_modules.scss @@ -858,6 +858,14 @@ .module-message__link-preview { @include button-reset; + + &--nonclickable { + cursor: inherit; + .module-image__image { + cursor: inherit; + } + } + display: block; margin-left: -12px; diff --git a/ts/components/conversation/Message.stories.tsx b/ts/components/conversation/Message.stories.tsx index 02c1d158c2..c9afc3b521 100644 --- a/ts/components/conversation/Message.stories.tsx +++ b/ts/components/conversation/Message.stories.tsx @@ -2,6 +2,7 @@ // SPDX-License-Identifier: AGPL-3.0-only import * as React from 'react'; +import { isBoolean } from 'lodash'; import { action } from '@storybook/addon-actions'; import { boolean, number, text } from '@storybook/addon-knobs'; @@ -72,6 +73,12 @@ const createProps = (overrideProps: Partial = {}): Props => ({ i18n, id: text('id', overrideProps.id || ''), interactionMode: overrideProps.interactionMode || 'keyboard', + isBlocked: isBoolean(overrideProps.isBlocked) + ? overrideProps.isBlocked + : false, + isMessageRequestAccepted: isBoolean(overrideProps.isMessageRequestAccepted) + ? overrideProps.isMessageRequestAccepted + : true, isTapToView: overrideProps.isTapToView, isTapToViewError: overrideProps.isTapToViewError, isTapToViewExpired: overrideProps.isTapToViewExpired, @@ -885,3 +892,31 @@ story.add('All the context menus', () => { return ; }); + +story.add('Not approved, with link preview', () => { + const props = createProps({ + previews: [ + { + domain: 'signal.org', + image: { + contentType: IMAGE_PNG, + fileName: 'the-sax.png', + height: 240, + url: pngUrl, + width: 320, + }, + isStickerPack: false, + title: 'Signal', + description: + 'Say "hello" to a different messaging experience. An unexpected focus on privacy, combined with all of the features you expect.', + url: 'https://www.signal.org', + date: new Date(2020, 2, 10).valueOf(), + }, + ], + status: 'sent', + text: 'Be sure to look at https://www.signal.org', + isMessageRequestAccepted: false, + }); + + return renderBothDirections(props); +}); diff --git a/ts/components/conversation/Message.tsx b/ts/components/conversation/Message.tsx index 8610bce057..5c8a51fb71 100644 --- a/ts/components/conversation/Message.tsx +++ b/ts/components/conversation/Message.tsx @@ -134,6 +134,8 @@ export type PropsData = { canReply: boolean; canDownload: boolean; canDeleteForEveryone: boolean; + isBlocked: boolean; + isMessageRequestAccepted: boolean; bodyRanges?: BodyRangesType; }; @@ -466,6 +468,11 @@ export class Message extends React.PureComponent { } } + private areLinksEnabled(): boolean { + const { isMessageRequestAccepted, isBlocked } = this.props; + return isMessageRequestAccepted && !isBlocked; + } + public renderTimestamp(): JSX.Element { const { direction, @@ -859,31 +866,18 @@ export class Message extends React.PureComponent { const linkPreviewDate = first.date || null; - return ( - + ) : ( +
{contents}
); } @@ -1138,6 +1157,7 @@ export class Message extends React.PureComponent { > null, openLink: () => null, diff --git a/ts/components/conversation/Quote.stories.tsx b/ts/components/conversation/Quote.stories.tsx index e7d8b99d0a..5f53f5c435 100644 --- a/ts/components/conversation/Quote.stories.tsx +++ b/ts/components/conversation/Quote.stories.tsx @@ -36,6 +36,8 @@ const defaultMessageProps: MessagesProps = { i18n, id: 'messageId', interactionMode: 'keyboard', + isBlocked: false, + isMessageRequestAccepted: true, kickOffAttachmentDownload: () => null, openConversation: () => null, openLink: () => null, diff --git a/ts/models/messages.ts b/ts/models/messages.ts index 9ca9dbb8d1..f2c5384712 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -876,6 +876,11 @@ export class MessageModel extends window.Backbone.Model { deletedForEveryone: this.get('deletedForEveryone') || false, bodyRanges: this.processBodyRanges(), + + isMessageRequestAccepted: conversation + ? conversation.getAccepted() + : true, + isBlocked: Boolean(conversation?.isBlocked()), }; } diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json index 32ebe41f0d..c025306fe8 100644 --- a/ts/util/lint/exceptions.json +++ b/ts/util/lint/exceptions.json @@ -14841,23 +14841,23 @@ "rule": "React-createRef", "path": "ts/components/conversation/Message.tsx", "line": " public audioRef: React.RefObject = React.createRef();", - "lineNumber": 220, - "reasonCategory": "usageTrusted", - "updated": "2020-09-08T20:19:01.913Z" - }, - { - "rule": "React-createRef", - "path": "ts/components/conversation/Message.tsx", - "line": " public focusRef: React.RefObject = React.createRef();", "lineNumber": 222, "reasonCategory": "usageTrusted", "updated": "2020-09-08T20:19:01.913Z" }, + { + "rule": "React-createRef", + "path": "ts/components/conversation/Message.tsx", + "line": " public focusRef: React.RefObject = React.createRef();", + "lineNumber": 224, + "reasonCategory": "usageTrusted", + "updated": "2020-09-08T20:19:01.913Z" + }, { "rule": "React-createRef", "path": "ts/components/conversation/Message.tsx", "line": " > = React.createRef();", - "lineNumber": 226, + "lineNumber": 228, "reasonCategory": "usageTrusted", "updated": "2020-08-28T19:36:40.817Z" },