Merge pull request #3628 from thelounge/xpaw/prefetch-error

Collapse prefetch errors by default, and correctly track user toggle
This commit is contained in:
Pavel Djundik 2019-12-31 21:31:35 +02:00 committed by GitHub
commit 093ef2ff55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 15 deletions

View file

@ -231,18 +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":
defaultState =
this.link.error === "image-too-big"
? this.$store.state.settings.media
: this.$store.state.settings.links;
break;
// Collapse all errors by default unless its a message about image being too big
if (this.link.error === "image-too-big") {
defaultState = this.$store.state.settings.media;
}
case "loading":
defaultState = false;
break;
case "link":
@ -253,7 +255,7 @@ export default {
defaultState = this.$store.state.settings.media;
}
this.link.shown = this.link.shown && defaultState;
this.link.shown = defaultState;
},
},
};

View file

@ -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);

View file

@ -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,
},
]);
@ -569,6 +569,7 @@ 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");
done();
});
});
@ -596,12 +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");
done();
});
});