Skip to content

Commit

Permalink
feat(SubscribeButton): Parse more endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Nov 13, 2024
1 parent 8ab760e commit 8bf9eb7
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions src/parser/classes/SubscribeButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@ import Text from './misc/Text.js';
export default class SubscribeButton extends YTNode {
static type = 'SubscribeButton';

title: Text;
subscribed: boolean;
enabled: boolean;
item_type: string;
channel_id: string;
show_preferences: boolean;
subscribed_text: Text;
unsubscribed_text: Text;
notification_preference_button: SubscriptionNotificationToggleButton | null;
endpoint: NavigationEndpoint;
public button_text: Text;
public subscribed: boolean;
public enabled: boolean;
public item_type: string;
public channel_id: string;
public show_preferences: boolean;
public subscribed_text: Text;
public unsubscribed_text: Text;
public notification_preference_button: SubscriptionNotificationToggleButton | null;
public service_endpoints?: NavigationEndpoint[];
public on_subscribe_endpoints?: NavigationEndpoint[];
public on_unsubscribe_endpoints?: NavigationEndpoint[];
public subscribed_entity_key?: string;
public target_id?: string;
public subscribe_accessibility_label?: string;
public unsubscribe_accessibility_label?: string;

constructor(data: RawNode) {
super();
this.title = new Text(data.buttonText);
this.button_text = new Text(data.buttonText);
this.subscribed = data.subscribed;
this.enabled = data.enabled;
this.item_type = data.type;
Expand All @@ -29,6 +35,26 @@ export default class SubscribeButton extends YTNode {
this.subscribed_text = new Text(data.subscribedButtonText);
this.unsubscribed_text = new Text(data.unsubscribedButtonText);
this.notification_preference_button = Parser.parseItem(data.notificationPreferenceButton, SubscriptionNotificationToggleButton);
this.endpoint = new NavigationEndpoint(data.serviceEndpoints?.[0] || data.onSubscribeEndpoints?.[0]);

if (Reflect.has(data, 'serviceEndpoints'))
this.service_endpoints = data.serviceEndpoints.map((endpoint: RawNode) => Parser.parseItem(endpoint, NavigationEndpoint));

if (Reflect.has(data, 'onSubscribeEndpoints'))
this.on_subscribe_endpoints = data.onSubscribeEndpoints.map((endpoint: RawNode) => Parser.parseItem(endpoint, NavigationEndpoint));

if (Reflect.has(data, 'onUnsubscribeEndpoints'))
this.on_unsubscribe_endpoints = data.onUnsubscribeEndpoints.map((endpoint: RawNode) => Parser.parseItem(endpoint, NavigationEndpoint));

if (Reflect.has(data, 'subscribedEntityKey'))
this.subscribed_entity_key = data.subscribedEntityKey;

if (Reflect.has(data, 'targetId'))
this.target_id = data.targetId;

if (Reflect.has(data, 'subscribeAccessibility'))
this.subscribe_accessibility_label = data.subscribeAccessibility.accessibilityData?.label;

if (Reflect.has(data, 'unsubscribeAccessibility'))
this.unsubscribe_accessibility_label = data.unsubscribeAccessibility.accessibilityData?.label;
}
}

0 comments on commit 8bf9eb7

Please sign in to comment.