feat: better support for join requests
This commit is contained in:
parent
ea7eabf0be
commit
b2fccf4978
6 changed files with 102 additions and 14 deletions
|
@ -74,6 +74,8 @@ import { setChatPhoto } from './methods/chats/set-chat-photo'
|
||||||
import { setChatTitle } from './methods/chats/set-chat-title'
|
import { setChatTitle } from './methods/chats/set-chat-title'
|
||||||
import { setChatUsername } from './methods/chats/set-chat-username'
|
import { setChatUsername } from './methods/chats/set-chat-username'
|
||||||
import { setSlowMode } from './methods/chats/set-slow-mode'
|
import { setSlowMode } from './methods/chats/set-slow-mode'
|
||||||
|
import { toggleJoinRequests } from './methods/chats/toggle-join-requests'
|
||||||
|
import { toggleJoinToSend } from './methods/chats/toggle-join-to-send'
|
||||||
import { unarchiveChats } from './methods/chats/unarchive-chats'
|
import { unarchiveChats } from './methods/chats/unarchive-chats'
|
||||||
import { unbanChatMember } from './methods/chats/unban-chat-member'
|
import { unbanChatMember } from './methods/chats/unban-chat-member'
|
||||||
import { addContact } from './methods/contacts/add-contact'
|
import { addContact } from './methods/contacts/add-contact'
|
||||||
|
@ -1477,6 +1479,26 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
* Valid values are: `0 (off), 10, 30, 60 (1m), 300 (5m), 900 (15m) or 3600 (1h)`
|
* Valid values are: `0 (off), 10, 30, 60 (1m), 300 (5m), 900 (15m) or 3600 (1h)`
|
||||||
*/
|
*/
|
||||||
setSlowMode(chatId: InputPeerLike, seconds?: number): Promise<void>
|
setSlowMode(chatId: InputPeerLike, seconds?: number): Promise<void>
|
||||||
|
/**
|
||||||
|
* Set whether a channel/supergroup has join requests enabled.
|
||||||
|
*
|
||||||
|
* > **Note**: this method only affects primary invite links.
|
||||||
|
* > Additional invite links may exist with the opposite setting.
|
||||||
|
*
|
||||||
|
* @param chatId Chat ID or username
|
||||||
|
* @param enabled (default: `false`) Whether join requests should be enabled
|
||||||
|
*/
|
||||||
|
toggleJoinRequests(chatId: InputPeerLike, enabled?: boolean): Promise<void>
|
||||||
|
/**
|
||||||
|
* Set whether a channel/supergroup has join-to-send setting enabled.
|
||||||
|
*
|
||||||
|
* This only affects discussion groups where users can send messages
|
||||||
|
* without joining the group.
|
||||||
|
*
|
||||||
|
* @param chatId Chat ID or username
|
||||||
|
* @param enabled (default: `false`) Whether join-to-send setting should be enabled
|
||||||
|
*/
|
||||||
|
toggleJoinToSend(chatId: InputPeerLike, enabled?: boolean): Promise<void>
|
||||||
/**
|
/**
|
||||||
* Unarchive one or more chats
|
* Unarchive one or more chats
|
||||||
*
|
*
|
||||||
|
@ -4145,6 +4167,8 @@ export class TelegramClient extends BaseTelegramClient {
|
||||||
setChatTitle = setChatTitle
|
setChatTitle = setChatTitle
|
||||||
setChatUsername = setChatUsername
|
setChatUsername = setChatUsername
|
||||||
setSlowMode = setSlowMode
|
setSlowMode = setSlowMode
|
||||||
|
toggleJoinRequests = toggleJoinRequests
|
||||||
|
toggleJoinToSend = toggleJoinToSend
|
||||||
unarchiveChats = unarchiveChats
|
unarchiveChats = unarchiveChats
|
||||||
unbanChatMember = unbanChatMember
|
unbanChatMember = unbanChatMember
|
||||||
unrestrictChatMember = unbanChatMember
|
unrestrictChatMember = unbanChatMember
|
||||||
|
|
22
packages/client/src/methods/chats/toggle-join-requests.ts
Normal file
22
packages/client/src/methods/chats/toggle-join-requests.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputPeerLike } from '../../types'
|
||||||
|
import { normalizeToInputChannel } from '../../utils/peer-utils'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether a channel/supergroup has join requests enabled.
|
||||||
|
*
|
||||||
|
* > **Note**: this method only affects primary invite links.
|
||||||
|
* > Additional invite links may exist with the opposite setting.
|
||||||
|
*
|
||||||
|
* @param chatId Chat ID or username
|
||||||
|
* @param enabled Whether join requests should be enabled
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export async function toggleJoinRequests(this: TelegramClient, chatId: InputPeerLike, enabled = false): Promise<void> {
|
||||||
|
const res = await this.call({
|
||||||
|
_: 'channels.toggleJoinRequest',
|
||||||
|
channel: normalizeToInputChannel(await this.resolvePeer(chatId), chatId),
|
||||||
|
enabled,
|
||||||
|
})
|
||||||
|
this._handleUpdate(res)
|
||||||
|
}
|
22
packages/client/src/methods/chats/toggle-join-to-send.ts
Normal file
22
packages/client/src/methods/chats/toggle-join-to-send.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputPeerLike } from '../../types'
|
||||||
|
import { normalizeToInputChannel } from '../../utils/peer-utils'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether a channel/supergroup has join-to-send setting enabled.
|
||||||
|
*
|
||||||
|
* This only affects discussion groups where users can send messages
|
||||||
|
* without joining the group.
|
||||||
|
*
|
||||||
|
* @param chatId Chat ID or username
|
||||||
|
* @param enabled Whether join-to-send setting should be enabled
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export async function toggleJoinToSend(this: TelegramClient, chatId: InputPeerLike, enabled = false): Promise<void> {
|
||||||
|
const res = await this.call({
|
||||||
|
_: 'channels.toggleJoinToSend',
|
||||||
|
channel: normalizeToInputChannel(await this.resolvePeer(chatId), chatId),
|
||||||
|
enabled,
|
||||||
|
})
|
||||||
|
this._handleUpdate(res)
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import { ChatInviteLink } from '../chat-invite-link'
|
||||||
import { ChatLocation } from '../chat-location'
|
import { ChatLocation } from '../chat-location'
|
||||||
import { ChatMember } from '../chat-member'
|
import { ChatMember } from '../chat-member'
|
||||||
import { ChatPermissions } from '../chat-permissions'
|
import { ChatPermissions } from '../chat-permissions'
|
||||||
|
import { User } from '../user'
|
||||||
|
|
||||||
/** A user has joined the group (in the case of big groups, info of the user that has joined isn't shown) */
|
/** A user has joined the group (in the case of big groups, info of the user that has joined isn't shown) */
|
||||||
export interface ChatActionUserJoined {
|
export interface ChatActionUserJoined {
|
||||||
|
@ -21,6 +22,17 @@ export interface ChatActionUserJoinedInvite {
|
||||||
link: ChatInviteLink
|
link: ChatInviteLink
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A user has joined the group using an invite link and was approved by an admin */
|
||||||
|
export interface ChatActionUserJoinedApproved {
|
||||||
|
type: 'user_joined_approved'
|
||||||
|
|
||||||
|
/** Invite link user to join */
|
||||||
|
link: ChatInviteLink
|
||||||
|
|
||||||
|
/** User who approved the join */
|
||||||
|
approvedBy: User
|
||||||
|
}
|
||||||
|
|
||||||
/** A user has left the group (in the case of big groups, info of the user that has joined isn't shown) */
|
/** A user has left the group (in the case of big groups, info of the user that has joined isn't shown) */
|
||||||
export interface ChatActionUserLeft {
|
export interface ChatActionUserLeft {
|
||||||
type: 'user_left'
|
type: 'user_left'
|
||||||
|
@ -315,6 +327,7 @@ export type ChatAction =
|
||||||
| ChatActionInviteLinkDeleted
|
| ChatActionInviteLinkDeleted
|
||||||
| ChatActionInviteLinkEdited
|
| ChatActionInviteLinkEdited
|
||||||
| ChatActionInviteLinkRevoked
|
| ChatActionInviteLinkRevoked
|
||||||
|
| ChatActionUserJoinedApproved
|
||||||
| ChatActionTtlChanged
|
| ChatActionTtlChanged
|
||||||
| null
|
| null
|
||||||
|
|
||||||
|
@ -324,8 +337,7 @@ export function _actionFromTl(
|
||||||
client: TelegramClient,
|
client: TelegramClient,
|
||||||
peers: PeersIndex,
|
peers: PeersIndex,
|
||||||
): ChatAction {
|
): ChatAction {
|
||||||
// todo - MTQ-78
|
// todo - MTQ-84
|
||||||
// channelAdminLogEventActionParticipantJoinByRequest#afb6144a invite:ExportedChatInvite approved_by:long
|
|
||||||
// channelAdminLogEventActionToggleNoForwards#cb2ac766 new_value:Bool = ChannelAdminLogEventAction;
|
// channelAdminLogEventActionToggleNoForwards#cb2ac766 new_value:Bool = ChannelAdminLogEventAction;
|
||||||
// todo - MTQ-57
|
// todo - MTQ-57
|
||||||
// channelAdminLogEventActionChangeUsernames#f04fb3a9 prev_value:Vector<string> new_value:Vector<string>
|
// channelAdminLogEventActionChangeUsernames#f04fb3a9 prev_value:Vector<string> new_value:Vector<string>
|
||||||
|
@ -502,6 +514,12 @@ export function _actionFromTl(
|
||||||
old: e.prevValue,
|
old: e.prevValue,
|
||||||
new: e.newValue,
|
new: e.newValue,
|
||||||
}
|
}
|
||||||
|
case 'channelAdminLogEventActionParticipantJoinByRequest':
|
||||||
|
return {
|
||||||
|
type: 'user_joined_approved',
|
||||||
|
link: new ChatInviteLink(client, e.invite, peers),
|
||||||
|
approvedBy: new User(client, peers.user(e.approvedBy)),
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@ export function normalizeChatEventFilters(input: InputChatEventFilters): ChatEve
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'user_joined':
|
case 'user_joined':
|
||||||
|
case 'user_joined_invite':
|
||||||
|
case 'user_joined_approved':
|
||||||
serverFilter.join = true
|
serverFilter.join = true
|
||||||
break
|
break
|
||||||
case 'user_left':
|
case 'user_left':
|
||||||
|
@ -47,6 +49,8 @@ export function normalizeChatEventFilters(input: InputChatEventFilters): ChatEve
|
||||||
case 'photo_changed':
|
case 'photo_changed':
|
||||||
case 'username_changed':
|
case 'username_changed':
|
||||||
case 'stickerset_changed':
|
case 'stickerset_changed':
|
||||||
|
case 'slow_mode_changed':
|
||||||
|
case 'ttl_changed':
|
||||||
serverFilter.info = true
|
serverFilter.info = true
|
||||||
break
|
break
|
||||||
case 'invites_toggled':
|
case 'invites_toggled':
|
||||||
|
@ -75,12 +79,6 @@ export function normalizeChatEventFilters(input: InputChatEventFilters): ChatEve
|
||||||
serverFilter.promote = true
|
serverFilter.promote = true
|
||||||
serverFilter.demote = true
|
serverFilter.demote = true
|
||||||
break
|
break
|
||||||
case 'slow_mode_changed':
|
|
||||||
case 'ttl_changed':
|
|
||||||
// not documented so idk, enable both
|
|
||||||
serverFilter.settings = true
|
|
||||||
serverFilter.info = true
|
|
||||||
break
|
|
||||||
case 'call_started':
|
case 'call_started':
|
||||||
case 'call_ended':
|
case 'call_ended':
|
||||||
serverFilter.groupCall = true
|
serverFilter.groupCall = true
|
||||||
|
@ -91,12 +89,6 @@ export function normalizeChatEventFilters(input: InputChatEventFilters): ChatEve
|
||||||
serverFilter.settings = true
|
serverFilter.settings = true
|
||||||
serverFilter.info = true
|
serverFilter.info = true
|
||||||
break
|
break
|
||||||
case 'user_joined_invite':
|
|
||||||
// not documented so idk, enable all
|
|
||||||
serverFilter.join = true
|
|
||||||
serverFilter.invite = true
|
|
||||||
serverFilter.invites = true
|
|
||||||
break
|
|
||||||
case 'invite_deleted':
|
case 'invite_deleted':
|
||||||
case 'invite_edited':
|
case 'invite_edited':
|
||||||
case 'invite_revoked':
|
case 'invite_revoked':
|
||||||
|
|
|
@ -202,6 +202,16 @@ export class Chat {
|
||||||
return this.peer._ === 'user' && this.peer.contact!
|
return this.peer._ === 'user' && this.peer.contact!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Whether this group is a channel/supergroup with join requests enabled */
|
||||||
|
get hasJoinRequests(): boolean {
|
||||||
|
return this.peer._ === 'channel' && this.peer.joinRequest!
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether this group is a supergroup with join-to-send rule enabled */
|
||||||
|
get hasJoinToSend(): boolean {
|
||||||
|
return this.peer._ === 'channel' && this.peer.joinToSend!
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title, for supergroups, channels and groups
|
* Title, for supergroups, channels and groups
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue