Fix link preview (#2681)
* Fix link preview * Fix typo * Fix preview options * Add example for preview
This commit is contained in:
parent
5001a89714
commit
ac0a50082f
2 changed files with 17 additions and 24 deletions
|
|
@ -66,6 +66,9 @@ client.on('message', async msg => {
|
|||
} else if (msg.body.startsWith('!echo ')) {
|
||||
// Replies with the same message
|
||||
msg.reply(msg.body.slice(6));
|
||||
} else if (msg.body.startsWith('!preview ')) {
|
||||
const text = msg.body.slice(9);
|
||||
msg.reply(text, null, { linkPreview: true });
|
||||
} else if (msg.body.startsWith('!desc ')) {
|
||||
// Change the group description
|
||||
let chat = await msg.getChat();
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||
window.Store.EphemeralFields = window.mR.findModule('getEphemeralFields')[0];
|
||||
window.Store.MsgActionChecks = window.mR.findModule('canSenderRevokeMsg')[0];
|
||||
window.Store.QuotedMsg = window.mR.findModule('getQuotedMsgObj')[0];
|
||||
window.Store.LinkPreview = window.mR.findModule('getLinkPreview')[0];
|
||||
window.Store.Socket = window.mR.findModule('deprecatedSendIq')[0];
|
||||
window.Store.SocketWap = window.mR.findModule('wap')[0];
|
||||
window.Store.SearchContext = window.mR.findModule('getSearchContext')[0].getSearchContext;
|
||||
|
|
@ -107,12 +108,6 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||
// eslint-disable-next-line no-undef
|
||||
if ((m = window.mR.findModule('ChatCollection')[0]) && m.ChatCollection && typeof m.ChatCollection.findImpl === 'undefined' && typeof m.ChatCollection._find !== 'undefined') m.ChatCollection.findImpl = m.ChatCollection._find;
|
||||
|
||||
// TODO remove these once everybody has been updated to WWebJS with legacy sessions removed
|
||||
const _linkPreview = window.mR.findModule('queryLinkPreview');
|
||||
if (_linkPreview && _linkPreview[0] && _linkPreview[0].default) {
|
||||
window.Store.Wap = _linkPreview[0].default;
|
||||
}
|
||||
|
||||
const _isMDBackend = window.mR.findModule('isMDBackend');
|
||||
if(_isMDBackend && _isMDBackend[0] && _isMDBackend[0].isMDBackend) {
|
||||
window.Store.MDBackend = _isMDBackend[0].isMDBackend();
|
||||
|
|
@ -271,12 +266,11 @@ exports.LoadUtils = () => {
|
|||
|
||||
if (options.linkPreview) {
|
||||
delete options.linkPreview;
|
||||
|
||||
// Not supported yet by WhatsApp Web on MD
|
||||
if(!window.Store.MDBackend) {
|
||||
const link = window.Store.Validators.findLink(content);
|
||||
if (link) {
|
||||
const preview = await window.Store.Wap.queryLinkPreview(link.url);
|
||||
let preview = await window.Store.LinkPreview.getLinkPreview(link);
|
||||
if (preview && preview.data) {
|
||||
preview = preview.data;
|
||||
preview.preview = true;
|
||||
preview.subtype = 'url';
|
||||
options = {...options, ...preview};
|
||||
|
|
@ -379,19 +373,15 @@ exports.LoadUtils = () => {
|
|||
}
|
||||
|
||||
if (options.linkPreview) {
|
||||
options.linkPreview = null;
|
||||
|
||||
// Not supported yet by WhatsApp Web on MD
|
||||
if(!window.Store.MDBackend) {
|
||||
delete options.linkPreview;
|
||||
const link = window.Store.Validators.findLink(content);
|
||||
if (link) {
|
||||
const preview = await window.Store.Wap.queryLinkPreview(link.url);
|
||||
const preview = await window.Store.LinkPreview.getLinkPreview(link);
|
||||
preview.preview = true;
|
||||
preview.subtype = 'url';
|
||||
options = { ...options, ...preview };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const internalOptions = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue