feat(client): chat invite link class

This commit is contained in:
teidesu 2021-04-27 20:30:20 +03:00
parent 85671f6e6a
commit 7e9f255fdc
2 changed files with 81 additions and 0 deletions

View file

@ -0,0 +1,80 @@
import { makeInspectable } from '../utils'
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
/**
* An invite link
*/
export class ChatInviteLink {
readonly client: TelegramClient
readonly raw: tl.RawChatInviteExported
constructor (client: TelegramClient, raw: tl.RawChatInviteExported) {
this.client = client
this.raw = raw
}
/**
* The invite link as a `t.me/joinchat/` string.
*
* If the link was created by another administrator, the second
* part of the link will be censored with `...` (e.g. `https://t.me/joinchat/BGxxHIg4...`
*/
get link(): string {
return this.raw.link
}
/**
* Creation date of the link
*/
get date(): Date {
return new Date(this.raw.date * 1000)
}
/**
* Whether this link is primary (i.e. "permanent")
*/
get isPrimary(): boolean {
return this.raw.permanent!
}
/**
* Whether this link was revoked and can't be used anymore
*/
get isRevoked(): boolean {
return this.raw.revoked!
}
/**
* The date since which the link will be valid (if any)
*/
get startDate(): Date | null {
return this.raw.startDate ? new Date(this.raw.startDate * 1000) : null
}
/**
* The date until which the link will be valid (if any)
*/
get endDate(): Date | null {
return this.raw.expireDate ? new Date(this.raw.expireDate * 1000) : null
}
/**
* Maximum number of users that can be members of this chat
* at the same time after joining using this link.
*
* Integer in range `[1, 99999]` or `Infinity` if unspecified
*/
get usageLimit(): number {
return this.raw.usageLimit ?? Infinity
}
/**
* Number of users currently in the chat that joined using this link
*/
get usage(): number {
return this.raw.usageLimit ?? 0
}
}
makeInspectable(ChatInviteLink)

View file

@ -5,6 +5,7 @@ export * from './chat'
export * from './chat-preview'
export { InputChatPermissions } from './chat-permissions'
export * from './chat-member'
export * from './chat-invite-link'
/**
* Peer types that have one-to-one relation to tl.Peer* types.