feat: content protection aka noforwards
closes MTQ-84
This commit is contained in:
parent
efaba06102
commit
6f7cda5544
6 changed files with 84 additions and 13 deletions
|
@ -75,6 +75,7 @@ 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 { toggleContentProtection } from './methods/chats/toggle-content-protection'
|
||||||
import { toggleFragmentUsername } from './methods/chats/toggle-fragment-username'
|
import { toggleFragmentUsername } from './methods/chats/toggle-fragment-username'
|
||||||
import { toggleJoinRequests } from './methods/chats/toggle-join-requests'
|
import { toggleJoinRequests } from './methods/chats/toggle-join-requests'
|
||||||
import { toggleJoinToSend } from './methods/chats/toggle-join-to-send'
|
import { toggleJoinToSend } from './methods/chats/toggle-join-to-send'
|
||||||
|
@ -1528,6 +1529,13 @@ 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 chat has content protection (i.e. forwarding messages is disabled)
|
||||||
|
*
|
||||||
|
* @param chatId Chat ID or username
|
||||||
|
* @param enabled (default: `false`) Whether content protection should be enabled
|
||||||
|
*/
|
||||||
|
toggleContentProtection(chatId: InputPeerLike, enabled?: boolean): Promise<void>
|
||||||
/**
|
/**
|
||||||
* Toggle a collectible (Fragment) username
|
* Toggle a collectible (Fragment) username
|
||||||
*
|
*
|
||||||
|
@ -4442,6 +4450,7 @@ export class TelegramClient extends BaseTelegramClient {
|
||||||
setChatTitle = setChatTitle
|
setChatTitle = setChatTitle
|
||||||
setChatUsername = setChatUsername
|
setChatUsername = setChatUsername
|
||||||
setSlowMode = setSlowMode
|
setSlowMode = setSlowMode
|
||||||
|
toggleContentProtection = toggleContentProtection
|
||||||
toggleFragmentUsername = toggleFragmentUsername
|
toggleFragmentUsername = toggleFragmentUsername
|
||||||
toggleJoinRequests = toggleJoinRequests
|
toggleJoinRequests = toggleJoinRequests
|
||||||
toggleJoinToSend = toggleJoinToSend
|
toggleJoinToSend = toggleJoinToSend
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputPeerLike } from '../../types'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether a chat has content protection (i.e. forwarding messages is disabled)
|
||||||
|
*
|
||||||
|
* @param chatId Chat ID or username
|
||||||
|
* @param enabled Whether content protection should be enabled
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export async function toggleContentProtection(
|
||||||
|
this: TelegramClient,
|
||||||
|
chatId: InputPeerLike,
|
||||||
|
enabled = false,
|
||||||
|
): Promise<void> {
|
||||||
|
const res = await this.call({
|
||||||
|
_: 'messages.toggleNoForwards',
|
||||||
|
peer: await this.resolvePeer(chatId),
|
||||||
|
enabled,
|
||||||
|
})
|
||||||
|
this._handleUpdate(res)
|
||||||
|
}
|
|
@ -146,6 +146,11 @@ export class Message {
|
||||||
return this.raw._ === 'messageService'
|
return this.raw._ === 'messageService'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Whether this message has content protection (i.e. disabled forwards) */
|
||||||
|
get isContentProtected(): boolean {
|
||||||
|
return this.raw._ === 'message' && this.raw.noforwards!
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multiple media messages with the same grouped ID
|
* Multiple media messages with the same grouped ID
|
||||||
* indicate an album or media group
|
* indicate an album or media group
|
||||||
|
|
|
@ -10,12 +10,12 @@ import { ChatMember } from '../chat-member'
|
||||||
import { ChatPermissions } from '../chat-permissions'
|
import { ChatPermissions } from '../chat-permissions'
|
||||||
import { User } from '../user'
|
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 channel (in the case of big groups, info of the user that has joined isn't shown) */
|
||||||
export interface ChatActionUserJoined {
|
export interface ChatActionUserJoined {
|
||||||
type: 'user_joined'
|
type: 'user_joined'
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A user has joined the group using an invite link */
|
/** A user has joined the channel using an invite link */
|
||||||
export interface ChatActionUserJoinedInvite {
|
export interface ChatActionUserJoinedInvite {
|
||||||
type: 'user_joined_invite'
|
type: 'user_joined_invite'
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ export interface ChatActionUserJoinedInvite {
|
||||||
link: ChatInviteLink
|
link: ChatInviteLink
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A user has joined the group using an invite link and was approved by an admin */
|
/** A user has joined the channel using an invite link and was approved by an admin */
|
||||||
export interface ChatActionUserJoinedApproved {
|
export interface ChatActionUserJoinedApproved {
|
||||||
type: 'user_joined_approved'
|
type: 'user_joined_approved'
|
||||||
|
|
||||||
|
@ -34,12 +34,12 @@ export interface ChatActionUserJoinedApproved {
|
||||||
approvedBy: User
|
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 channel (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'
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A user was invited to the group */
|
/** A user was invited to the channel */
|
||||||
export interface ChatActionUserInvited {
|
export interface ChatActionUserInvited {
|
||||||
type: 'user_invited'
|
type: 'user_invited'
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ export interface ChatActionUserInvited {
|
||||||
member: ChatMember
|
member: ChatMember
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Group title has been changed */
|
/** Channel title has been changed */
|
||||||
export interface ChatActionTitleChanged {
|
export interface ChatActionTitleChanged {
|
||||||
type: 'title_changed'
|
type: 'title_changed'
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ export interface ChatActionTitleChanged {
|
||||||
new: string
|
new: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Group description has been changed */
|
/** Channel description has been changed */
|
||||||
export interface ChatActionDescriptionChanged {
|
export interface ChatActionDescriptionChanged {
|
||||||
type: 'description_changed'
|
type: 'description_changed'
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ export interface ChatActionDescriptionChanged {
|
||||||
new: string
|
new: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Group username has been changed */
|
/** Channel username has been changed */
|
||||||
export interface ChatActionUsernameChanged {
|
export interface ChatActionUsernameChanged {
|
||||||
type: 'username_changed'
|
type: 'username_changed'
|
||||||
|
|
||||||
|
@ -80,7 +80,18 @@ export interface ChatActionUsernameChanged {
|
||||||
new: string
|
new: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Group photo has been changed */
|
/** Channel username list has been changed */
|
||||||
|
export interface ChatActionUsernamesChanged {
|
||||||
|
type: 'usernames_changed'
|
||||||
|
|
||||||
|
/** Old username */
|
||||||
|
old: string[]
|
||||||
|
|
||||||
|
/** New username */
|
||||||
|
new: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Channel photo has been changed */
|
||||||
export interface ChatActionPhotoChanged {
|
export interface ChatActionPhotoChanged {
|
||||||
type: 'photo_changed'
|
type: 'photo_changed'
|
||||||
|
|
||||||
|
@ -298,6 +309,14 @@ export interface ChatActionTtlChanged {
|
||||||
new: number
|
new: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Content protection has been toggled */
|
||||||
|
export interface ChatActionNoForwardsToggled {
|
||||||
|
type: 'no_forwards_toggled'
|
||||||
|
|
||||||
|
/** New status */
|
||||||
|
enabled: boolean
|
||||||
|
}
|
||||||
|
|
||||||
/** Forum has been toggled */
|
/** Forum has been toggled */
|
||||||
export interface ChatActionForumToggled {
|
export interface ChatActionForumToggled {
|
||||||
type: 'forum_toggled'
|
type: 'forum_toggled'
|
||||||
|
@ -341,6 +360,7 @@ export type ChatAction =
|
||||||
| ChatActionTitleChanged
|
| ChatActionTitleChanged
|
||||||
| ChatActionDescriptionChanged
|
| ChatActionDescriptionChanged
|
||||||
| ChatActionUsernameChanged
|
| ChatActionUsernameChanged
|
||||||
|
| ChatActionUsernamesChanged
|
||||||
| ChatActionPhotoChanged
|
| ChatActionPhotoChanged
|
||||||
| ChatActionInvitesToggled
|
| ChatActionInvitesToggled
|
||||||
| ChatActionSignaturesToggled
|
| ChatActionSignaturesToggled
|
||||||
|
@ -365,6 +385,7 @@ export type ChatAction =
|
||||||
| ChatActionInviteLinkRevoked
|
| ChatActionInviteLinkRevoked
|
||||||
| ChatActionUserJoinedApproved
|
| ChatActionUserJoinedApproved
|
||||||
| ChatActionTtlChanged
|
| ChatActionTtlChanged
|
||||||
|
| ChatActionNoForwardsToggled
|
||||||
| ChatActionForumToggled
|
| ChatActionForumToggled
|
||||||
| ChatActionTopicCreated
|
| ChatActionTopicCreated
|
||||||
| ChatActionTopicEdited
|
| ChatActionTopicEdited
|
||||||
|
@ -377,10 +398,6 @@ export function _actionFromTl(
|
||||||
client: TelegramClient,
|
client: TelegramClient,
|
||||||
peers: PeersIndex,
|
peers: PeersIndex,
|
||||||
): ChatAction {
|
): ChatAction {
|
||||||
// todo - MTQ-84
|
|
||||||
// channelAdminLogEventActionToggleNoForwards#cb2ac766 new_value:Bool = ChannelAdminLogEventAction;
|
|
||||||
// todo - MTQ-57
|
|
||||||
// channelAdminLogEventActionChangeUsernames#f04fb3a9 prev_value:Vector<string> new_value:Vector<string>
|
|
||||||
// todo - MTQ-72
|
// todo - MTQ-72
|
||||||
// channelAdminLogEventActionSendMessage#278f2868 message:Message = ChannelAdminLogEventAction;
|
// channelAdminLogEventActionSendMessage#278f2868 message:Message = ChannelAdminLogEventAction;
|
||||||
// channelAdminLogEventActionChangeAvailableReactions#be4e0ef8 prev_value:ChatReactions new_value:ChatReactions
|
// channelAdminLogEventActionChangeAvailableReactions#be4e0ef8 prev_value:ChatReactions new_value:ChatReactions
|
||||||
|
@ -407,6 +424,12 @@ export function _actionFromTl(
|
||||||
old: e.prevValue,
|
old: e.prevValue,
|
||||||
new: e.newValue,
|
new: e.newValue,
|
||||||
}
|
}
|
||||||
|
case 'channelAdminLogEventActionChangeUsernames':
|
||||||
|
return {
|
||||||
|
type: 'usernames_changed',
|
||||||
|
old: e.prevValue,
|
||||||
|
new: e.newValue,
|
||||||
|
}
|
||||||
case 'channelAdminLogEventActionChangePhoto':
|
case 'channelAdminLogEventActionChangePhoto':
|
||||||
return {
|
return {
|
||||||
type: 'photo_changed',
|
type: 'photo_changed',
|
||||||
|
@ -585,6 +608,11 @@ export function _actionFromTl(
|
||||||
type: 'topic_deleted',
|
type: 'topic_deleted',
|
||||||
topic: new ForumTopic(client, e.topic, peers),
|
topic: new ForumTopic(client, e.topic, peers),
|
||||||
}
|
}
|
||||||
|
case 'channelAdminLogEventActionToggleNoForwards':
|
||||||
|
return {
|
||||||
|
type: 'no_forwards_toggled',
|
||||||
|
enabled: e.newValue,
|
||||||
|
}
|
||||||
// case 'channelAdminLogEventActionPinTopic'
|
// case 'channelAdminLogEventActionPinTopic'
|
||||||
// ^ looks like it is not used, and pinned topics are not at all presented in the event log
|
// ^ looks like it is not used, and pinned topics are not at all presented in the event log
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -48,6 +48,7 @@ export function normalizeChatEventFilters(input: InputChatEventFilters): ChatEve
|
||||||
case 'location_changed':
|
case 'location_changed':
|
||||||
case 'photo_changed':
|
case 'photo_changed':
|
||||||
case 'username_changed':
|
case 'username_changed':
|
||||||
|
case 'usernames_changed':
|
||||||
case 'stickerset_changed':
|
case 'stickerset_changed':
|
||||||
case 'slow_mode_changed':
|
case 'slow_mode_changed':
|
||||||
case 'ttl_changed':
|
case 'ttl_changed':
|
||||||
|
@ -58,6 +59,7 @@ export function normalizeChatEventFilters(input: InputChatEventFilters): ChatEve
|
||||||
case 'signatures_toggled':
|
case 'signatures_toggled':
|
||||||
case 'def_perms_changed':
|
case 'def_perms_changed':
|
||||||
case 'forum_toggled':
|
case 'forum_toggled':
|
||||||
|
case 'no_forwards_toggled':
|
||||||
serverFilter.settings = true
|
serverFilter.settings = true
|
||||||
break
|
break
|
||||||
case 'msg_pinned':
|
case 'msg_pinned':
|
||||||
|
|
|
@ -212,6 +212,11 @@ export class Chat {
|
||||||
return this.peer._ === 'channel' && this.peer.joinToSend!
|
return this.peer._ === 'channel' && this.peer.joinToSend!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Whether this group has content protection (i.e. disabled forwards) */
|
||||||
|
get hasContentProtection(): boolean {
|
||||||
|
return (this.peer._ === 'channel' || this.peer._ === 'chat') && this.peer.noforwards!
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title, for supergroups, channels and groups
|
* Title, for supergroups, channels and groups
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue