Skip to content

Commit

Permalink
feat: link previews
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pedroslopez committed Apr 11, 2020
1 parent 2b3c3e9 commit 044f622
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Client.js
Expand Up @@ -381,6 +381,7 @@ class Client extends EventEmitter {
*/
async sendMessage(chatId, content, options = {}) {
let internalOptions = {
linkPreview: options.linkPreview === false ? undefined : true,
caption: options.caption,
quotedMessageId: options.quotedMessageId,
mentionedJidList: Array.isArray(options.mentions) ? options.mentions.map(contact => contact.id._serialized) : []
Expand Down
13 changes: 12 additions & 1 deletion src/util/Injected.js
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 044f622

Please sign in to comment.