From af4442d898dabafbaf24f6c7978d686cb3b4d5b6 Mon Sep 17 00:00:00 2001 From: jonz94 Date: Sat, 2 Nov 2024 02:21:36 +0800 Subject: [PATCH] refactor: attempt to replace `author_*` fields with a single `Author` class --- .../LiveChatSponsorshipsGiftPurchaseAnnouncement.ts | 12 ++++++++++-- .../livechat/items/LiveChatSponsorshipsHeader.ts | 9 --------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/parser/classes/livechat/items/LiveChatSponsorshipsGiftPurchaseAnnouncement.ts b/src/parser/classes/livechat/items/LiveChatSponsorshipsGiftPurchaseAnnouncement.ts index 39f51f90a..12dd1118e 100644 --- a/src/parser/classes/livechat/items/LiveChatSponsorshipsGiftPurchaseAnnouncement.ts +++ b/src/parser/classes/livechat/items/LiveChatSponsorshipsGiftPurchaseAnnouncement.ts @@ -1,5 +1,6 @@ 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 { @@ -7,14 +8,21 @@ export default class LiveChatSponsorshipsGiftPurchaseAnnouncement extends YTNode 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); } } \ No newline at end of file diff --git a/src/parser/classes/livechat/items/LiveChatSponsorshipsHeader.ts b/src/parser/classes/livechat/items/LiveChatSponsorshipsHeader.ts index 8c2d4440c..5b3ddff5b 100644 --- a/src/parser/classes/livechat/items/LiveChatSponsorshipsHeader.ts +++ b/src/parser/classes/livechat/items/LiveChatSponsorshipsHeader.ts @@ -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 | 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);