Get Stories (#3294)
* Get all broadcast * fixed return msgs * feat: add usage example * Update src/structures/Broadcast.js Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com> --------- Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
This commit is contained in:
parent
289b354285
commit
5b0e139ad4
1 changed files with 125 additions and 2 deletions
69
src/structures/Broadcast.js
Normal file
69
src/structures/Broadcast.js
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
'use strict';
|
||||
|
||||
const Base = require('./Base');
|
||||
const Message = require('./Message');
|
||||
|
||||
/**
|
||||
* Represents a Status/Story on WhatsApp
|
||||
* @extends {Base}
|
||||
*/
|
||||
class Broadcast extends Base {
|
||||
constructor(client, data) {
|
||||
super(client);
|
||||
|
||||
if (data) this._patch(data);
|
||||
}
|
||||
|
||||
_patch(data) {
|
||||
/**
|
||||
* ID that represents the chat
|
||||
* @type {object}
|
||||
*/
|
||||
this.id = data.id;
|
||||
|
||||
/**
|
||||
* Unix timestamp of last status
|
||||
* @type {number}
|
||||
*/
|
||||
this.timestamp = data.t;
|
||||
|
||||
/**
|
||||
* Number of available statuses
|
||||
* @type {number}
|
||||
*/
|
||||
this.totalCount = data.totalCount;
|
||||
|
||||
/**
|
||||
* Number of not viewed
|
||||
* @type {number}
|
||||
*/
|
||||
this.unreadCount = data.unreadCount;
|
||||
|
||||
/**
|
||||
* Messages statuses
|
||||
* @type {Message[]}
|
||||
*/
|
||||
this.msgs = data.msgs.map(msg => new Message(this.client, msg));
|
||||
|
||||
return super._patch(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Chat this message was sent in
|
||||
* @returns {Promise<Chat>}
|
||||
*/
|
||||
getChat() {
|
||||
return this.client.getChatById(this.id._serialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Contact this message was sent from
|
||||
* @returns {Promise<Contact>}
|
||||
*/
|
||||
getContact() {
|
||||
return this.client.getContactById(this.id._serialized);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Broadcast;
|
||||
Loading…
Reference in a new issue