47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
|
import { TelegramClient } from '../../client'
|
||
|
import { InputPeerLike, MtCuteInvalidPeerTypeError } from '../../types'
|
||
|
import {
|
||
|
isInputPeerChannel,
|
||
|
isInputPeerChat,
|
||
|
normalizeToInputChannel,
|
||
|
normalizeToInputPeer,
|
||
|
} 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 = normalizeToInputPeer(await this.resolvePeer(chatId))
|
||
|
const user = normalizeToInputPeer(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')
|
||
|
}
|