If a preview fails to load, remove the link from msg object
Fixes #2438
This commit is contained in:
parent
2d13eaaf6b
commit
a663993d0b
@ -238,7 +238,7 @@ function parse(msg, preview, res, client) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return;
|
return removePreview(msg, preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!promise) {
|
if (!promise) {
|
||||||
@ -261,7 +261,7 @@ function handlePreview(client, msg, preview, res) {
|
|||||||
// For link previews, drop the thumbnail
|
// For link previews, drop the thumbnail
|
||||||
// For other types, do not display preview at all
|
// For other types, do not display preview at all
|
||||||
if (preview.type !== "link") {
|
if (preview.type !== "link") {
|
||||||
return;
|
return removePreview(msg, preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
preview.thumb = "";
|
preview.thumb = "";
|
||||||
@ -282,7 +282,7 @@ function emitPreview(client, msg, preview) {
|
|||||||
if (preview.thumb.length || preview.body.length) {
|
if (preview.thumb.length || preview.body.length) {
|
||||||
preview.head = "Untitled page";
|
preview.head = "Untitled page";
|
||||||
} else {
|
} else {
|
||||||
return;
|
return removePreview(msg, preview);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,6 +290,16 @@ function emitPreview(client, msg, preview) {
|
|||||||
client.emit("msg:preview", {id, preview});
|
client.emit("msg:preview", {id, preview});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removePreview(msg, preview) {
|
||||||
|
// If a preview fails to load, remove the link from msg object
|
||||||
|
// So that client doesn't attempt to display an preview on page reload
|
||||||
|
const index = msg.previews.indexOf(preview);
|
||||||
|
|
||||||
|
if (index > -1) {
|
||||||
|
msg.previews.splice(index, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getRequestHeaders(headers) {
|
function getRequestHeaders(headers) {
|
||||||
const formattedHeaders = {
|
const formattedHeaders = {
|
||||||
"User-Agent": "Mozilla/5.0 (compatible; The Lounge IRC Client; +https://github.com/thelounge/thelounge)",
|
"User-Agent": "Mozilla/5.0 (compatible; The Lounge IRC Client; +https://github.com/thelounge/thelounge)",
|
||||||
|
Loading…
Reference in New Issue
Block a user