Fix support for - in invite links; Small refactoring
This commit is contained in:
parent
196419be32
commit
a6d0f5a220
@ -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
|
const restrictionReason = peerEntity.restricted
|
||||||
? buildApiChatRestrictionReason(peerEntity.restrictionReason)
|
? buildApiChatRestrictionReason(peerEntity.restrictionReason)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
if (restrictionReason === undefined) {
|
if (restrictionReason) {
|
||||||
return {
|
Object.assign(restrictions, {
|
||||||
isRestricted: false,
|
isRestricted: true,
|
||||||
};
|
restrictionReason,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
if (peerEntity instanceof GramJs.Chat) {
|
||||||
isRestricted: peerEntity.restricted,
|
Object.assign(restrictions, {
|
||||||
restrictionReason,
|
|
||||||
};
|
|
||||||
} else if (peerEntity instanceof GramJs.Chat) {
|
|
||||||
return {
|
|
||||||
isNotJoined: peerEntity.left,
|
isNotJoined: peerEntity.left,
|
||||||
isRestricted: peerEntity.kicked,
|
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
|
// `left` is weirdly set to `true` on all channels never joined before
|
||||||
isNotJoined: peerEntity.left,
|
isNotJoined: peerEntity.left,
|
||||||
isRestricted,
|
});
|
||||||
restrictionReason: buildApiChatRestrictionReason(peerEntity.restrictionReason),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return {};
|
|
||||||
|
return restrictions;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildApiChatMigrationInfo(peerEntity: GramJs.TypeChat): {
|
function buildApiChatMigrationInfo(peerEntity: GramJs.TypeChat): {
|
||||||
|
|||||||
@ -116,7 +116,7 @@ export const CONTENT_TYPES_FOR_QUICK_UPLOAD = 'image/png,image/gif,image/jpeg,vi
|
|||||||
// eslint-disable-next-line max-len
|
// 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_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_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
|
// MTProto constants
|
||||||
export const SERVICE_NOTIFICATIONS_USER_ID = 777000;
|
export const SERVICE_NOTIFICATIONS_USER_ID = 777000;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user