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

View File

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

View File

@ -138,7 +138,7 @@ export async function fetchBlockedContacts() {
return {
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)),
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
.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))
.forEach((chat) => {
if (!chat) {