diff --git a/.storybook/webpack.config.js b/.storybook/webpack.config.js
index 268602c5e..9d9c3cbf9 100644
--- a/.storybook/webpack.config.js
+++ b/.storybook/webpack.config.js
@@ -22,5 +22,9 @@ module.exports = ({ config }) => {
config.resolve.extensions = ['.tsx', '.ts', '.jsx', '.js'];
+ config.externals = {
+ net: 'net',
+ };
+
return config;
};
diff --git a/ACKNOWLEDGMENTS.md b/ACKNOWLEDGMENTS.md
index 70c08b0d6..5b175a13f 100644
--- a/ACKNOWLEDGMENTS.md
+++ b/ACKNOWLEDGMENTS.md
@@ -42,6 +42,30 @@ Signal Desktop makes use of the following open source projects.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+## abort-controller
+
+ MIT License
+
+ Copyright (c) 2017 Toru Nagashima
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+
## array-move
MIT License
@@ -1145,29 +1169,6 @@ Signal Desktop makes use of the following open source projects.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-## he
-
- Copyright Mathias Bynens
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
## history
MIT License
diff --git a/js/modules/link_previews.js b/js/modules/link_previews.js
index 2b7b8c3f9..2eefb9ddf 100644
--- a/js/modules/link_previews.js
+++ b/js/modules/link_previews.js
@@ -1,23 +1,16 @@
/* global URL */
const { isNumber, compact, isEmpty } = require('lodash');
-const he = require('he');
+const { isIP } = require('net');
const nodeUrl = require('url');
const LinkifyIt = require('linkify-it');
const linkify = LinkifyIt();
-const { concatenateBytes, getViewOfArrayBuffer } = require('../../ts/Crypto');
module.exports = {
- assembleChunks,
findLinks,
- getChunkPattern,
getDomain,
- getTitleMetaTag,
- getImageMetaTag,
isLinkSafeToPreview,
- isLinkInWhitelist,
- isMediaLinkInWhitelist,
isLinkSneaky,
isStickerPack,
};
@@ -32,101 +25,10 @@ function isLinkSafeToPreview(link) {
return url.protocol === 'https:' && !isLinkSneaky(link);
}
-const SUPPORTED_DOMAINS = [
- 'youtube.com',
- 'www.youtube.com',
- 'm.youtube.com',
- 'youtu.be',
- 'reddit.com',
- 'www.reddit.com',
- 'm.reddit.com',
- 'imgur.com',
- 'www.imgur.com',
- 'm.imgur.com',
- 'instagram.com',
- 'www.instagram.com',
- 'm.instagram.com',
- 'pinterest.com',
- 'www.pinterest.com',
- 'pin.it',
- 'signal.art',
-];
-
-// This function will soon be removed in favor of `isLinkSafeToPreview`. It is
-// currently used because outbound-from-Desktop link previews only support a
-// few domains (see the list above). We will soon remove this restriction to
-// allow link previews from all domains, making this function obsolete.
-function isLinkInWhitelist(link) {
- try {
- const url = new URL(link);
-
- if (url.protocol !== 'https:') {
- return false;
- }
-
- if (!url.pathname || url.pathname.length < 2) {
- return false;
- }
-
- const lowercase = url.host.toLowerCase();
- if (!SUPPORTED_DOMAINS.includes(lowercase)) {
- return false;
- }
-
- return true;
- } catch (error) {
- return false;
- }
-}
-
function isStickerPack(link) {
return (link || '').startsWith('https://signal.art/addstickers/');
}
-const SUPPORTED_MEDIA_DOMAINS = /^([^.]+\.)*(ytimg\.com|cdninstagram\.com|redd\.it|imgur\.com|fbcdn\.net|pinimg\.com)$/i;
-
-// This function will soon be removed. See the comment in `isLinkInWhitelist`
-// for more info.
-function isMediaLinkInWhitelist(link) {
- try {
- const url = new URL(link);
-
- if (url.protocol !== 'https:') {
- return false;
- }
-
- if (!url.pathname || url.pathname.length < 2) {
- return false;
- }
-
- if (!SUPPORTED_MEDIA_DOMAINS.test(url.host)) {
- return false;
- }
-
- return true;
- } catch (error) {
- return false;
- }
-}
-
-const META_TITLE = /]+?content="([\s\S]+?)"[^>]*>/im;
-const META_IMAGE = /]+?content="([\s\S]+?)"[^>]*>/im;
-function _getMetaTag(html, regularExpression) {
- const match = regularExpression.exec(html);
- if (match && match[1]) {
- return he.decode(match[1]).trim();
- }
-
- return null;
-}
-
-function getTitleMetaTag(html) {
- return _getMetaTag(html, META_TITLE);
-}
-function getImageMetaTag(html) {
- return _getMetaTag(html, META_IMAGE);
-}
-
function findLinks(text, caretLocation) {
const haveCaretLocation = isNumber(caretLocation);
const textLength = text ? text.length : 0;
@@ -169,81 +71,6 @@ function getDomain(url) {
}
}
-const MB = 1024 * 1024;
-const KB = 1024;
-
-function getChunkPattern(size, initialOffset) {
- if (size > MB) {
- return _getRequestPattern(size, MB, initialOffset);
- }
- if (size > 500 * KB) {
- return _getRequestPattern(size, 500 * KB, initialOffset);
- }
- if (size > 100 * KB) {
- return _getRequestPattern(size, 100 * KB, initialOffset);
- }
- if (size > 50 * KB) {
- return _getRequestPattern(size, 50 * KB, initialOffset);
- }
- if (size > 10 * KB) {
- return _getRequestPattern(size, 10 * KB, initialOffset);
- }
- if (size > KB) {
- return _getRequestPattern(size, KB, initialOffset);
- }
-
- return {
- start: {
- start: initialOffset,
- end: size - 1,
- },
- };
-}
-
-function _getRequestPattern(size, increment, initialOffset) {
- const results = [];
-
- let offset = initialOffset || 0;
- while (size - offset > increment) {
- results.push({
- start: offset,
- end: offset + increment - 1,
- overlap: 0,
- });
- offset += increment;
- }
-
- if (size - offset > 0) {
- results.push({
- start: size - increment,
- end: size - 1,
- overlap: increment - (size - offset),
- });
- }
-
- return results;
-}
-
-function assembleChunks(chunkDescriptors) {
- const chunks = chunkDescriptors.map((chunk, index) => {
- if (index !== chunkDescriptors.length - 1) {
- return chunk.data;
- }
-
- if (!chunk.overlap) {
- return chunk.data;
- }
-
- return getViewOfArrayBuffer(
- chunk.data,
- chunk.overlap,
- chunk.data.byteLength
- );
- });
-
- return concatenateBytes(...chunks);
-}
-
const ASCII_PATTERN = new RegExp('[\\u0020-\\u007F]', 'g');
function isLinkSneaky(link) {
@@ -272,6 +99,11 @@ function isLinkSneaky(link) {
return true;
}
+ // Domain cannot be an IP address.
+ if (isIP(domain)) {
+ return true;
+ }
+
// There must be at least 2 domain labels, and none of them can be empty.
const labels = domain.split('.');
if (labels.length < 2 || labels.some(isEmpty)) {
diff --git a/package.json b/package.json
index b17938fc0..0e9653b67 100644
--- a/package.json
+++ b/package.json
@@ -63,6 +63,7 @@
"dependencies": {
"@journeyapps/sqlcipher": "https://github.com/scottnonnenberg-signal/node-sqlcipher.git#b10f232fac62ba7f8775c9e086bb5558fe7d948b",
"@sindresorhus/is": "0.8.0",
+ "abort-controller": "3.0.0",
"array-move": "2.1.0",
"backbone": "1.3.3",
"blob-util": "1.3.0",
@@ -88,7 +89,6 @@
"glob": "7.1.6",
"google-libphonenumber": "3.2.6",
"got": "8.2.0",
- "he": "1.2.0",
"history": "4.9.0",
"intl-tel-input": "12.1.15",
"jquery": "3.5.0",
diff --git a/preload.js b/preload.js
index db14a01b0..7660bef8d 100644
--- a/preload.js
+++ b/preload.js
@@ -555,8 +555,20 @@ try {
});
if (config.environment === 'test') {
+ // This is a hack to let us run TypeScript tests in the renderer process. See the
+ // code in `test/index.html`.
+ const pendingDescribeCalls = [];
+ window.describe = (...args) => {
+ pendingDescribeCalls.push(args);
+ };
+
/* eslint-disable global-require, import/no-extraneous-dependencies */
+ require('./ts/test-electron/linkPreviews/linkPreviewFetch_test');
+
+ delete window.describe;
+
window.test = {
+ pendingDescribeCalls,
fastGlob: require('fast-glob'),
normalizePath: require('normalize-path'),
fse: require('fs-extra'),
diff --git a/protos/SignalService.proto b/protos/SignalService.proto
index 7598c1bed..450395915 100644
--- a/protos/SignalService.proto
+++ b/protos/SignalService.proto
@@ -352,8 +352,9 @@ message SyncMessage {
optional bool readReceipts = 1;
optional bool unidentifiedDeliveryIndicators = 2;
optional bool typingIndicators = 3;
- optional bool linkPreviews = 4;
+ // 4 is reserved
optional uint32 provisioningVersion = 5;
+ optional bool linkPreviews = 6;
}
message StickerPackOperation {
diff --git a/protos/SignalStorage.proto b/protos/SignalStorage.proto
index 8e4db5705..9b2b8e673 100644
--- a/protos/SignalStorage.proto
+++ b/protos/SignalStorage.proto
@@ -98,5 +98,7 @@ message AccountRecord {
optional bool readReceipts = 6;
optional bool sealedSenderIndicators = 7;
optional bool typingIndicators = 8;
- optional bool linkPreviews = 9;
+ optional bool proxiedLinkPreviews = 9;
+ optional bool noteToSelfUnread = 10;
+ optional bool linkPreviews = 11;
}
diff --git a/stylesheets/_modules.scss b/stylesheets/_modules.scss
index bf6ccf4f5..40c399cf5 100644
--- a/stylesheets/_modules.scss
+++ b/stylesheets/_modules.scss
@@ -5048,7 +5048,7 @@ button.module-image__border-overlay:focus {
position: relative;
display: flex;
flex-direction: row;
- align-items: flex-start;
+ align-items: stretch;
min-height: 65px;
}
@@ -5073,6 +5073,8 @@ button.module-image__border-overlay:focus {
margin-right: 8px;
}
.module-staged-link-preview__content {
+ display: flex;
+ flex-direction: column;
margin-right: 20px;
}
.module-staged-link-preview__title {
@@ -5087,14 +5089,46 @@ button.module-image__border-overlay:focus {
overflow: hidden;
display: -webkit-box;
- -webkit-line-clamp: 2;
+ -webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}
+.module-staged-link-preview__description {
+ @include font-body-1;
+
+ overflow: hidden;
+ display: -webkit-box;
+ -webkit-line-clamp: 1;
+ -webkit-box-orient: vertical;
+}
+.module-staged-link-preview__footer {
+ @include font-body-2;
+
+ display: flex;
+ flex-flow: row wrap;
+ align-items: center;
+
+ @include light-theme {
+ color: $color-gray-60;
+ }
+ @include dark-theme {
+ color: $color-gray-25;
+ }
+
+ > *:not(:first-child) {
+ display: flex;
+
+ &:before {
+ content: '•';
+ font-size: 50%;
+ margin-left: 0.2rem;
+ margin-right: 0.2rem;
+ }
+ }
+}
.module-staged-link-preview__location {
@include font-body-2;
- margin-top: 4px;
- text-transform: uppercase;
+ text-transform: lowercase;
@include light-theme {
color: $color-gray-60;
diff --git a/test/index.html b/test/index.html
index 78c90a5e2..5b3edb471 100644
--- a/test/index.html
+++ b/test/index.html
@@ -395,6 +395,11 @@