feat: listen to group events (#90)

This allows you to listen for user joins or leaves, description updates, subject updates, picture updates, and group settings updates.

Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>
This commit is contained in:
Aliyss Snow
2020-03-01 19:32:58 +01:00
committed by GitHub
parent 588dc93c17
commit 48b9ae1e81
4 changed files with 154 additions and 2 deletions

View File

@@ -10,8 +10,7 @@ const { WhatsWebURL, UserAgent, DefaultOptions, Events, WAState } = require('./u
const { ExposeStore, LoadUtils } = require('./util/Injected');
const ChatFactory = require('./factories/ChatFactory');
const ContactFactory = require('./factories/ContactFactory');
const { ClientInfo, Message, MessageMedia, Location } = require('./structures');
const { ClientInfo, Message, MessageMedia, Location, GroupNotification } = require('./structures');
/**
* Starting point for interacting with the WhatsApp Web API
* @extends {EventEmitter}
@@ -146,6 +145,18 @@ class Client extends EventEmitter {
await page.exposeFunction('onAddMessageEvent', msg => {
if (!msg.isNewMsg) return;
if (msg.type === 'gp2') {
const notification = new GroupNotification(this, msg);
if (msg.subtype === 'add' || msg.subtype === 'invite') {
this.emit(Events.GROUP_JOIN, notification);
} else if (msg.subtype === 'remove' || msg.subtype === 'leave') {
this.emit(Events.GROUP_LEAVE, notification);
} else {
this.emit(Events.GROUP_UPDATE, notification);
}
return;
}
const message = new Message(this, msg);
/**