Files
YouTube.js/lib/parser/youtube/NotificationsMenu.js
LuanRT 68cb841c00 refactor!: finish parser migration
Finally! :)

This removes all code related to the old parser.

#65
2022-07-11 06:19:10 -03:00

46 lines
1.2 KiB
JavaScript

'use strict';
const Parser = require('..');
const { InnertubeError } = require('../../utils/Utils');
class NotificationsMenu {
#page;
#actions;
#continuation;
/**
* @param {import('../../core/Actions')} actions
* @param {object} response - API response.
*/
constructor(actions, response) {
this.#actions = actions;
this.#page = Parser.parseResponse(response);
/** @type {import('../classes/menus/SimpleMenuHeader')} */
this.header = this.#page.actions_memo.get('SimpleMenuHeader')?.[0] || null;
/** @type {import('../classes/Notification')} */
this.contents = this.#page.actions_memo.get('Notification');
}
/**
* Retrieves next batch of notifications.
* @returns {Promise.<NotificationsMenu>}
*/
async getContinuation() {
const continuation = this.#page.actions_memo.get('ContinuationItem')?.[0];
if (!continuation)
throw new InnertubeError('Continuation not found');
const response = await continuation.endpoint.callTest(this.#actions, { parse: false });
return new NotificationsMenu(this.#actions, response.data);
}
get page() {
return this.#page;
}
}
module.exports = NotificationsMenu;