feat: link previews

After this commit, previews for links will be enabled by default. To disable it, use linkPreview: false as an option when sending the message.

close #98
This commit is contained in:
Pedro Lopez
2020-04-11 19:45:06 -04:00
parent 2b3c3e971a
commit 044f62216b
2 changed files with 13 additions and 1 deletions

View File

@@ -24,7 +24,7 @@ exports.ExposeStore = (moduleRaidStr) => {
window.Store.Cmd = window.mR.findModule('Cmd')[0].default;
window.Store.MediaTypes = window.mR.findModule('msgToMediaType')[0];
window.Store.UserConstructor = window.mR.findModule((module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null)[0].default;
window.Store.Validators = window.mR.findModule('findLinks')[0];
};
exports.LoadUtils = () => {
@@ -76,6 +76,17 @@ exports.LoadUtils = () => {
delete options.location;
}
if (options.linkPreview) {
delete options.linkPreview;
const link = window.Store.Validators.findLink(content);
if (link) {
const preview = await window.Store.Wap.queryLinkPreview(link.url);
if (!preview.status) {
options = { ...options, ...preview};
}
}
}
const newMsgId = new window.Store.MsgKey({
from: window.Store.Conn.me,
to: chat.id,