Skip to content

Commit

Permalink
feat(parser): Update LiveChatViewerEngagementMessage (#856)
Browse files Browse the repository at this point in the history
Update `LiveChatViewerEngagementMessage` to extend `YTNode` rather than
`LiveChatMessageBase` to better align with the latest data provided by
Innertube.
  • Loading branch information
jonz94 authored Dec 31, 2024
1 parent 0054690 commit b4a947a
Showing 1 changed file with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,47 @@
import { Parser } from '../../../index.js';
import { LiveChatMessageBase } from './LiveChatTextMessage.js';
import type { RawNode } from '../../../index.js';
import type { YTNode } from '../../../helpers.js';
import { YTNode } from '../../../helpers.js';
import NavigationEndpoint from '../../NavigationEndpoint.js';
import Text from '../../misc/Text.js';

export default class LiveChatViewerEngagementMessage extends LiveChatMessageBase {
export default class LiveChatViewerEngagementMessage extends YTNode {
static type = 'LiveChatViewerEngagementMessage';

id: string;
timestamp?: number;
timestamp_usec?: string;
icon_type?: string;
action_button: YTNode;
message: Text;
action_button: YTNode | null;
menu_endpoint?: NavigationEndpoint;
context_menu_accessibility_label?: string;

constructor(data: RawNode) {
super(data);
super();
this.id = data.id;

if (Reflect.has(data, 'timestampUsec')) {
this.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000);
this.timestamp_usec = data.timestampUsec;
}

if (Reflect.has(data, 'icon') && Reflect.has(data.icon, 'iconType')) {
this.icon_type = data.icon.iconType;
}

this.message = new Text(data.message);
this.action_button = Parser.parseItem(data.actionButton);

if (Reflect.has(data, 'contextMenuEndpoint')) {
this.menu_endpoint = new NavigationEndpoint(data.contextMenuEndpoint);
}

if (
Reflect.has(data, 'contextMenuAccessibility') &&
Reflect.has(data.contextMenuAccessibility, 'accessibilityData') &&
Reflect.has(data.contextMenuAccessibility.accessibilityData, 'label')
) {
this.context_menu_accessibility_label = data.contextMenuAccessibility.accessibilityData.label;
}
}
}

0 comments on commit b4a947a

Please sign in to comment.