fix(core): properly handle star gift owner when the server doesnt return peer

This commit is contained in:
alina sireneva
2025-04-07 04:56:01 +03:00
parent ad73000ace
commit b4d6361f13
2 changed files with 23 additions and 1 deletions

View File

@@ -74,4 +74,15 @@ export class PeersIndex {
return this.chat(peer.channelId)
}
}
has(peer: tl.TypePeer): boolean {
switch (peer._) {
case 'peerUser':
return this.users.has(peer.userId)
case 'peerChat':
return this.chats.has(peer.chatId)
case 'peerChannel':
return this.chats.has(peer.channelId)
}
}
}

View File

@@ -4,6 +4,7 @@ import type { TextWithEntities } from '../misc/entities.js'
import type { Peer } from '../peers/peer.js'
import type { PeersIndex } from '../peers/peers-index.js'
import { assert } from '@fuman/utils'
import { getMarkedPeerId } from '../../../utils/peer-utils.js'
import { makeInspectable } from '../../utils/inspectable.js'
import { memoizeGetters } from '../../utils/memoize.js'
import { parseDocument } from '../media/document-utils.js'
@@ -145,12 +146,22 @@ export class StarGiftUnique {
return this.raw.slug
}
/** ID of the peer who owns this gift, if available */
/**
* ID of the peer who owns this gift, if available
* > Note: in some cases, only {@link ownerId} is available, and not {@link owner},
* > in which cases please use `tg.getPeer(ownerId)` manually
*/
get owner(): Peer | null {
if (!this.raw.ownerId) return null
if (!this._peers.has(this.raw.ownerId)) return null
return parsePeer(this.raw.ownerId, this._peers)
}
/** ID of the peer who owns this gift, if available */
get ownerId(): number | null {
return this.raw.ownerId ? getMarkedPeerId(this.raw.ownerId) : null
}
/** Name of the user who owns this gift, if available */
get ownerName(): string | null {
return this.raw.ownerName ?? null