From 769585e72d9bfbeb463d50be66d1ab8d9f71a218 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 23 Dec 2019 12:15:23 +0200 Subject: [PATCH 1/2] Collapse prefetch errors by default --- client/components/LinkPreview.vue | 3 ++- src/plugins/irc-events/link.js | 1 + test/plugins/link.js | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/client/components/LinkPreview.vue b/client/components/LinkPreview.vue index 41692ae9..6680c2f1 100644 --- a/client/components/LinkPreview.vue +++ b/client/components/LinkPreview.vue @@ -235,10 +235,11 @@ export default { switch (this.link.type) { case "error": + // Collapse all errors by default unless its a message about image being too big defaultState = this.link.error === "image-too-big" ? this.$store.state.settings.media - : this.$store.state.settings.links; + : false; break; case "loading": diff --git a/src/plugins/irc-events/link.js b/src/plugins/irc-events/link.js index 9c782e7e..ee2c4096 100644 --- a/src/plugins/irc-events/link.js +++ b/src/plugins/irc-events/link.js @@ -58,6 +58,7 @@ module.exports = function(client, chan, msg) { parse(msg, chan, preview, res, client); }) .catch((err) => { + preview.shown = false; preview.type = "error"; preview.error = "message"; preview.message = err.message; diff --git a/test/plugins/link.js b/test/plugins/link.js index 8d49ddcd..a46b7290 100644 --- a/test/plugins/link.js +++ b/test/plugins/link.js @@ -569,6 +569,8 @@ Vivamus bibendum vulputate tincidunt. Sed vitae ligula felis.`; this.irc.once("msg:preview", function(data) { expect(data.preview.link).to.equal("http://localhost:" + port + ""); + expect(data.preview.type).to.equal("error"); + expect(data.preview.shown).to.equal(false); done(); }); }); @@ -602,6 +604,8 @@ Vivamus bibendum vulputate tincidunt. Sed vitae ligula felis.`; this.irc.once("msg:preview", function(data) { expect(data.preview.link).to.equal("http://localhost:" + port + ""); + expect(data.preview.type).to.equal("error"); + expect(data.preview.shown).to.equal(false); done(); }); }); From d2932ccea8bab7c63374effe3616eadb6e8825ff Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 23 Dec 2019 12:26:57 +0200 Subject: [PATCH 2/2] Correctly track user toggle of previews --- client/components/LinkPreview.vue | 19 ++++++++++--------- src/plugins/irc-events/link.js | 3 +-- test/plugins/link.js | 12 +++++------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/client/components/LinkPreview.vue b/client/components/LinkPreview.vue index 6680c2f1..b38f8cbb 100644 --- a/client/components/LinkPreview.vue +++ b/client/components/LinkPreview.vue @@ -231,19 +231,20 @@ export default { }); }, updateShownState() { - let defaultState = true; + // User has manually toggled the preview, do not apply default + if (this.link.shown !== null) { + return; + } + + let defaultState = false; switch (this.link.type) { case "error": // Collapse all errors by default unless its a message about image being too big - defaultState = - this.link.error === "image-too-big" - ? this.$store.state.settings.media - : false; - break; + if (this.link.error === "image-too-big") { + defaultState = this.$store.state.settings.media; + } - case "loading": - defaultState = false; break; case "link": @@ -254,7 +255,7 @@ export default { defaultState = this.$store.state.settings.media; } - this.link.shown = this.link.shown && defaultState; + this.link.shown = defaultState; }, }, }; diff --git a/src/plugins/irc-events/link.js b/src/plugins/irc-events/link.js index ee2c4096..cf0c8c70 100644 --- a/src/plugins/irc-events/link.js +++ b/src/plugins/irc-events/link.js @@ -45,7 +45,7 @@ module.exports = function(client, chan, msg) { thumb: "", size: -1, link: link.link, // Send original matched link to the client - shown: true, + shown: null, }; cleanLinks.push(preview); @@ -58,7 +58,6 @@ module.exports = function(client, chan, msg) { parse(msg, chan, preview, res, client); }) .catch((err) => { - preview.shown = false; preview.type = "error"; preview.error = "message"; preview.message = err.message; diff --git a/test/plugins/link.js b/test/plugins/link.js index a46b7290..59d8e317 100644 --- a/test/plugins/link.js +++ b/test/plugins/link.js @@ -59,7 +59,7 @@ Vivamus bibendum vulputate tincidunt. Sed vitae ligula felis.`; thumb: "", size: -1, type: "loading", - shown: true, + shown: null, }, ]); @@ -96,7 +96,7 @@ Vivamus bibendum vulputate tincidunt. Sed vitae ligula felis.`; thumb: "", size: -1, type: "loading", - shown: true, + shown: null, }, ]); @@ -394,7 +394,7 @@ Vivamus bibendum vulputate tincidunt. Sed vitae ligula felis.`; thumb: "", size: -1, type: "loading", - shown: true, + shown: null, }, { body: "", @@ -403,7 +403,7 @@ Vivamus bibendum vulputate tincidunt. Sed vitae ligula felis.`; thumb: "", size: -1, type: "loading", - shown: true, + shown: null, }, ]); @@ -570,7 +570,6 @@ Vivamus bibendum vulputate tincidunt. Sed vitae ligula felis.`; this.irc.once("msg:preview", function(data) { expect(data.preview.link).to.equal("http://localhost:" + port + ""); expect(data.preview.type).to.equal("error"); - expect(data.preview.shown).to.equal(false); done(); }); }); @@ -598,14 +597,13 @@ Vivamus bibendum vulputate tincidunt. Sed vitae ligula felis.`; thumb: "", size: -1, link: "http://localhost:" + port + "", - shown: true, + shown: null, }, ]); this.irc.once("msg:preview", function(data) { expect(data.preview.link).to.equal("http://localhost:" + port + ""); expect(data.preview.type).to.equal("error"); - expect(data.preview.shown).to.equal(false); done(); }); });