From 3705c18782ef8c8258b5d37fc6672ea892ba5728 Mon Sep 17 00:00:00 2001 From: Daniel Fischer Date: Sat, 29 Apr 2023 13:07:26 +0200 Subject: [PATCH] invert subscription convenience method context logic fixes #488 --- packages/api/src/endpoints/user/HelixUser.ts | 36 ++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/api/src/endpoints/user/HelixUser.ts b/packages/api/src/endpoints/user/HelixUser.ts index 2ffa488c..5c2bc6c8 100644 --- a/packages/api/src/endpoints/user/HelixUser.ts +++ b/packages/api/src/endpoints/user/HelixUser.ts @@ -5,7 +5,7 @@ import { type BaseApiClient } from '../../client/BaseApiClient'; import { type HelixBroadcasterType, type HelixUserData } from '../../interfaces/endpoints/user.external'; import type { HelixPaginatedResultWithTotal } from '../../utils/pagination/HelixPaginatedResult'; import type { HelixStream } from '../stream/HelixStream'; -import type { HelixSubscription } from '../subscriptions/HelixSubscription'; +import { type HelixUserSubscription } from '../subscriptions/HelixUserSubscription'; import type { HelixFollow } from './HelixFollow'; /** @@ -156,18 +156,48 @@ export class HelixUser extends DataObject implements UserIdResolv /** * Gets the subscription data for the user to the given broadcaster, or `null` if the user is not subscribed. * + * This requires user authentication. + * For broadcaster authentication, you can use `getSubscriber` while switching `this` and the parameter. + * * @param broadcaster The broadcaster you want to get the subscription data for. */ - async getSubscriptionTo(broadcaster: UserIdResolvable): Promise { - return await this._client.subscriptions.getSubscriptionForUser(broadcaster, this); + async getSubscriptionTo(broadcaster: UserIdResolvable): Promise { + return await this._client.subscriptions.checkUserSubscription(this, broadcaster); } /** * Checks whether the user is subscribed to the given broadcaster. * + * This requires user authentication. + * For broadcaster authentication, you can use `hasSubscriber` while switching `this` and the parameter. + * * @param broadcaster The broadcaster you want to check the subscription for. */ async isSubscribedTo(broadcaster: UserIdResolvable): Promise { return (await this.getSubscriptionTo(broadcaster)) !== null; } + + /** + * Gets the subscription data for the given user to the broadcaster, or `null` if the user is not subscribed. + * + * This requires broadcaster authentication. + * For user authentication, you can use `getSubscriptionTo` while switching `this` and the parameter. + * + * @param user The user you want to get the subscription data for. + */ + async getSubscriber(user: UserIdResolvable): Promise { + return await this._client.subscriptions.getSubscriptionForUser(this, user); + } + + /** + * Checks whether the given user is subscribed to the broadcaster. + * + * This requires broadcaster authentication. + * For user authentication, you can use `isSubscribedTo` while switching `this` and the parameter. + * + * @param user The user you want to check the subscription for. + */ + async hasSubscriber(user: UserIdResolvable): Promise { + return (await this.getSubscriber(user)) !== null; + } }