mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
Merge branch 'main' into fix-buttons-list
This commit is contained in:
4
index.d.ts
vendored
4
index.d.ts
vendored
@@ -1062,6 +1062,10 @@ declare namespace WAWebJS {
|
||||
* Set this to Infinity to load all messages.
|
||||
*/
|
||||
limit?: number
|
||||
/**
|
||||
* Return only messages from the bot number or vise versa. To get all messages, leave the option undefined.
|
||||
*/
|
||||
fromMe?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,9 @@ try {
|
||||
var unzipper = require('unzipper');
|
||||
var archiver = require('archiver');
|
||||
} catch {
|
||||
throw new Error('Optional Dependencies [fs-extra, unzipper, archiver] are required to use RemoteAuth. Make sure to run npm install correctly and remove the --no-optional flag');
|
||||
fs = undefined;
|
||||
unzipper = undefined;
|
||||
archiver = undefined;
|
||||
}
|
||||
|
||||
const path = require('path');
|
||||
@@ -23,6 +25,7 @@ const BaseAuthStrategy = require('./BaseAuthStrategy');
|
||||
*/
|
||||
class RemoteAuth extends BaseAuthStrategy {
|
||||
constructor({ clientId, dataPath, store, backupSyncIntervalMs } = {}) {
|
||||
if (!fs && !unzipper && !archiver) throw new Error('Optional Dependencies [fs-extra, unzipper, archiver] are required to use RemoteAuth. Make sure to run npm install correctly and remove the --no-optional flag');
|
||||
super();
|
||||
|
||||
const idRegex = /^[-_\w]+$/i;
|
||||
@@ -198,4 +201,4 @@ class RemoteAuth extends BaseAuthStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RemoteAuth;
|
||||
module.exports = RemoteAuth;
|
||||
|
||||
@@ -170,13 +170,22 @@ class Chat extends Base {
|
||||
|
||||
/**
|
||||
* Loads chat messages, sorted from earliest to latest.
|
||||
* @param {Object} searchOptions Options for searching messages. Right now only limit is supported.
|
||||
* @param {Object} searchOptions Options for searching messages. Right now only limit and fromMe is supported.
|
||||
* @param {Number} [searchOptions.limit] The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.
|
||||
* @param {Boolean} [searchOptions.fromMe] Return only messages from the bot number or vise versa. To get all messages, leave the option undefined.
|
||||
* @returns {Promise<Array<Message>>}
|
||||
*/
|
||||
async fetchMessages(searchOptions) {
|
||||
let messages = await this.client.pupPage.evaluate(async (chatId, searchOptions) => {
|
||||
const msgFilter = m => !m.isNotification; // dont include notification messages
|
||||
const msgFilter = (m) => {
|
||||
if (m.isNotification) {
|
||||
return false; // dont include notification messages
|
||||
}
|
||||
if (searchOptions && searchOptions.fromMe && m.id.fromMe !== searchOptions.fromMe) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const chat = window.Store.Chat.get(chatId);
|
||||
let msgs = chat.msgs.getModelsArray().filter(msgFilter);
|
||||
|
||||
@@ -410,7 +410,7 @@ class Message extends Base {
|
||||
signal: (new AbortController).signal
|
||||
});
|
||||
|
||||
const data = window.WWebJS.arrayBufferToBase64(decryptedMedia);
|
||||
const data = await window.WWebJS.arrayBufferToBase64Async(decryptedMedia);
|
||||
|
||||
return {
|
||||
data,
|
||||
|
||||
@@ -756,6 +756,20 @@ exports.LoadUtils = () => {
|
||||
return window.btoa(binary);
|
||||
};
|
||||
|
||||
window.WWebJS.arrayBufferToBase64Async = (arrayBuffer) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const blob = new Blob([arrayBuffer], {
|
||||
type: 'application/octet-stream',
|
||||
});
|
||||
const fileReader = new FileReader();
|
||||
fileReader.onload = () => {
|
||||
const [, data] = fileReader.result.split(',');
|
||||
resolve(data);
|
||||
};
|
||||
fileReader.onerror = (e) => reject(e);
|
||||
fileReader.readAsDataURL(blob);
|
||||
});
|
||||
|
||||
window.WWebJS.getFileHash = async (data) => {
|
||||
let buffer = await data.arrayBuffer();
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', buffer);
|
||||
|
||||
Reference in New Issue
Block a user