Skip to content

Commit

Permalink
feat(parser): Update LiveChatTextMessage
Browse files Browse the repository at this point in the history
Update `LiveChatTextMessage` to extend `YTNode` rather than
`LiveChatMessageBase` to better align with the latest data
provided by Innertube.

- Add `timestamp_usec` property
- Add `timestamp_text` property
- Add `context_menu_accessibility_label` property
- Add `before_content_buttons` property
  • Loading branch information
jonz94 committed Jan 5, 2025
1 parent f3c777b commit a4c0d3a
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/parser/classes/livechat/items/LiveChatTextMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,36 @@ import { type ObservedArray, YTNode } from '../../../helpers.js';
import type { RawNode } from '../../../index.js';
import { Parser } from '../../../index.js';
import Button from '../../Button.js';
import ButtonView from '../../ButtonView.js';
import NavigationEndpoint from '../../NavigationEndpoint.js';
import Author from '../../misc/Author.js';
import Text from '../../misc/Text.js';

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

id: string;
message: Text;
inline_action_buttons: ObservedArray<Button>;
timestamp: number;
id: string;
timestamp_usec: number;
timestamp_text?: string;
author: Author;
menu_endpoint: NavigationEndpoint;
context_menu_accessibility_label: string;
before_content_buttons: ObservedArray<ButtonView>;

constructor(data: RawNode) {
super();
this.id = data.id;
this.message = new Text(data.message);
this.inline_action_buttons = Parser.parseArray(data.inlineActionButtons, Button);
this.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000);
this.id = data.id;
}
}

export default class LiveChatTextMessage extends LiveChatMessageBase {
static type = 'LiveChatTextMessage';
this.timestamp_usec = data.timestampUsec;

author: Author;
menu_endpoint: NavigationEndpoint;

constructor(data: RawNode) {
super(data);
if (Reflect.has(data, 'timestampText')) {
this.timestamp_text = new Text(data.timestampText).toString();
}

this.author = new Author(
data.authorName,
Expand All @@ -40,5 +41,7 @@ export default class LiveChatTextMessage extends LiveChatMessageBase {
);

this.menu_endpoint = new NavigationEndpoint(data.contextMenuEndpoint);
this.context_menu_accessibility_label = data.contextMenuAccessibility.accessibilityData.label;
this.before_content_buttons = Parser.parseArray(data.beforeContentButtons, ButtonView);
}
}

0 comments on commit a4c0d3a

Please sign in to comment.