diff --git a/example.js b/example.js index 9e5eec5..7187b6f 100644 --- a/example.js +++ b/example.js @@ -270,3 +270,14 @@ client.on('disconnected', (reason) => { console.log('Client was logged out', reason); }); +client.on('group_admin_changed', (notification) => { + if (notification.type === 'promote') { + /** + * Emitted when a current user is promoted to an admin. + * {@link notification.author} is a user who performs the action of promoting/demoting the current user. + */ + console.log(`You were promoted by ${notification.author}`); + } else if (notification.type === 'demote') + /** Emitted when a current user is demoted to a regular user. */ + console.log(`You were demoted by ${notification.author}`); +}); diff --git a/index.d.ts b/index.d.ts index ec7ff4c..1e94099 100644 --- a/index.d.ts +++ b/index.d.ts @@ -198,6 +198,12 @@ declare namespace WAWebJS { notification: GroupNotification ) => void): this + /** Emitted when a current user is promoted to an admin or demoted to a regular user */ + on(event: 'group_admin_changed', listener: ( + /** GroupNotification with more information about the action */ + notification: GroupNotification + ) => void): this + /** Emitted when group settings are updated, such as subject, description or picture */ on(event: 'group_update', listener: ( /** GroupNotification with more information about the action */ @@ -512,6 +518,7 @@ declare namespace WAWebJS { MEDIA_UPLOADED = 'media_uploaded', GROUP_JOIN = 'group_join', GROUP_LEAVE = 'group_leave', + GROUP_ADMIN_CHANGED = 'group_admin_changed', GROUP_UPDATE = 'group_update', QR_RECEIVED = 'qr', LOADING_SCREEN = 'loading_screen', diff --git a/src/Client.js b/src/Client.js index acd04ac..586fee8 100644 --- a/src/Client.js +++ b/src/Client.js @@ -45,6 +45,7 @@ const NoAuth = require('./authStrategies/NoAuth'); * @fires Client#group_update * @fires Client#disconnected * @fires Client#change_state + * @fires Client#group_admin_changed */ class Client extends EventEmitter { constructor(options = {}) { @@ -317,6 +318,13 @@ class Client extends EventEmitter { * @param {GroupNotification} notification GroupNotification with more information about the action */ this.emit(Events.GROUP_LEAVE, notification); + } else if (msg.subtype === 'promote' || msg.subtype === 'demote') { + /** + * Emitted when a current user is promoted to an admin or demoted to a regular user. + * @event Client#group_admin_changed + * @param {GroupNotification} notification GroupNotification with more information about the action + */ + this.emit(Events.GROUP_ADMIN_CHANGED, notification); } else { /** * Emitted when group settings are updated, such as subject, description or picture. diff --git a/src/util/Constants.js b/src/util/Constants.js index e341b4c..39c85df 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -46,6 +46,7 @@ exports.Events = { MEDIA_UPLOADED: 'media_uploaded', GROUP_JOIN: 'group_join', GROUP_LEAVE: 'group_leave', + GROUP_ADMIN_CHANGED: 'group_admin_changed', GROUP_UPDATE: 'group_update', QR_RECEIVED: 'qr', LOADING_SCREEN: 'loading_screen',