Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parser): Update LiveChatTextMessage #864

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading