From c9bd952c2a650be7a68c3d9f5c38be809aa3a086 Mon Sep 17 00:00:00 2001 From: alina sireneva Date: Sat, 25 Jan 2025 13:17:16 +0300 Subject: [PATCH] fix(core): deprecated getStarGifts method --- .../methods/premium/get-saved-star-gifts.ts | 6 +- .../methods/premium/get-star-gifts.ts | 25 ++---- .../types/premium/saved-star-gift.ts | 5 ++ .../src/highlevel/types/premium/stars-gift.ts | 87 ------------------- 4 files changed, 17 insertions(+), 106 deletions(-) diff --git a/packages/core/src/highlevel/methods/premium/get-saved-star-gifts.ts b/packages/core/src/highlevel/methods/premium/get-saved-star-gifts.ts index 58bcc7ae..4e5a5671 100644 --- a/packages/core/src/highlevel/methods/premium/get-saved-star-gifts.ts +++ b/packages/core/src/highlevel/methods/premium/get-saved-star-gifts.ts @@ -5,7 +5,11 @@ import { SavedStarGift } from '../../types/premium/saved-star-gift.js' import { makeArrayPaginated } from '../../utils/misc-utils.js' import { resolvePeer } from '../users/resolve-peer.js' -/** Get a list of saved star gifts of a user */ +/** + * Get a list of saved star gifts of a user/channel + * + * Note that filters currently only work for channels + */ export async function getSavedStarGifts( client: ITelegramClient, params: { diff --git a/packages/core/src/highlevel/methods/premium/get-star-gifts.ts b/packages/core/src/highlevel/methods/premium/get-star-gifts.ts index ad74ca26..333e59a2 100644 --- a/packages/core/src/highlevel/methods/premium/get-star-gifts.ts +++ b/packages/core/src/highlevel/methods/premium/get-star-gifts.ts @@ -1,16 +1,14 @@ import type { ITelegramClient } from '../../client.types.js' +import type { SavedStarGift } from '../../types/index.js' import type { InputPeerLike } from '../../types/peers/peer.js' import type { ArrayPaginated } from '../../types/utils.js' -import { PeersIndex } from '../../types/peers/peers-index.js' -import { UserStarGift } from '../../types/premium/stars-gift.js' -import { makeArrayPaginated } from '../../utils/misc-utils.js' -import { resolveUser } from '../users/resolve-peer.js' +import { getSavedStarGifts } from './get-saved-star-gifts.js' -// @available=user /** * Get a list of gifts sent to a user. * * @param userId User whose gifts to fetch + * @deprecated Use {@link getSavedStarGifts} instead * @returns Gifts sent to the user */ export async function getStarGifts( @@ -29,18 +27,9 @@ export async function getStarGifts( */ limit?: number }, -): Promise> { - const { offset = '', limit = 100 } = params ?? {} - - const res = await client.call({ - _: 'payments.getUserStarGifts', - userId: await resolveUser(client, userId), - offset, - limit, +): Promise> { + return getSavedStarGifts(client, { + owner: userId, + ...params, }) - - const peers = PeersIndex.from(res) - const gifts = res.gifts.map(gift => new UserStarGift(gift, peers)) - - return makeArrayPaginated(gifts, res.count, res.nextOffset) } diff --git a/packages/core/src/highlevel/types/premium/saved-star-gift.ts b/packages/core/src/highlevel/types/premium/saved-star-gift.ts index c4b0f178..3d2b912d 100644 --- a/packages/core/src/highlevel/types/premium/saved-star-gift.ts +++ b/packages/core/src/highlevel/types/premium/saved-star-gift.ts @@ -91,3 +91,8 @@ export class SavedStarGift { makeInspectable(SavedStarGift) memoizeGetters(SavedStarGift, ['sender', 'gift']) + +export { + /** @deprecated alias for {@link SavedStarGift} */ + SavedStarGift as UserStarGift, +} diff --git a/packages/core/src/highlevel/types/premium/stars-gift.ts b/packages/core/src/highlevel/types/premium/stars-gift.ts index 95d8c6d6..1e1c654f 100644 --- a/packages/core/src/highlevel/types/premium/stars-gift.ts +++ b/packages/core/src/highlevel/types/premium/stars-gift.ts @@ -2,17 +2,12 @@ import type { tl } from '@mtcute/tl' import type { Sticker } from '../media/sticker.js' import type { Message } from '../messages/message.js' -import type { TextWithEntities } from '../misc/entities.js' import type { InputPeerLike } from '../peers/peer.js' -import type { PeersIndex } from '../peers/peers-index.js' -import Long from 'long' import { MtTypeAssertionError } from '../../../types/errors.js' import { assertTypeIs } from '../../../utils/type-assertions.js' import { makeInspectable } from '../../utils/inspectable.js' import { memoizeGetters } from '../../utils/memoize.js' import { parseDocument } from '../media/document-utils.js' -import { User } from '../peers/user.js' -import { StarGiftUnique } from './stars-gift-unique.js' export type InputStarGift = | { @@ -116,85 +111,3 @@ export class StarGift { makeInspectable(StarGift) memoizeGetters(StarGift, ['sticker']) - -/** - * Information about a certain user's {@link StarGift}. - */ -export class UserStarGift { - constructor( - readonly raw: tl.RawUserStarGift, - readonly peers: PeersIndex, - ) {} - - /** Whether the sender chose to appear anonymously */ - get nameHidden(): boolean { - return this.raw.nameHidden! - } - - /** Whether this gift is not visible on the recipient's profile */ - get hidden(): boolean { - return this.raw.unsaved! - } - - get isRefunded(): boolean { - return this.raw.refunded! - } - - /** Sender of the gift, if available */ - get sender(): User | null { - return this.raw.fromId ? new User(this.peers.user(this.raw.fromId)) : null - } - - /** Message ID where the gift was sent, if available */ - get messageId(): number | null { - return this.raw.msgId ?? null - } - - /** Date the gift was sent or minted */ - get date(): Date { - return new Date(this.raw.date * 1000) - } - - /** Whether the gift can be upgraded to a unique gift */ - get canUpgrade(): boolean { - return this.raw.canUpgrade! - } - - /** Number of stars to upgrade the gift to a unique gift (may be 0) */ - get upgradeStars(): tl.Long | null { - if (!this.raw.canUpgrade) return null - return this.raw.upgradeStars ?? Long.ZERO - } - - /** The gift itself */ - get gift(): StarGift | StarGiftUnique { - return this.raw.gift._ === 'starGift' - ? new StarGift(this.raw.gift) - : new StarGiftUnique(this.raw.gift, this.peers) - } - - /** Text attached to the gift */ - get text(): TextWithEntities | null { - return this.raw.message ?? null - } - - /** - * If the gift was converted to stars, the amount of stars - * it was converted to - */ - get convertStars(): tl.Long | null { - return this.raw.convertStars ?? null - } - - get canExportAt(): Date | null { - return this.raw.canExportAt ? new Date(this.raw.canExportAt * 1000) : null - } - - /** Number of stars this gift can be transferred for */ - get transferStars(): tl.Long | null { - return this.raw.transferStars ?? null - } -} - -makeInspectable(UserStarGift) -memoizeGetters(UserStarGift, ['sender', 'gift'])