Skip to content

Commit

Permalink
refactor: attempt to replace author_* fields with a single Author
Browse files Browse the repository at this point in the history
… class
  • Loading branch information
jonz94 committed Nov 1, 2024
1 parent f563b9b commit af4442d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import { YTNode } from '../../../helpers.js';
import { Parser, type RawNode } from '../../../index.js';
import Author from '../../misc/Author.js';
import LiveChatSponsorshipsHeader from './LiveChatSponsorshipsHeader.js';

export default class LiveChatSponsorshipsGiftPurchaseAnnouncement extends YTNode {
static type = 'LiveChatSponsorshipsGiftPurchaseAnnouncement';

id: string;
timestamp_usec: string;
author_external_channel_id: string;
author: Author;
header: LiveChatSponsorshipsHeader | null;

constructor(data: RawNode) {
super();
this.id = data.id;
this.timestamp_usec = data.timestampUsec;
this.author_external_channel_id = data.authorExternalChannelId;

this.author = new Author(
data.header.liveChatSponsorshipsHeaderRenderer.authorName,
data.header.liveChatSponsorshipsHeaderRenderer.authorBadges,
data.header.liveChatSponsorshipsHeaderRenderer.authorPhoto,
data.authorExternalChannelId
);

this.header = Parser.parseItem(data.header, LiveChatSponsorshipsHeader);
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
import { Parser } from '../../../index.js';
import { YTNode } from '../../../helpers.js';
import type { ObservedArray } from '../../../helpers.js';
import type { RawNode } from '../../../index.js';
import NavigationEndpoint from '../../NavigationEndpoint.js';
import Text from '../../misc/Text.js';
import Thumbnail from '../../misc/Thumbnail.js';
import LiveChatAuthorBadge from '../../LiveChatAuthorBadge.js';

export default class LiveChatSponsorshipsHeader extends YTNode {
static type = 'LiveChatSponsorshipsHeader';

author_name: Text;
author_photo: Thumbnail[];
primary_text: Text;
author_badges: ObservedArray<LiveChatAuthorBadge> | null;
menu_endpoint: NavigationEndpoint;
context_menu_accessibility_label: string;
image: Thumbnail[];

constructor(data: RawNode) {
super();
this.author_name = new Text(data.authorName);
this.author_photo = Thumbnail.fromResponse(data.authorPhoto);
this.primary_text = new Text(data.primaryText);
this.author_badges = Parser.parse(data.authorBadges, true, LiveChatAuthorBadge);
this.menu_endpoint = new NavigationEndpoint(data.contextMenuEndpoint);
this.context_menu_accessibility_label = data.contextMenuAccessibility.accessibilityData.label;
this.image = Thumbnail.fromResponse(data.image);
Expand Down

0 comments on commit af4442d

Please sign in to comment.