fix(core): deprecated getStarGifts method
All checks were successful
Tests / test-deno (push) Successful in 1m42s
Tests / test-bun (push) Successful in 1m49s
Tests / test-node (node18) (push) Successful in 1m59s
Tests / test-node (node22) (push) Successful in 1m56s
Tests / test-node (node20) (push) Successful in 2m0s
Tests / test-web (chromium) (push) Successful in 1m59s
Tests / test-web (firefox) (push) Successful in 2m9s
Build and deploy typedoc / build (push) Successful in 5m47s
Tests / lint (push) Successful in 6m28s
Tests / e2e (push) Successful in 49s
Tests / e2e-deno (push) Successful in 2m4s
All checks were successful
Tests / test-deno (push) Successful in 1m42s
Tests / test-bun (push) Successful in 1m49s
Tests / test-node (node18) (push) Successful in 1m59s
Tests / test-node (node22) (push) Successful in 1m56s
Tests / test-node (node20) (push) Successful in 2m0s
Tests / test-web (chromium) (push) Successful in 1m59s
Tests / test-web (firefox) (push) Successful in 2m9s
Build and deploy typedoc / build (push) Successful in 5m47s
Tests / lint (push) Successful in 6m28s
Tests / e2e (push) Successful in 49s
Tests / e2e-deno (push) Successful in 2m4s
This commit is contained in:
parent
f8cd49e900
commit
c9bd952c2a
4 changed files with 17 additions and 106 deletions
|
@ -5,7 +5,11 @@ import { SavedStarGift } from '../../types/premium/saved-star-gift.js'
|
||||||
import { makeArrayPaginated } from '../../utils/misc-utils.js'
|
import { makeArrayPaginated } from '../../utils/misc-utils.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.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(
|
export async function getSavedStarGifts(
|
||||||
client: ITelegramClient,
|
client: ITelegramClient,
|
||||||
params: {
|
params: {
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
import type { ITelegramClient } from '../../client.types.js'
|
import type { ITelegramClient } from '../../client.types.js'
|
||||||
|
import type { SavedStarGift } from '../../types/index.js'
|
||||||
import type { InputPeerLike } from '../../types/peers/peer.js'
|
import type { InputPeerLike } from '../../types/peers/peer.js'
|
||||||
import type { ArrayPaginated } from '../../types/utils.js'
|
import type { ArrayPaginated } from '../../types/utils.js'
|
||||||
import { PeersIndex } from '../../types/peers/peers-index.js'
|
import { getSavedStarGifts } from './get-saved-star-gifts.js'
|
||||||
import { UserStarGift } from '../../types/premium/stars-gift.js'
|
|
||||||
import { makeArrayPaginated } from '../../utils/misc-utils.js'
|
|
||||||
import { resolveUser } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
// @available=user
|
|
||||||
/**
|
/**
|
||||||
* Get a list of gifts sent to a user.
|
* Get a list of gifts sent to a user.
|
||||||
*
|
*
|
||||||
* @param userId User whose gifts to fetch
|
* @param userId User whose gifts to fetch
|
||||||
|
* @deprecated Use {@link getSavedStarGifts} instead
|
||||||
* @returns Gifts sent to the user
|
* @returns Gifts sent to the user
|
||||||
*/
|
*/
|
||||||
export async function getStarGifts(
|
export async function getStarGifts(
|
||||||
|
@ -29,18 +27,9 @@ export async function getStarGifts(
|
||||||
*/
|
*/
|
||||||
limit?: number
|
limit?: number
|
||||||
},
|
},
|
||||||
): Promise<ArrayPaginated<UserStarGift, string>> {
|
): Promise<ArrayPaginated<SavedStarGift, string>> {
|
||||||
const { offset = '', limit = 100 } = params ?? {}
|
return getSavedStarGifts(client, {
|
||||||
|
owner: userId,
|
||||||
const res = await client.call({
|
...params,
|
||||||
_: 'payments.getUserStarGifts',
|
|
||||||
userId: await resolveUser(client, userId),
|
|
||||||
offset,
|
|
||||||
limit,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const peers = PeersIndex.from(res)
|
|
||||||
const gifts = res.gifts.map(gift => new UserStarGift(gift, peers))
|
|
||||||
|
|
||||||
return makeArrayPaginated(gifts, res.count, res.nextOffset)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,3 +91,8 @@ export class SavedStarGift {
|
||||||
|
|
||||||
makeInspectable(SavedStarGift)
|
makeInspectable(SavedStarGift)
|
||||||
memoizeGetters(SavedStarGift, ['sender', 'gift'])
|
memoizeGetters(SavedStarGift, ['sender', 'gift'])
|
||||||
|
|
||||||
|
export {
|
||||||
|
/** @deprecated alias for {@link SavedStarGift} */
|
||||||
|
SavedStarGift as UserStarGift,
|
||||||
|
}
|
||||||
|
|
|
@ -2,17 +2,12 @@ import type { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import type { Sticker } from '../media/sticker.js'
|
import type { Sticker } from '../media/sticker.js'
|
||||||
import type { Message } from '../messages/message.js'
|
import type { Message } from '../messages/message.js'
|
||||||
import type { TextWithEntities } from '../misc/entities.js'
|
|
||||||
import type { InputPeerLike } from '../peers/peer.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 { MtTypeAssertionError } from '../../../types/errors.js'
|
||||||
import { assertTypeIs } from '../../../utils/type-assertions.js'
|
import { assertTypeIs } from '../../../utils/type-assertions.js'
|
||||||
import { makeInspectable } from '../../utils/inspectable.js'
|
import { makeInspectable } from '../../utils/inspectable.js'
|
||||||
import { memoizeGetters } from '../../utils/memoize.js'
|
import { memoizeGetters } from '../../utils/memoize.js'
|
||||||
import { parseDocument } from '../media/document-utils.js'
|
import { parseDocument } from '../media/document-utils.js'
|
||||||
import { User } from '../peers/user.js'
|
|
||||||
import { StarGiftUnique } from './stars-gift-unique.js'
|
|
||||||
|
|
||||||
export type InputStarGift =
|
export type InputStarGift =
|
||||||
| {
|
| {
|
||||||
|
@ -116,85 +111,3 @@ export class StarGift {
|
||||||
|
|
||||||
makeInspectable(StarGift)
|
makeInspectable(StarGift)
|
||||||
memoizeGetters(StarGift, ['sticker'])
|
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'])
|
|
||||||
|
|
Loading…
Reference in a new issue