diff --git a/src/api/gramjs/apiBuilders/chats.ts b/src/api/gramjs/apiBuilders/chats.ts index 15ba16a38..3a214b54f 100644 --- a/src/api/gramjs/apiBuilders/chats.ts +++ b/src/api/gramjs/apiBuilders/chats.ts @@ -109,39 +109,36 @@ function buildApiChatRestrictions(peerEntity: GramJs.TypeUser | GramJs.TypeChat) }; } - if (peerEntity instanceof GramJs.User) { + const restrictions = {}; + + if ('restricted' in peerEntity) { const restrictionReason = peerEntity.restricted ? buildApiChatRestrictionReason(peerEntity.restrictionReason) : undefined; - if (restrictionReason === undefined) { - return { - isRestricted: false, - }; + if (restrictionReason) { + Object.assign(restrictions, { + isRestricted: true, + restrictionReason, + }); } + } - return { - isRestricted: peerEntity.restricted, - restrictionReason, - }; - } else if (peerEntity instanceof GramJs.Chat) { - return { + if (peerEntity instanceof GramJs.Chat) { + Object.assign(restrictions, { isNotJoined: peerEntity.left, isRestricted: peerEntity.kicked, - }; - } else if (peerEntity instanceof GramJs.Channel) { - const isRestricted = peerEntity.restricted - && peerEntity.restrictionReason - && peerEntity.restrictionReason.some((reason) => reason.platform === 'all'); + }); + } - return { + if (peerEntity instanceof GramJs.Channel) { + Object.assign(restrictions, { // `left` is weirdly set to `true` on all channels never joined before isNotJoined: peerEntity.left, - isRestricted, - restrictionReason: buildApiChatRestrictionReason(peerEntity.restrictionReason), - }; + }); } - return {}; + + return restrictions; } function buildApiChatMigrationInfo(peerEntity: GramJs.TypeChat): { diff --git a/src/config.ts b/src/config.ts index c47a1999e..4f31f831a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -116,7 +116,7 @@ export const CONTENT_TYPES_FOR_QUICK_UPLOAD = 'image/png,image/gif,image/jpeg,vi // eslint-disable-next-line max-len export const RE_LINK_TEMPLATE = '((ftp|https?):\\/\\/)?((www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6})\\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)'; export const RE_TME_LINK = /^(?:https?:\/\/)?(?:t\.me\/)([\d\w_]+)(?:\/([\d]+))?$/gm; -export const RE_TME_INVITE_LINK = /^(?:https?:\/\/)?(?:t\.me\/joinchat\/)([\d\w_]+)?$/gm; +export const RE_TME_INVITE_LINK = /^(?:https?:\/\/)?(?:t\.me\/joinchat\/)([\d\w_-]+)?$/gm; // MTProto constants export const SERVICE_NOTIFICATIONS_USER_ID = 777000;