feat(interface): Open chat search, open chat at message position (#447)

This commit is contained in:
Aliyss Snow
2020-12-17 22:01:46 +01:00
committed by Pedro S. Lopez
parent 274d24002b
commit 87cb5a0519
2 changed files with 49 additions and 20 deletions

View File

@@ -40,11 +40,11 @@ client.on('ready', () => {
client.on('message', async msg => { client.on('message', async msg => {
console.log('MESSAGE RECEIVED', msg); console.log('MESSAGE RECEIVED', msg);
if (msg.body == '!ping reply') { if (msg.body === '!ping reply') {
// Send a new message as a reply to the current one // Send a new message as a reply to the current one
msg.reply('pong'); msg.reply('pong');
} else if (msg.body == '!ping') { } else if (msg.body === '!ping') {
// Send a new message to the same chat // Send a new message to the same chat
client.sendMessage(msg.from, 'pong'); client.sendMessage(msg.from, 'pong');
@@ -79,7 +79,7 @@ client.on('message', async msg => {
} else { } else {
msg.reply('This command can only be used in a group!'); msg.reply('This command can only be used in a group!');
} }
} else if (msg.body == '!leave') { } else if (msg.body === '!leave') {
// Leave the group // Leave the group
let chat = await msg.getChat(); let chat = await msg.getChat();
if (chat.isGroup) { if (chat.isGroup) {
@@ -95,7 +95,7 @@ client.on('message', async msg => {
} catch (e) { } catch (e) {
msg.reply('That invite code seems to be invalid.'); msg.reply('That invite code seems to be invalid.');
} }
} else if (msg.body == '!groupinfo') { } else if (msg.body === '!groupinfo') {
let chat = await msg.getChat(); let chat = await msg.getChat();
if (chat.isGroup) { if (chat.isGroup) {
msg.reply(` msg.reply(`
@@ -109,10 +109,10 @@ client.on('message', async msg => {
} else { } else {
msg.reply('This command can only be used in a group!'); msg.reply('This command can only be used in a group!');
} }
} else if (msg.body == '!chats') { } else if (msg.body === '!chats') {
const chats = await client.getChats(); const chats = await client.getChats();
client.sendMessage(msg.from, `The bot has ${chats.length} chats open.`); client.sendMessage(msg.from, `The bot has ${chats.length} chats open.`);
} else if (msg.body == '!info') { } else if (msg.body === '!info') {
let info = client.info; let info = client.info;
client.sendMessage(msg.from, ` client.sendMessage(msg.from, `
*Connection info* *Connection info*
@@ -121,7 +121,7 @@ client.on('message', async msg => {
Platform: ${info.platform} Platform: ${info.platform}
WhatsApp version: ${info.phone.wa_version} WhatsApp version: ${info.phone.wa_version}
`); `);
} else if (msg.body == '!mediainfo' && msg.hasMedia) { } else if (msg.body === '!mediainfo' && msg.hasMedia) {
const attachmentData = await msg.downloadMedia(); const attachmentData = await msg.downloadMedia();
msg.reply(` msg.reply(`
*Media info* *Media info*
@@ -129,7 +129,7 @@ client.on('message', async msg => {
Filename: ${attachmentData.filename} Filename: ${attachmentData.filename}
Data (length): ${attachmentData.data.length} Data (length): ${attachmentData.data.length}
`); `);
} else if (msg.body == '!quoteinfo' && msg.hasQuotedMsg) { } else if (msg.body === '!quoteinfo' && msg.hasQuotedMsg) {
const quotedMsg = await msg.getQuotedMessage(); const quotedMsg = await msg.getQuotedMessage();
quotedMsg.reply(` quotedMsg.reply(`
@@ -139,13 +139,13 @@ client.on('message', async msg => {
Timestamp: ${quotedMsg.timestamp} Timestamp: ${quotedMsg.timestamp}
Has Media? ${quotedMsg.hasMedia} Has Media? ${quotedMsg.hasMedia}
`); `);
} else if (msg.body == '!resendmedia' && msg.hasQuotedMsg) { } else if (msg.body === '!resendmedia' && msg.hasQuotedMsg) {
const quotedMsg = await msg.getQuotedMessage(); const quotedMsg = await msg.getQuotedMessage();
if (quotedMsg.hasMedia) { if (quotedMsg.hasMedia) {
const attachmentData = await quotedMsg.downloadMedia(); const attachmentData = await quotedMsg.downloadMedia();
client.sendMessage(msg.from, attachmentData, { caption: 'Here\'s your requested media.' }); client.sendMessage(msg.from, attachmentData, { caption: 'Here\'s your requested media.' });
} }
} else if (msg.body == '!location') { } else if (msg.body === '!location') {
msg.reply(new Location(37.422, -122.084, 'Googleplex\nGoogle Headquarters')); msg.reply(new Location(37.422, -122.084, 'Googleplex\nGoogle Headquarters'));
} else if (msg.location) { } else if (msg.location) {
msg.reply(msg.location); msg.reply(msg.location);
@@ -153,18 +153,20 @@ client.on('message', async msg => {
const newStatus = msg.body.split(' ')[1]; const newStatus = msg.body.split(' ')[1];
await client.setStatus(newStatus); await client.setStatus(newStatus);
msg.reply(`Status was updated to *${newStatus}*`); msg.reply(`Status was updated to *${newStatus}*`);
} else if (msg.body == '!mention') { } else if (msg.body === '!mention') {
const contact = await msg.getContact(); const contact = await msg.getContact();
const chat = await msg.getChat(); const chat = await msg.getChat();
chat.sendMessage(`Hi @${contact.number}!`, { chat.sendMessage(`Hi @${contact.number}!`, {
mentions: [contact] mentions: [contact]
}); });
} else if (msg.body == '!delete' && msg.hasQuotedMsg) { } else if (msg.body === '!delete') {
const quotedMsg = await msg.getQuotedMessage(); if (msg.hasQuotedMsg) {
if (quotedMsg.fromMe) { const quotedMsg = await msg.getQuotedMessage();
quotedMsg.delete(true); if (quotedMsg.fromMe) {
} else { quotedMsg.delete(true);
msg.reply('I can only delete my own messages'); } else {
msg.reply('I can only delete my own messages');
}
} }
} else if (msg.body === '!pin') { } else if (msg.body === '!pin') {
const chat = await msg.getChat(); const chat = await msg.getChat();
@@ -181,15 +183,20 @@ client.on('message', async msg => {
} else if (msg.body === '!typing') { } else if (msg.body === '!typing') {
const chat = await msg.getChat(); const chat = await msg.getChat();
// simulates typing in the chat // simulates typing in the chat
chat.sendStateTyping(); chat.sendStateTyping();
} else if (msg.body === '!recording') { } else if (msg.body === '!recording') {
const chat = await msg.getChat(); const chat = await msg.getChat();
// simulates recording audio in the chat // simulates recording audio in the chat
chat.sendStateRecording(); chat.sendStateRecording();
} else if (msg.body === '!clearstate') { } else if (msg.body === '!clearstate') {
const chat = await msg.getChat(); const chat = await msg.getChat();
// stops typing or recording in the chat // stops typing or recording in the chat
chat.clearState(); chat.clearState();
} else if (msg.body === 'jumpto') {
if (msg.hasQuotedMsg) {
const quotedMsg = await msg.getQuotedMessage();
client.interface.openChatWindowAt(quotedMsg.id._serialized);
}
} }
}); });

View File

@@ -31,6 +31,28 @@ class InterfaceController {
}, chatId); }, chatId);
} }
/**
* Opens the Chat Search
* @param {string} chatId ID of the chat search that will be opened
*/
async openChatSearch(chatId) {
await this.pupPage.evaluate(async chatId => {
let chat = await window.Store.Chat.get(chatId);
await window.Store.Cmd.chatSearch(chat);
}, chatId);
}
/**
* Opens or Scrolls the Chat Window to the position of the message
* @param {string} msgId ID of the message that will be scrolled to
*/
async openChatWindowAt(msgId) {
await this.pupPage.evaluate(async msgId => {
let msg = await window.Store.Msg.get(msgId);
await window.Store.Cmd.openChatAt(msg.chat, msg.chat.getSearchContext(msg));
}, msgId);
}
/** /**
* Opens the Message Drawer * Opens the Message Drawer
* @param {string} msgId ID of the message drawer that will be opened * @param {string} msgId ID of the message drawer that will be opened