mtcute/packages/client/src/methods/chats/unban-chat-member.ts

45 lines
1.3 KiB
TypeScript

import { TelegramClient } from '../../client'
import { InputPeerLike, MtCuteInvalidPeerTypeError } from '../../types'
import {
isInputPeerChannel,
isInputPeerChat,
normalizeToInputChannel,
} from '../../utils/peer-utils'
// @alias=unrestrictChatMember
/**
* Unban a user from a supergroup or a channel,
* or remove any restrictions that they have.
* Unbanning does not add the user back to the chat, this
* just allows the user to join the chat again, if they want.
*
* This method acts as a no-op in case a legacy group is passed.
*
* @param chatId Chat ID
* @param userId User ID
* @internal
*/
export async function unbanChatMember(
this: TelegramClient,
chatId: InputPeerLike,
userId: InputPeerLike
): Promise<void> {
const chat = await this.resolvePeer(chatId)
const user = await this.resolvePeer(userId)
if (isInputPeerChannel(chat)) {
const res = await this.call({
_: 'channels.editBanned',
channel: normalizeToInputChannel(chat),
participant: user,
bannedRights: {
_: 'chatBannedRights',
untilDate: 0,
},
})
this._handleUpdate(res)
} else if (isInputPeerChat(chat)) {
// no-op //
} else throw new MtCuteInvalidPeerTypeError(chatId, 'chat or channel')
}