-
-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser): Update
LiveChatViewerEngagementMessage
(#856)
Update `LiveChatViewerEngagementMessage` to extend `YTNode` rather than `LiveChatMessageBase` to better align with the latest data provided by Innertube.
- Loading branch information
Showing
1 changed file
with
33 additions
and
5 deletions.
There are no files selected for viewing
38 changes: 33 additions & 5 deletions
38
src/parser/classes/livechat/items/LiveChatViewerEngagementMessage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |