2021-05-12 22:07:00 +03:00
|
|
|
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> {
|
2021-05-15 20:25:59 +03:00
|
|
|
const chat = await this.resolvePeer(chatId)
|
|
|
|
const user = await this.resolvePeer(userId)
|
2021-05-12 22:07:00 +03:00
|
|
|
|
|
|
|
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')
|
|
|
|
}
|