mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 04:29:15 +00:00
Feat: Add chat_removed and chat_archived events (#1778)
* Add chat_removed and chat_archived events * Make eslint happy --------- Co-authored-by: Rajeh Taher <rajeh@reforward.dev> Co-authored-by: Aliyss Snow <33941859+Aliyss@users.noreply.github.com>
This commit is contained in:
16
index.d.ts
vendored
16
index.d.ts
vendored
@@ -265,6 +265,22 @@ declare namespace WAWebJS {
|
|||||||
reaction: Reaction
|
reaction: Reaction
|
||||||
) => void): this
|
) => void): this
|
||||||
|
|
||||||
|
/** Emitted when a chat is removed */
|
||||||
|
on(event: 'chat_removed', listener: (
|
||||||
|
/** The chat that was removed */
|
||||||
|
chat: Chat
|
||||||
|
) => void): this
|
||||||
|
|
||||||
|
/** Emitted when a chat is archived/unarchived */
|
||||||
|
on(event: 'chat_archived', listener: (
|
||||||
|
/** The chat that was archived/unarchived */
|
||||||
|
chat: Chat,
|
||||||
|
/** State the chat is currently in */
|
||||||
|
currState: boolean,
|
||||||
|
/** State the chat was previously in */
|
||||||
|
prevState: boolean
|
||||||
|
) => void): this
|
||||||
|
|
||||||
/** Emitted when loading screen is appearing */
|
/** Emitted when loading screen is appearing */
|
||||||
on(event: 'loading_screen', listener: (percent: string, message: string) => void): this
|
on(event: 'loading_screen', listener: (percent: string, message: string) => void): this
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const { WhatsWebURL, DefaultOptions, Events, WAState } = require('./util/Constan
|
|||||||
const { ExposeStore, LoadUtils } = require('./util/Injected');
|
const { ExposeStore, LoadUtils } = require('./util/Injected');
|
||||||
const ChatFactory = require('./factories/ChatFactory');
|
const ChatFactory = require('./factories/ChatFactory');
|
||||||
const ContactFactory = require('./factories/ContactFactory');
|
const ContactFactory = require('./factories/ContactFactory');
|
||||||
const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification, Label, Call, Buttons, List, Reaction } = require('./structures');
|
const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification, Label, Call, Buttons, List, Reaction, Chat } = require('./structures');
|
||||||
const LegacySessionAuth = require('./authStrategies/LegacySessionAuth');
|
const LegacySessionAuth = require('./authStrategies/LegacySessionAuth');
|
||||||
const NoAuth = require('./authStrategies/NoAuth');
|
const NoAuth = require('./authStrategies/NoAuth');
|
||||||
|
|
||||||
@@ -524,6 +524,26 @@ class Client extends EventEmitter {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await page.exposeFunction('onRemoveChatEvent', (chat) => {
|
||||||
|
/**
|
||||||
|
* Emitted when a chat is removed
|
||||||
|
* @event Client#chat_removed
|
||||||
|
* @param {Chat} chat
|
||||||
|
*/
|
||||||
|
this.emit(Events.CHAT_REMOVED, new Chat(this, chat));
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.exposeFunction('onArchiveChatEvent', (chat, currState, prevState) => {
|
||||||
|
/**
|
||||||
|
* Emitted when a chat is archived/unarchived
|
||||||
|
* @event Client#chat_archived
|
||||||
|
* @param {Chat} chat
|
||||||
|
* @param {boolean} currState
|
||||||
|
* @param {boolean} prevState
|
||||||
|
*/
|
||||||
|
this.emit(Events.CHAT_ARCHIVED, new Chat(this, chat), currState, prevState);
|
||||||
|
});
|
||||||
|
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(window.WWebJS.getMessageModel(msg)); });
|
window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(window.WWebJS.getMessageModel(msg)); });
|
||||||
window.Store.Msg.on('change:type', (msg) => { window.onChangeMessageTypeEvent(window.WWebJS.getMessageModel(msg)); });
|
window.Store.Msg.on('change:type', (msg) => { window.onChangeMessageTypeEvent(window.WWebJS.getMessageModel(msg)); });
|
||||||
@@ -533,6 +553,8 @@ class Client extends EventEmitter {
|
|||||||
window.Store.AppState.on('change:state', (_AppState, state) => { window.onAppStateChangedEvent(state); });
|
window.Store.AppState.on('change:state', (_AppState, state) => { window.onAppStateChangedEvent(state); });
|
||||||
window.Store.Conn.on('change:battery', (state) => { window.onBatteryStateChangedEvent(state); });
|
window.Store.Conn.on('change:battery', (state) => { window.onBatteryStateChangedEvent(state); });
|
||||||
window.Store.Call.on('add', (call) => { window.onIncomingCall(call); });
|
window.Store.Call.on('add', (call) => { window.onIncomingCall(call); });
|
||||||
|
window.Store.Chat.on('remove', async (chat) => { window.onRemoveChatEvent(await window.WWebJS.getChatModel(chat)); });
|
||||||
|
window.Store.Chat.on('change:archive', async (chat, currState, prevState) => { window.onArchiveChatEvent(await window.WWebJS.getChatModel(chat), currState, prevState); });
|
||||||
window.Store.Msg.on('add', (msg) => {
|
window.Store.Msg.on('add', (msg) => {
|
||||||
if (msg.isNewMsg) {
|
if (msg.isNewMsg) {
|
||||||
if(msg.type === 'ciphertext') {
|
if(msg.type === 'ciphertext') {
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ exports.Events = {
|
|||||||
AUTHENTICATED: 'authenticated',
|
AUTHENTICATED: 'authenticated',
|
||||||
AUTHENTICATION_FAILURE: 'auth_failure',
|
AUTHENTICATION_FAILURE: 'auth_failure',
|
||||||
READY: 'ready',
|
READY: 'ready',
|
||||||
|
CHAT_REMOVED: 'chat_removed',
|
||||||
|
CHAT_ARCHIVED: 'chat_archived',
|
||||||
MESSAGE_RECEIVED: 'message',
|
MESSAGE_RECEIVED: 'message',
|
||||||
MESSAGE_CREATE: 'message_create',
|
MESSAGE_CREATE: 'message_create',
|
||||||
MESSAGE_REVOKED_EVERYONE: 'message_revoke_everyone',
|
MESSAGE_REVOKED_EVERYONE: 'message_revoke_everyone',
|
||||||
|
|||||||
Reference in New Issue
Block a user