mirror of
https://github.com/zhigang1992/mtcute.git
synced 2026-01-12 17:32:35 +08:00
fix(core): properly handle star gift owner when the server doesnt return peer
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user