Skip to content

Commit

Permalink
Preview message URLs only once
Browse files Browse the repository at this point in the history
If a message lists the same URL twice, the URL would be previewed twice.
This includes Markdown code explicitly using the URL as the link text.
e.g.
        ```
        [http://example.com/](http://example.com/)
        ```

Strip out duplicate URLs when parsing them out,so we only show
a single preview.

Co-authored-by: Evgeniy Kulesh <evgeniyk@seekingalpha.com>
  • Loading branch information
nmagedman and Evgeniy Kulesh committed Jun 30, 2021
1 parent 44f9f89 commit 52fc6d1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/lib/server/functions/insertMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const insertMessage = function(user, message, rid, upsert = false) {

const urls = message.html.match(/([A-Za-z]{3,9}):\/\/([-;:&=\+\$,\w]+@{1})?([-A-Za-z0-9\.]+)+:?(\d+)?((\/[-\+=!:~%\/\.@\,\(\)\w]*)?\??([-\+=&!:;%@\/\.\,\w]+)?(?:#([^\s\)]+))?)?/g);
if (urls) {
message.urls = urls.map((url) => ({ url }));
message.urls = [...new Set(urls)].map((url) => ({ url }));
}

message = Markdown.mountTokensBack(message, false);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/server/functions/parseUrlsInMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const parseUrlsInMessage = (message) => {

const urls = message.html.match(/([A-Za-z]{3,9}):\/\/([-;:&=\+\$,\w]+@{1})?([-A-Za-z0-9\.]+)+:?(\d+)?((\/[-\+=!:~%\/\.@\,\w]*)?\??([-\+=&!:;%@\/\.\,\w]+)?(?:#([^\s\)]+))?)?/g) || [];
if (urls) {
message.urls = urls.map((url) => ({ url }));
message.urls = [...new Set(urls)].map((url) => ({ url }));
}

message = Markdown.mountTokensBack(message, false);
Expand Down

0 comments on commit 52fc6d1

Please sign in to comment.