node-groupme
Version:
The only GroupMe API library that isn't a million years old.
42 lines • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("..");
class ChatManager extends __1.BaseManager {
constructor(client) {
super(client, __1.Chat);
}
fetch(ids) {
throw new Error('Method not implemented.');
}
async fetchChats(options) {
const apiParams = {};
if (options) {
// If no pagination is specified, recursively fetch all chats
if (options.page === undefined && options.per_page === undefined) {
let batch, i = 1;
do
batch = await this.fetchChats({ page: i++ });
while (batch.size);
return this.cache;
}
// Translate the options into valid API parameters
if (options.page != undefined)
apiParams.page = options.page;
if (options.per_page != undefined)
apiParams.per_page = options.per_page;
}
const batch = new __1.Collection();
const chats = await this.client.rest.api('GET', 'chats', { query: apiParams });
chats.forEach(data => {
const chat = this._upsert(new __1.Chat(this.client, this.client.users._add({
id: data.other_user.id,
name: data.other_user.name,
avatar_url: data.other_user.avatar_url,
}), data));
batch.set(chat.recipient.id, chat);
});
return batch;
}
}
exports.default = ChatManager;
//# sourceMappingURL=ChatManager.js.map