2017-06-26 09:01:55 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const socket = require("../socket");
|
2018-07-11 11:33:06 +00:00
|
|
|
const {shouldOpenMessagePreview} = require("../options");
|
2018-07-10 11:57:11 +00:00
|
|
|
const {vueApp, findChannel} = require("../vue");
|
2017-06-26 09:01:55 +00:00
|
|
|
|
|
|
|
socket.on("msg:preview", function(data) {
|
2018-07-10 11:57:11 +00:00
|
|
|
const {channel} = findChannel(data.chan);
|
|
|
|
const message = channel.messages.find((m) => m.id === data.id);
|
|
|
|
|
|
|
|
if (!message) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const previewIndex = message.previews.findIndex((m) => m.link === data.preview.link);
|
|
|
|
|
|
|
|
if (previewIndex > -1) {
|
2018-07-11 11:33:06 +00:00
|
|
|
data.preview.canDisplay = shouldOpenMessagePreview(data.preview.type);
|
|
|
|
|
2018-07-10 11:57:11 +00:00
|
|
|
vueApp.$set(message.previews, previewIndex, data.preview);
|
|
|
|
}
|
2017-06-26 09:01:55 +00:00
|
|
|
});
|