Fix support for forbidden chats

This commit is contained in:
Alexander Zinchuk 2022-09-15 10:17:50 +02:00
parent 4d64c9c91e
commit df3cadf5a1
4 changed files with 13 additions and 29 deletions

View File

@ -48,20 +48,13 @@ function buildApiChatFieldsFromPeerEntity(
...(accessHash && { accessHash }), ...(accessHash && { accessHash }),
hasVideoAvatar, hasVideoAvatar,
...(avatarHash && { avatarHash }), ...(avatarHash && { avatarHash }),
...( ...(('username' in peerEntity) && { username: peerEntity.username }),
(peerEntity instanceof GramJs.Channel || peerEntity instanceof GramJs.User)
&& { username: peerEntity.username }
),
...(('verified' in peerEntity) && { isVerified: peerEntity.verified }), ...(('verified' in peerEntity) && { isVerified: peerEntity.verified }),
...(('callActive' in peerEntity) && { isCallActive: peerEntity.callActive }), ...(('callActive' in peerEntity) && { isCallActive: peerEntity.callActive }),
...(('callNotEmpty' in peerEntity) && { isCallNotEmpty: peerEntity.callNotEmpty }), ...(('callNotEmpty' in peerEntity) && { isCallNotEmpty: peerEntity.callNotEmpty }),
...((peerEntity instanceof GramJs.Chat || peerEntity instanceof GramJs.Channel) && { ...('date' in peerEntity && { joinDate: peerEntity.date }),
...(peerEntity.participantsCount && { membersCount: peerEntity.participantsCount }), ...('participantsCount' in peerEntity && { membersCount: peerEntity.participantsCount }),
joinDate: peerEntity.date, ...(('noforwards' in peerEntity) && { isProtected: Boolean(peerEntity.noforwards) }),
}),
...((peerEntity instanceof GramJs.Chat || peerEntity instanceof GramJs.Channel) && {
isProtected: Boolean('noforwards' in peerEntity && peerEntity.noforwards),
}),
...(isSupport && { isSupport: true }), ...(isSupport && { isSupport: true }),
...buildApiChatPermissions(peerEntity), ...buildApiChatPermissions(peerEntity),
...(('creator' in peerEntity) && { isCreator: peerEntity.creator }), ...(('creator' in peerEntity) && { isCreator: peerEntity.creator }),
@ -113,7 +106,7 @@ function buildApiChatPermissions(peerEntity: GramJs.TypeUser | GramJs.TypeChat):
return { return {
adminRights: peerEntity.adminRights ? omitVirtualClassFields(peerEntity.adminRights) : undefined, adminRights: peerEntity.adminRights ? omitVirtualClassFields(peerEntity.adminRights) : undefined,
currentUserBannedRights: peerEntity instanceof GramJs.Channel && peerEntity.bannedRights currentUserBannedRights: 'bannedRights' in peerEntity && peerEntity.bannedRights
? omitVirtualClassFields(peerEntity.bannedRights) ? omitVirtualClassFields(peerEntity.bannedRights)
: undefined, : undefined,
defaultBannedRights: peerEntity.defaultBannedRights defaultBannedRights: peerEntity.defaultBannedRights
@ -178,7 +171,7 @@ function buildApiChatMigrationInfo(peerEntity: GramJs.TypeChat): {
}; };
} { } {
if ( if (
peerEntity instanceof GramJs.Chat 'migratedTo' in peerEntity
&& peerEntity.migratedTo && peerEntity.migratedTo
&& !(peerEntity.migratedTo instanceof GramJs.InputChannelEmpty) && !(peerEntity.migratedTo instanceof GramJs.InputChannelEmpty)
) { ) {
@ -209,20 +202,8 @@ function buildApiChatRestrictionReason(
export function buildApiChatFromPreview( export function buildApiChatFromPreview(
preview: GramJs.TypeChat | GramJs.TypeUser, preview: GramJs.TypeChat | GramJs.TypeUser,
isSupport = false, isSupport = false,
withForbidden = false,
): ApiChat | undefined { ): ApiChat | undefined {
if (!( if (preview instanceof GramJs.ChatEmpty || preview instanceof GramJs.UserEmpty) {
preview instanceof GramJs.Chat
|| preview instanceof GramJs.Channel
|| preview instanceof GramJs.User
|| (
withForbidden
&& (
preview instanceof GramJs.ChatForbidden
|| preview instanceof GramJs.ChannelForbidden
)
)
)) {
return undefined; return undefined;
} }

View File

@ -469,7 +469,7 @@ async function getFullChannelInfo(
updateLocalDb(result); updateLocalDb(result);
const [, mtpLinkedChat] = result.chats; const [, mtpLinkedChat] = result.chats;
const chat = buildApiChatFromPreview(mtpLinkedChat, undefined, true); const chat = buildApiChatFromPreview(mtpLinkedChat);
if (chat) { if (chat) {
onUpdate({ onUpdate({
'@type': 'updateChat', '@type': 'updateChat',

View File

@ -138,7 +138,7 @@ export async function fetchBlockedContacts() {
return { return {
users: result.users.map(buildApiUser).filter<ApiUser>(Boolean as any), users: result.users.map(buildApiUser).filter<ApiUser>(Boolean as any),
chats: result.chats.map((chat) => buildApiChatFromPreview(chat, undefined, true)).filter<ApiChat>(Boolean as any), chats: result.chats.map((chat) => buildApiChatFromPreview(chat)).filter<ApiChat>(Boolean as any),
blockedIds: result.blocked.map((blocked) => getApiChatIdFromMtpPeer(blocked.peerId)), blockedIds: result.blocked.map((blocked) => getApiChatIdFromMtpPeer(blocked.peerId)),
totalCount: result instanceof GramJs.contacts.BlockedSlice ? result.count : result.blocked.length, totalCount: result instanceof GramJs.contacts.BlockedSlice ? result.count : result.blocked.length,
}; };

View File

@ -87,7 +87,10 @@ function dispatchUserAndChatUpdates(entities: (GramJs.TypeUser | GramJs.TypeChat
}); });
entities entities
.filter((e) => e instanceof GramJs.Chat || e instanceof GramJs.Channel) .filter((e) => (
e instanceof GramJs.Chat || e instanceof GramJs.ChatForbidden
|| e instanceof GramJs.Channel || e instanceof GramJs.ChannelForbidden
))
.map((e) => buildApiChatFromPreview(e)) .map((e) => buildApiChatFromPreview(e))
.forEach((chat) => { .forEach((chat) => {
if (!chat) { if (!chat) {