diff --git a/packages/api/src/endpoints/channel/HelixChannelApi.ts b/packages/api/src/endpoints/channel/HelixChannelApi.ts index 4b9030da..98880fc8 100644 --- a/packages/api/src/endpoints/channel/HelixChannelApi.ts +++ b/packages/api/src/endpoints/channel/HelixChannelApi.ts @@ -368,7 +368,7 @@ export class HelixChannelApi extends BaseApi { user: UserIdResolvable, broadcaster?: UserIdResolvable, pagination?: HelixForwardPagination - ): Promise> { + ): Promise> { const result = await this._client.callApi>({ type: 'helix', url: 'channels/followed', diff --git a/packages/api/src/endpoints/user/HelixUser.ts b/packages/api/src/endpoints/user/HelixUser.ts index 5c2bc6c8..880610ca 100644 --- a/packages/api/src/endpoints/user/HelixUser.ts +++ b/packages/api/src/endpoints/user/HelixUser.ts @@ -4,9 +4,10 @@ import { DataObject, rawDataSymbol, rtfm } from '@twurple/common'; 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 HelixChannelFollower } from '../channel/HelixChannelFollower'; +import { type HelixFollowedChannel } from '../channel/HelixFollowedChannel'; import type { HelixStream } from '../stream/HelixStream'; import { type HelixUserSubscription } from '../subscriptions/HelixUserSubscription'; -import type { HelixFollow } from './HelixFollow'; /** * A Twitch user. @@ -98,59 +99,67 @@ export class HelixUser extends DataObject implements UserIdResolv /** * Gets a list of broadcasters the user follows. - * - * @deprecated Use {@link HelixChannelApi#getFollowedChannels} instead. */ - async getFollows(): Promise> { - return await this._client.users.getFollows({ user: this }); + async getFollowedChannels(): Promise> { + return await this._client.channels.getFollowedChannels(this); } /** - * Gets the follow data of the given user to the broadcaster. + * Gets the follow data of the user to the given broadcaster, or `null` if the user doesn't follow the broadcaster. * - * @deprecated Use {@link HelixChannelApi#getChannelFollowers} - * or {@link HelixChannelApi#getFollowedChannels} instead. + * This requires user authentication. + * For broadcaster authentication, you can use `getChannelFollower` while switching `this` and the parameter. * - * @param user The user to check the follow from. + * @param broadcaster The broadcaster to check the follow to. */ - async getFollowFrom(user: UserIdResolvable): Promise { - return await this._client.users.getFollowFromUserToBroadcaster(user, this); + async getFollowedChannel(broadcaster: UserIdResolvable): Promise { + const result = await this._client.channels.getFollowedChannels(this, broadcaster); + + return result.data[0] ?? null; } /** - * Gets the follow data of the user to the given broadcaster. + * Checks whether the user is following the given broadcaster. * - * @deprecated Use {@link HelixChannelApi#getChannelFollowers} - * or {@link HelixChannelApi#getFollowedChannels} instead. + * This requires user authentication. + * For broadcaster authentication, you can use `isFollowedBy` while switching `this` and the parameter. * - * @param broadcaster The broadcaster to check the follow to. + * @param broadcaster The broadcaster to check the user's follow to. + */ + async follows(broadcaster: UserIdResolvable): Promise { + return (await this.getFollowedChannel(broadcaster)) !== null; + } + + /** + * Gets a list of users that follow the broadcaster. */ - async getFollowTo(broadcaster: UserIdResolvable): Promise { - return await this._client.users.getFollowFromUserToBroadcaster(this, broadcaster); + async getChannelFollowers(): Promise> { + return await this._client.channels.getChannelFollowers(this); } /** - * Checks whether the user is following the given broadcaster. + * Gets the follow data of the given user to the broadcaster, or `null` if the user doesn't follow the broadcaster. * - * @deprecated Use {@link HelixChannelApi#getChannelFollowers} - * or {@link HelixChannelApi#getFollowedChannels} instead. + * This requires broadcaster authentication. + * For user authentication, you can use `getFollowedChannel` while switching `this` and the parameter. * - * @param broadcaster The broadcaster to check the user's follow to. + * @param user The user to check the follow from. */ - async follows(broadcaster: UserIdResolvable): Promise { - return await this._client.users.userFollowsBroadcaster(this, broadcaster); + async getChannelFollower(user: UserIdResolvable): Promise { + const result = await this._client.channels.getChannelFollowers(this, user); + return result.data[0] ?? null; } /** * Checks whether the given user is following the broadcaster. * - * @deprecated Use {@link HelixChannelApi#getChannelFollowers} - * or {@link HelixChannelApi#getFollowedChannels} instead. + * This requires broadcaster authentication. + * For user authentication, you can use `follows` while switching `this` and the parameter. * * @param user The user to check the broadcaster's follow from. */ async isFollowedBy(user: UserIdResolvable): Promise { - return await this._client.users.userFollowsBroadcaster(user, this); + return (await this.getChannelFollower(user)) !== null; } /**