2021-05-10 00:35:29 +03:00
|
|
|
import { TelegramClient } from '../../client'
|
|
|
|
import { ChatInviteLink, InputPeerLike } from '../../types'
|
2021-05-15 20:25:59 +03:00
|
|
|
import { createUsersChatsIndex } from '../../utils/peer-utils'
|
2021-05-10 00:35:29 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Revoke an invite link.
|
|
|
|
*
|
|
|
|
* If `link` is a primary invite link, a new invite link will be
|
|
|
|
* generated automatically by Telegram
|
|
|
|
*
|
|
|
|
* @param chatId Chat ID
|
|
|
|
* @param link Invite link to revoke
|
|
|
|
* @returns If `link` is a primary invite, newly generated invite link, otherwise the revoked link
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
export async function revokeInviteLink(
|
|
|
|
this: TelegramClient,
|
|
|
|
chatId: InputPeerLike,
|
|
|
|
link: string
|
|
|
|
): Promise<ChatInviteLink> {
|
|
|
|
const res = await this.call({
|
|
|
|
_: 'messages.editExportedChatInvite',
|
2021-05-15 20:25:59 +03:00
|
|
|
peer: await this.resolvePeer(chatId),
|
2021-05-10 00:35:29 +03:00
|
|
|
link,
|
2021-06-06 15:20:41 +03:00
|
|
|
revoked: true,
|
2021-05-10 00:35:29 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
const { users } = createUsersChatsIndex(res)
|
|
|
|
|
2021-06-06 15:20:41 +03:00
|
|
|
const invite =
|
|
|
|
res._ === 'messages.exportedChatInviteReplaced'
|
|
|
|
? res.newInvite
|
|
|
|
: res.invite
|
2021-05-10 00:35:29 +03:00
|
|
|
|
|
|
|
return new ChatInviteLink(this, invite, users)
|
|
|
|
}
|