diff --git a/Telegram-iOS.xcodeproj/project.pbxproj b/Telegram-iOS.xcodeproj/project.pbxproj index 960a5d8077..95a16174b8 100644 --- a/Telegram-iOS.xcodeproj/project.pbxproj +++ b/Telegram-iOS.xcodeproj/project.pbxproj @@ -188,7 +188,6 @@ 09FDAEE62140477F00BF856F /* MtProtoKitDynamic.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 09FDAEE52140477F00BF856F /* MtProtoKitDynamic.framework */; }; D000CACF21FB6E380011B15D /* NotificationService.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = D000CAC821FB6E370011B15D /* NotificationService.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; D001D5AA1F878DA300DF975A /* PhoneCountries.txt in Resources */ = {isa = PBXBuildFile; fileRef = D001D5A91F878DA300DF975A /* PhoneCountries.txt */; }; - D008184E22B5796E008A895F /* BuildConfig.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D008184D22B5796E008A895F /* BuildConfig.framework */; }; D008185022B5797A008A895F /* BuildConfig.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D008184F22B5797A008A895F /* BuildConfig.framework */; }; D008185222B57986008A895F /* BuildConfig.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D008185122B57986008A895F /* BuildConfig.framework */; }; D008185422B57994008A895F /* BuildConfig.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D008185322B57994008A895F /* BuildConfig.framework */; }; @@ -205,7 +204,6 @@ D015E04D225D2D8F00CB9E8A /* WebP.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D015E04C225D2D8F00CB9E8A /* WebP.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; D015E050225D303F00CB9E8A /* WebP.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D015E04C225D2D8F00CB9E8A /* WebP.framework */; }; D015E051225D303F00CB9E8A /* WebP.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D015E04C225D2D8F00CB9E8A /* WebP.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - D01A47551F4DBED700383CC1 /* HockeySDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D01A47541F4DBED700383CC1 /* HockeySDK.framework */; }; D021D4D9219CAEDD0064BEBA /* Config-Fork.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = D021D4D8219CAEDD0064BEBA /* Config-Fork.xcconfig */; }; D02CF5FD215D9ABF00E0F56A /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0AA1A671D568BA400152314 /* UserNotifications.framework */; }; D02CF5FE215D9ABF00E0F56A /* UserNotificationsUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0AA1A691D568BA400152314 /* UserNotificationsUI.framework */; }; @@ -1099,11 +1097,9 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - D008184E22B5796E008A895F /* BuildConfig.framework in Frameworks */, D0CAD6A421C03BEB001E3055 /* FFMpeg.framework in Frameworks */, 09C50E88217385CF009E676F /* WatchConnectivity.framework in Frameworks */, 09FDAEE62140477F00BF856F /* MtProtoKitDynamic.framework in Frameworks */, - D01A47551F4DBED700383CC1 /* HockeySDK.framework in Frameworks */, D0A18D631E149043004C6734 /* PushKit.framework in Frameworks */, D0B844601DACF561005F29E1 /* libc++.tbd in Frameworks */, D06706621D5118F500DED3E3 /* TelegramCore.framework in Frameworks */, diff --git a/submodules/TelegramCore/TelegramCore/ApiGroupOrChannel.swift b/submodules/TelegramCore/TelegramCore/ApiGroupOrChannel.swift index 650cb4761e..e0e4db8f72 100644 --- a/submodules/TelegramCore/TelegramCore/ApiGroupOrChannel.swift +++ b/submodules/TelegramCore/TelegramCore/ApiGroupOrChannel.swift @@ -32,87 +32,95 @@ func imageRepresentationsForApiChatPhoto(_ photo: Api.ChatPhoto) -> [TelegramMed func parseTelegramGroupOrChannel(chat: Api.Chat) -> Peer? { switch chat { - case let .chat(flags, id, title, photo, participantsCount, date, version, migratedTo, adminRights, defaultBannedRights): - let left = (flags & ((1 << 1) | (1 << 2))) != 0 - var migrationReference: TelegramGroupToChannelMigrationReference? - if let migratedTo = migratedTo { - switch migratedTo { - case let .inputChannel(channelId, accessHash): - migrationReference = TelegramGroupToChannelMigrationReference(peerId: PeerId(namespace: Namespaces.Peer.CloudChannel, id: channelId), accessHash: accessHash) - case .inputChannelEmpty: - break - } + case let .chat(flags, id, title, photo, participantsCount, date, version, migratedTo, adminRights, defaultBannedRights): + let left = (flags & ((1 << 1) | (1 << 2))) != 0 + var migrationReference: TelegramGroupToChannelMigrationReference? + if let migratedTo = migratedTo { + switch migratedTo { + case let .inputChannel(channelId, accessHash): + migrationReference = TelegramGroupToChannelMigrationReference(peerId: PeerId(namespace: Namespaces.Peer.CloudChannel, id: channelId), accessHash: accessHash) + case .inputChannelEmpty: + break } - var groupFlags = TelegramGroupFlags() - var role: TelegramGroupRole = .member - if (flags & (1 << 0)) != 0 { - role = .creator - } else if let adminRights = adminRights { - role = .admin(TelegramChatAdminRights(apiAdminRights: adminRights)) + } + var groupFlags = TelegramGroupFlags() + var role: TelegramGroupRole = .member + if (flags & (1 << 0)) != 0 { + role = .creator + } else if let adminRights = adminRights { + role = .admin(TelegramChatAdminRights(apiAdminRights: adminRights)) + } + if (flags & (1 << 5)) != 0 { + groupFlags.insert(.deactivated) + } + return TelegramGroup(id: PeerId(namespace: Namespaces.Peer.CloudGroup, id: id), title: title, photo: imageRepresentationsForApiChatPhoto(photo), participantCount: Int(participantsCount), role: role, membership: left ? .Left : .Member, flags: groupFlags, defaultBannedRights: defaultBannedRights.flatMap(TelegramChatBannedRights.init(apiBannedRights:)), migrationReference: migrationReference, creationDate: date, version: Int(version)) + case let .chatEmpty(id): + return TelegramGroup(id: PeerId(namespace: Namespaces.Peer.CloudGroup, id: id), title: "", photo: [], participantCount: 0, role: .member, membership: .Removed, flags: [], defaultBannedRights: nil, migrationReference: nil, creationDate: 0, version: 0) + case let .chatForbidden(id, title): + return TelegramGroup(id: PeerId(namespace: Namespaces.Peer.CloudGroup, id: id), title: title, photo: [], participantCount: 0, role: .member, membership: .Removed, flags: [], defaultBannedRights: nil, migrationReference: nil, creationDate: 0, version: 0) + case let .channel(flags, id, accessHash, title, username, photo, date, version, restrictionReason, adminRights, bannedRights, defaultBannedRights, _): + let isMin = (flags & (1 << 20)) != 0 + + let participationStatus: TelegramChannelParticipationStatus + if (flags & Int32(1 << 1)) != 0 { + participationStatus = .kicked + } else if (flags & Int32(1 << 2)) != 0 { + participationStatus = .left + } else { + participationStatus = .member + } + + let info: TelegramChannelInfo + if (flags & Int32(1 << 8)) != 0 { + let infoFlags = TelegramChannelGroupFlags() + info = .group(TelegramChannelGroupInfo(flags: infoFlags)) + } else { + var infoFlags = TelegramChannelBroadcastFlags() + if (flags & Int32(1 << 11)) != 0 { + infoFlags.insert(.messagesShouldHaveSignatures) } - if (flags & (1 << 5)) != 0 { - groupFlags.insert(.deactivated) + if (flags & Int32(1 << 20)) != 0 { + infoFlags.insert(.hasDiscussionGroup) } - return TelegramGroup(id: PeerId(namespace: Namespaces.Peer.CloudGroup, id: id), title: title, photo: imageRepresentationsForApiChatPhoto(photo), participantCount: Int(participantsCount), role: role, membership: left ? .Left : .Member, flags: groupFlags, defaultBannedRights: defaultBannedRights.flatMap(TelegramChatBannedRights.init(apiBannedRights:)), migrationReference: migrationReference, creationDate: date, version: Int(version)) - case let .chatEmpty(id): - return TelegramGroup(id: PeerId(namespace: Namespaces.Peer.CloudGroup, id: id), title: "", photo: [], participantCount: 0, role: .member, membership: .Removed, flags: [], defaultBannedRights: nil, migrationReference: nil, creationDate: 0, version: 0) - case let .chatForbidden(id, title): - return TelegramGroup(id: PeerId(namespace: Namespaces.Peer.CloudGroup, id: id), title: title, photo: [], participantCount: 0, role: .member, membership: .Removed, flags: [], defaultBannedRights: nil, migrationReference: nil, creationDate: 0, version: 0) - case let .channel(flags, id, accessHash, title, username, photo, date, version, restrictionReason, adminRights, bannedRights, defaultBannedRights, _): - let isMin = (flags & (1 << 20)) != 0 - - let participationStatus: TelegramChannelParticipationStatus - if (flags & Int32(1 << 1)) != 0 { - participationStatus = .kicked - } else if (flags & Int32(1 << 2)) != 0 { - participationStatus = .left + info = .broadcast(TelegramChannelBroadcastInfo(flags: infoFlags)) + } + + var channelFlags = TelegramChannelFlags() + if (flags & Int32(1 << 0)) != 0 { + channelFlags.insert(.isCreator) + } + if (flags & Int32(1 << 7)) != 0 { + channelFlags.insert(.isVerified) + } + if (flags & Int32(1 << 19)) != 0 { + channelFlags.insert(.isScam) + } + + let restrictionInfo: PeerAccessRestrictionInfo? + if let restrictionReason = restrictionReason { + restrictionInfo = PeerAccessRestrictionInfo(reason: restrictionReason) + } else { + restrictionInfo = nil + } + + let accessHashValue = accessHash.flatMap { value -> TelegramPeerAccessHash in + if isMin { + return .genericPublic(value) } else { - participationStatus = .member + return .personal(value) } - - let info: TelegramChannelInfo - if (flags & Int32(1 << 8)) != 0 { - let infoFlags = TelegramChannelGroupFlags() - info = .group(TelegramChannelGroupInfo(flags: infoFlags)) - } else { - var infoFlags = TelegramChannelBroadcastFlags() - if (flags & Int32(1 << 11)) != 0 { - infoFlags.insert(.messagesShouldHaveSignatures) - } - if (flags & Int32(1 << 20)) != 0 { - infoFlags.insert(.hasDiscussionGroup) - } - info = .broadcast(TelegramChannelBroadcastInfo(flags: infoFlags)) - } - - var channelFlags = TelegramChannelFlags() - if (flags & Int32(1 << 0)) != 0 { - channelFlags.insert(.isCreator) - } - if (flags & Int32(1 << 7)) != 0 { - channelFlags.insert(.isVerified) - } - if (flags & Int32(1 << 19)) != 0 { - channelFlags.insert(.isScam) - } - - let restrictionInfo: PeerAccessRestrictionInfo? - if let restrictionReason = restrictionReason { - restrictionInfo = PeerAccessRestrictionInfo(reason: restrictionReason) - } else { - restrictionInfo = nil - } - - return TelegramChannel(id: PeerId(namespace: Namespaces.Peer.CloudChannel, id: id), accessHash: accessHash, title: title, username: username, photo: imageRepresentationsForApiChatPhoto(photo), creationDate: date, version: version, participationStatus: participationStatus, info: info, flags: channelFlags, restrictionInfo: restrictionInfo, adminRights: adminRights.flatMap(TelegramChatAdminRights.init), bannedRights: bannedRights.flatMap(TelegramChatBannedRights.init), defaultBannedRights: defaultBannedRights.flatMap(TelegramChatBannedRights.init)) - case let .channelForbidden(flags, id, accessHash, title, untilDate): - let info: TelegramChannelInfo - if (flags & Int32(1 << 8)) != 0 { - info = .group(TelegramChannelGroupInfo(flags: [])) - } else { - info = .broadcast(TelegramChannelBroadcastInfo(flags: [])) - } - - return TelegramChannel(id: PeerId(namespace: Namespaces.Peer.CloudChannel, id: id), accessHash: accessHash, title: title, username: nil, photo: [], creationDate: 0, version: 0, participationStatus: .kicked, info: info, flags: TelegramChannelFlags(), restrictionInfo: nil, adminRights: nil, bannedRights: TelegramChatBannedRights(flags: [.banReadMessages], untilDate: untilDate ?? Int32.max), defaultBannedRights: nil) + } + + return TelegramChannel(id: PeerId(namespace: Namespaces.Peer.CloudChannel, id: id), accessHash: accessHashValue, title: title, username: username, photo: imageRepresentationsForApiChatPhoto(photo), creationDate: date, version: version, participationStatus: participationStatus, info: info, flags: channelFlags, restrictionInfo: restrictionInfo, adminRights: adminRights.flatMap(TelegramChatAdminRights.init), bannedRights: bannedRights.flatMap(TelegramChatBannedRights.init), defaultBannedRights: defaultBannedRights.flatMap(TelegramChatBannedRights.init)) + case let .channelForbidden(flags, id, accessHash, title, untilDate): + let info: TelegramChannelInfo + if (flags & Int32(1 << 8)) != 0 { + info = .group(TelegramChannelGroupInfo(flags: [])) + } else { + info = .broadcast(TelegramChannelBroadcastInfo(flags: [])) + } + + return TelegramChannel(id: PeerId(namespace: Namespaces.Peer.CloudChannel, id: id), accessHash: .personal(accessHash), title: title, username: nil, photo: [], creationDate: 0, version: 0, participationStatus: .kicked, info: info, flags: TelegramChannelFlags(), restrictionInfo: nil, adminRights: nil, bannedRights: TelegramChatBannedRights(flags: [.banReadMessages], untilDate: untilDate ?? Int32.max), defaultBannedRights: nil) } } @@ -121,7 +129,8 @@ func mergeGroupOrChannel(lhs: Peer?, rhs: Api.Chat) -> Peer? { case .chat, .chatEmpty, .chatForbidden, .channelForbidden: return parseTelegramGroupOrChannel(chat: rhs) case let .channel(flags, _, accessHash, title, username, photo, _, _, _, _, _, defaultBannedRights, _/*feed*//*, feedId*/): - if accessHash != nil && (flags & (1 << 12)) == 0 { + let isMin = (flags & (1 << 12)) != 0 + if accessHash != nil && !isMin { return parseTelegramGroupOrChannel(chat: rhs) } else if let lhs = lhs as? TelegramChannel { var channelFlags = lhs.flags @@ -132,11 +141,11 @@ func mergeGroupOrChannel(lhs: Peer?, rhs: Api.Chat) -> Peer? { } var info = lhs.info switch info { - case .broadcast: - break - case .group: - let infoFlags = TelegramChannelGroupFlags() - info = .group(TelegramChannelGroupInfo(flags: infoFlags)) + case .broadcast: + break + case .group: + let infoFlags = TelegramChannelGroupFlags() + info = .group(TelegramChannelGroupInfo(flags: infoFlags)) } return TelegramChannel(id: lhs.id, accessHash: lhs.accessHash, title: title, username: username, photo: imageRepresentationsForApiChatPhoto(photo), creationDate: lhs.creationDate, version: lhs.version, participationStatus: lhs.participationStatus, info: info, flags: channelFlags, restrictionInfo: lhs.restrictionInfo, adminRights: lhs.adminRights, bannedRights: lhs.bannedRights, defaultBannedRights: defaultBannedRights.flatMap(TelegramChatBannedRights.init)) } else { diff --git a/submodules/TelegramCore/TelegramCore/ApiUtils.swift b/submodules/TelegramCore/TelegramCore/ApiUtils.swift index 88633421d9..c425388858 100644 --- a/submodules/TelegramCore/TelegramCore/ApiUtils.swift +++ b/submodules/TelegramCore/TelegramCore/ApiUtils.swift @@ -56,7 +56,7 @@ public enum PeerReference: PostboxCoding, Hashable, Equatable { switch peer { case let user as TelegramUser: if let accessHash = user.accessHash { - self = .user(id: user.id.id, accessHash: accessHash) + self = .user(id: user.id.id, accessHash: accessHash.value) } else { return nil } @@ -64,7 +64,7 @@ public enum PeerReference: PostboxCoding, Hashable, Equatable { self = .group(id: group.id.id) case let channel as TelegramChannel: if let accessHash = channel.accessHash { - self = .channel(id: channel.id.id, accessHash: accessHash) + self = .channel(id: channel.id.id, accessHash: accessHash.value) } else { return nil } @@ -104,12 +104,12 @@ public enum PeerReference: PostboxCoding, Hashable, Equatable { func forceApiInputPeer(_ peer: Peer) -> Api.InputPeer? { switch peer { case let user as TelegramUser: - return Api.InputPeer.inputPeerUser(userId: user.id.id, accessHash: user.accessHash ?? 0) + return Api.InputPeer.inputPeerUser(userId: user.id.id, accessHash: user.accessHash?.value ?? 0) case let group as TelegramGroup: return Api.InputPeer.inputPeerChat(chatId: group.id.id) case let channel as TelegramChannel: if let accessHash = channel.accessHash { - return Api.InputPeer.inputPeerChannel(channelId: channel.id.id, accessHash: accessHash) + return Api.InputPeer.inputPeerChannel(channelId: channel.id.id, accessHash: accessHash.value) } else { return nil } @@ -121,12 +121,12 @@ func forceApiInputPeer(_ peer: Peer) -> Api.InputPeer? { func apiInputPeer(_ peer: Peer) -> Api.InputPeer? { switch peer { case let user as TelegramUser where user.accessHash != nil: - return Api.InputPeer.inputPeerUser(userId: user.id.id, accessHash: user.accessHash!) + return Api.InputPeer.inputPeerUser(userId: user.id.id, accessHash: user.accessHash!.value) case let group as TelegramGroup: return Api.InputPeer.inputPeerChat(chatId: group.id.id) case let channel as TelegramChannel: if let accessHash = channel.accessHash { - return Api.InputPeer.inputPeerChannel(channelId: channel.id.id, accessHash: accessHash) + return Api.InputPeer.inputPeerChannel(channelId: channel.id.id, accessHash: accessHash.value) } else { return nil } @@ -137,7 +137,7 @@ func apiInputPeer(_ peer: Peer) -> Api.InputPeer? { func apiInputChannel(_ peer: Peer) -> Api.InputChannel? { if let channel = peer as? TelegramChannel, let accessHash = channel.accessHash { - return Api.InputChannel.inputChannel(channelId: channel.id.id, accessHash: accessHash) + return Api.InputChannel.inputChannel(channelId: channel.id.id, accessHash: accessHash.value) } else { return nil } @@ -145,7 +145,7 @@ func apiInputChannel(_ peer: Peer) -> Api.InputChannel? { func apiInputUser(_ peer: Peer) -> Api.InputUser? { if let user = peer as? TelegramUser, let accessHash = user.accessHash { - return Api.InputUser.inputUser(userId: user.id.id, accessHash: accessHash) + return Api.InputUser.inputUser(userId: user.id.id, accessHash: accessHash.value) } else { return nil } diff --git a/submodules/TelegramCore/TelegramCore/LoadedPeerFromMessage.swift b/submodules/TelegramCore/TelegramCore/LoadedPeerFromMessage.swift index 2b88bda0b0..fe45b47b32 100644 --- a/submodules/TelegramCore/TelegramCore/LoadedPeerFromMessage.swift +++ b/submodules/TelegramCore/TelegramCore/LoadedPeerFromMessage.swift @@ -12,7 +12,7 @@ public func loadedPeerFromMessage(account: Account, peerId: PeerId, messageId: M return account.postbox.transaction { transaction -> Signal in if let peer = transaction.getPeer(peerId) { if let user = peer as? TelegramUser { - if user.accessHash != 0 { + if let accessHash = user.accessHash, accessHash.value != 0 { return .single(user) } else { let messageSignal: Signal? @@ -50,7 +50,7 @@ public func loadedPeerFromMessage(account: Account, peerId: PeerId, messageId: M for user in apiUsers { let telegramUser = TelegramUser(user: user) - if telegramUser.id == peerId && telegramUser.accessHash != 0 { + if telegramUser.id == peerId, let accessHash = telegramUser.accessHash, accessHash.value != 0 { if let presence = TelegramUserPresence(apiUser: user) { updatePeerPresences(transaction: transaction, accountPeerId: account.peerId, peerPresences: [telegramUser.id: presence]) } diff --git a/submodules/TelegramCore/TelegramCore/PeerAccessHash.swift b/submodules/TelegramCore/TelegramCore/PeerAccessHash.swift index 44a5c34699..926e2b882d 100644 --- a/submodules/TelegramCore/TelegramCore/PeerAccessHash.swift +++ b/submodules/TelegramCore/TelegramCore/PeerAccessHash.swift @@ -3,4 +3,13 @@ import Foundation public enum TelegramPeerAccessHash: Hashable { case personal(Int64) case genericPublic(Int64) + + public var value: Int64 { + switch self { + case let .personal(personal): + return personal + case let .genericPublic(genericPublic): + return genericPublic + } + } } diff --git a/submodules/TelegramCore/TelegramCore/TelegramChannel.swift b/submodules/TelegramCore/TelegramCore/TelegramChannel.swift index 2b2326c650..0ccf6f3f62 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramChannel.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramChannel.swift @@ -148,7 +148,7 @@ public struct TelegramChannelFlags: OptionSet { public final class TelegramChannel: Peer { public let id: PeerId - public let accessHash: Int64? + public let accessHash: TelegramPeerAccessHash? public let title: String public let username: String? public let photo: [TelegramMediaImageRepresentation] @@ -169,7 +169,7 @@ public final class TelegramChannel: Peer { public let associatedPeerId: PeerId? = nil public let notificationSettingsPeerId: PeerId? = nil - public init(id: PeerId, accessHash: Int64?, title: String, username: String?, photo: [TelegramMediaImageRepresentation], creationDate: Int32, version: Int32, participationStatus: TelegramChannelParticipationStatus, info: TelegramChannelInfo, flags: TelegramChannelFlags, restrictionInfo: PeerAccessRestrictionInfo?, adminRights: TelegramChatAdminRights?, bannedRights: TelegramChatBannedRights?, defaultBannedRights: TelegramChatBannedRights?) { + public init(id: PeerId, accessHash: TelegramPeerAccessHash?, title: String, username: String?, photo: [TelegramMediaImageRepresentation], creationDate: Int32, version: Int32, participationStatus: TelegramChannelParticipationStatus, info: TelegramChannelInfo, flags: TelegramChannelFlags, restrictionInfo: PeerAccessRestrictionInfo?, adminRights: TelegramChatAdminRights?, bannedRights: TelegramChatBannedRights?, defaultBannedRights: TelegramChatBannedRights?) { self.id = id self.accessHash = accessHash self.title = title @@ -188,7 +188,17 @@ public final class TelegramChannel: Peer { public init(decoder: PostboxDecoder) { self.id = PeerId(decoder.decodeInt64ForKey("i", orElse: 0)) - self.accessHash = decoder.decodeOptionalInt64ForKey("ah") + let accessHash = decoder.decodeOptionalInt64ForKey("ah") + let accessHashType: Int32 = decoder.decodeInt32ForKey("aht", orElse: 0) + if let accessHash = accessHash { + if accessHashType == 0 { + self.accessHash = .personal(accessHash) + } else { + self.accessHash = .genericPublic(accessHash) + } + } else { + self.accessHash = nil + } self.title = decoder.decodeStringForKey("t", orElse: "") self.username = decoder.decodeOptionalStringForKey("un") self.photo = decoder.decodeObjectArrayForKey("ph") @@ -206,7 +216,14 @@ public final class TelegramChannel: Peer { public func encode(_ encoder: PostboxEncoder) { encoder.encodeInt64(self.id.toInt64(), forKey: "i") if let accessHash = self.accessHash { - encoder.encodeInt64(accessHash, forKey: "ah") + switch accessHash { + case let .personal(value): + encoder.encodeInt64(value, forKey: "ah") + encoder.encodeInt32(0, forKey: "aht") + case let .genericPublic(value): + encoder.encodeInt64(value, forKey: "ah") + encoder.encodeInt32(1, forKey: "aht") + } } else { encoder.encodeNil(forKey: "ah") } diff --git a/submodules/TelegramCore/TelegramCore/TelegramUser.swift b/submodules/TelegramCore/TelegramCore/TelegramUser.swift index 16769be20f..621cb5f2d4 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramUser.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramUser.swift @@ -61,15 +61,11 @@ public struct BotUserInfo: PostboxCoding, Equatable { encoder.encodeNil(forKey: "ip") } } - - public static func ==(lhs: BotUserInfo, rhs: BotUserInfo) -> Bool { - return lhs.flags == rhs.flags && lhs.inlinePlaceholder == rhs.inlinePlaceholder - } } public final class TelegramUser: Peer { public let id: PeerId - public let accessHash: Int64? + public let accessHash: TelegramPeerAccessHash? public let firstName: String? public let lastName: String? public let username: String? @@ -100,7 +96,7 @@ public final class TelegramUser: Peer { public let associatedPeerId: PeerId? = nil public let notificationSettingsPeerId: PeerId? = nil - public init(id: PeerId, accessHash: Int64?, firstName: String?, lastName: String?, username: String?, phone: String?, photo: [TelegramMediaImageRepresentation], botInfo: BotUserInfo?, restrictionInfo: PeerAccessRestrictionInfo?, flags: UserInfoFlags) { + public init(id: PeerId, accessHash: TelegramPeerAccessHash?, firstName: String?, lastName: String?, username: String?, phone: String?, photo: [TelegramMediaImageRepresentation], botInfo: BotUserInfo?, restrictionInfo: PeerAccessRestrictionInfo?, flags: UserInfoFlags) { self.id = id self.accessHash = accessHash self.firstName = firstName @@ -117,8 +113,13 @@ public final class TelegramUser: Peer { self.id = PeerId(decoder.decodeInt64ForKey("i", orElse: 0)) let accessHash: Int64 = decoder.decodeInt64ForKey("ah", orElse: 0) + let accessHashType: Int32 = decoder.decodeInt32ForKey("aht", orElse: 0) if accessHash != 0 { - self.accessHash = accessHash + if accessHashType == 0 { + self.accessHash = .personal(accessHash) + } else { + self.accessHash = .genericPublic(accessHash) + } } else { self.accessHash = nil } @@ -146,7 +147,14 @@ public final class TelegramUser: Peer { encoder.encodeInt64(self.id.toInt64(), forKey: "i") if let accessHash = self.accessHash { - encoder.encodeInt64(accessHash, forKey: "ah") + switch accessHash { + case let .personal(value): + encoder.encodeInt64(value, forKey: "ah") + encoder.encodeInt32(0, forKey: "aht") + case let .genericPublic(value): + encoder.encodeInt64(value, forKey: "ah") + encoder.encodeInt32(1, forKey: "aht") + } } if let firstName = self.firstName { @@ -242,7 +250,7 @@ public final class TelegramUser: Peer { func parsedTelegramProfilePhoto(_ photo: Api.UserProfilePhoto) -> [TelegramMediaImageRepresentation] { var representations: [TelegramMediaImageRepresentation] = [] switch photo { - case let .userProfilePhoto(photoId, photoSmall, photoBig, dcId): + case let .userProfilePhoto(_, photoSmall, photoBig, dcId): let smallResource: TelegramMediaResource let fullSizeResource: TelegramMediaResource switch photoSmall { @@ -267,6 +275,15 @@ extension TelegramUser { case let .user(flags, id, accessHash, firstName, lastName, username, phone, photo, _, _, restrictionReason, botInlinePlaceholder, _): let representations: [TelegramMediaImageRepresentation] = photo.flatMap(parsedTelegramProfilePhoto) ?? [] + let isMin = (flags & (1 << 20)) != 0 + let accessHashValue = accessHash.flatMap { value -> TelegramPeerAccessHash in + if isMin { + return .genericPublic(value) + } else { + return .personal(value) + } + } + var userFlags: UserInfoFlags = [] if (flags & (1 << 17)) != 0 { userFlags.insert(.isVerified) @@ -295,7 +312,7 @@ extension TelegramUser { let restrictionInfo: PeerAccessRestrictionInfo? = restrictionReason.flatMap(PeerAccessRestrictionInfo.init) - self.init(id: PeerId(namespace: Namespaces.Peer.CloudUser, id: id), accessHash: accessHash, firstName: firstName, lastName: lastName, username: username, phone: phone, photo: representations, botInfo: botInfo, restrictionInfo: restrictionInfo, flags: userFlags) + self.init(id: PeerId(namespace: Namespaces.Peer.CloudUser, id: id), accessHash: accessHashValue, firstName: firstName, lastName: lastName, username: username, phone: phone, photo: representations, botInfo: botInfo, restrictionInfo: restrictionInfo, flags: userFlags) case let .userEmpty(id): self.init(id: PeerId(namespace: Namespaces.Peer.CloudUser, id: id), accessHash: nil, firstName: nil, lastName: nil, username: nil, phone: nil, photo: [], botInfo: nil, restrictionInfo: nil, flags: []) } @@ -303,7 +320,7 @@ extension TelegramUser { static func merge(_ lhs: TelegramUser?, rhs: Api.User) -> TelegramUser? { switch rhs { - case let .user(flags, _, _, _, _, username, _, photo, _, _, restrictionReason, botInlinePlaceholder, _): + case let .user(flags, _, rhsAccessHash, _, _, username, _, photo, _, _, restrictionReason, botInlinePlaceholder, _): let isMin = (flags & (1 << 20)) != 0 if !isMin { return TelegramUser(user: rhs) @@ -338,7 +355,22 @@ extension TelegramUser { let restrictionInfo: PeerAccessRestrictionInfo? = restrictionReason.flatMap(PeerAccessRestrictionInfo.init) - return TelegramUser(id: lhs.id, accessHash: lhs.accessHash, firstName: lhs.firstName, lastName: lhs.lastName, username: username, phone: lhs.phone, photo: telegramPhoto, botInfo: botInfo, restrictionInfo: restrictionInfo, flags: userFlags) + let rhsAccessHashValue = rhsAccessHash.flatMap { value -> TelegramPeerAccessHash in + if isMin { + return .genericPublic(value) + } else { + return .personal(value) + } + } + + let accessHash: TelegramPeerAccessHash? + if let rhsAccessHashValue = rhsAccessHashValue, case .personal = rhsAccessHashValue { + accessHash = rhsAccessHashValue + } else { + accessHash = lhs.accessHash ?? rhsAccessHashValue + } + + return TelegramUser(id: lhs.id, accessHash: accessHash, firstName: lhs.firstName, lastName: lhs.lastName, username: username, phone: lhs.phone, photo: telegramPhoto, botInfo: botInfo, restrictionInfo: restrictionInfo, flags: userFlags) } else { return TelegramUser(user: rhs) } diff --git a/submodules/TelegramUI/TelegramUI/ChatInterfaceStateInputPanels.swift b/submodules/TelegramUI/TelegramUI/ChatInterfaceStateInputPanels.swift index 2a54350303..defa532eaf 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInterfaceStateInputPanels.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInterfaceStateInputPanels.swift @@ -58,23 +58,6 @@ func inputPanelForChatPresentationIntefaceState(_ chatPresentationInterfaceState var displayInputTextPanel = false - /*if case .group = chatPresentationInterfaceState.chatLocation { - if chatPresentationInterfaceState.interfaceState.editMessage != nil { - displayInputTextPanel = true - } else { - if let currentPanel = currentPanel as? ChatFeedNavigationInputPanelNode { - currentPanel.interfaceInteraction = interfaceInteraction - currentPanel.updateThemeAndStrings(theme: chatPresentationInterfaceState.theme, strings: chatPresentationInterfaceState.strings) - return currentPanel - } else { - let panel = ChatFeedNavigationInputPanelNode(theme: chatPresentationInterfaceState.theme, strings: chatPresentationInterfaceState.strings) - panel.context = context - panel.interfaceInteraction = interfaceInteraction - return panel - } - } - }*/ - if let peer = chatPresentationInterfaceState.renderedPeer?.peer { if let secretChat = peer as? TelegramSecretChat { switch secretChat.embeddedState { @@ -100,7 +83,24 @@ func inputPanelForChatPresentationIntefaceState(_ chatPresentationInterfaceState break } } else if let channel = peer as? TelegramChannel { - if channel.hasBannedPermission(.banSendMessages) != nil { + var isMember: Bool = false + switch channel.participationStatus { + case .kicked: + if let currentPanel = currentPanel as? DeleteChatInputPanelNode { + return currentPanel + } else { + let panel = DeleteChatInputPanelNode() + panel.context = context + panel.interfaceInteraction = interfaceInteraction + return panel + } + case .member: + isMember = true + case .left: + break + } + + if isMember && channel.hasBannedPermission(.banSendMessages) != nil { if let currentPanel = currentPanel as? ChatRestrictedInputPanelNode { return currentPanel } else { @@ -111,61 +111,48 @@ func inputPanelForChatPresentationIntefaceState(_ chatPresentationInterfaceState } } - switch channel.participationStatus { - case .kicked: - if let currentPanel = currentPanel as? DeleteChatInputPanelNode { + switch channel.info { + case .broadcast: + if chatPresentationInterfaceState.interfaceState.editMessage != nil, channel.hasPermission(.editAllMessages) { + displayInputTextPanel = true + } else if !channel.hasPermission(.sendMessages) { + if let currentPanel = currentPanel as? ChatChannelSubscriberInputPanelNode { return currentPanel } else { - let panel = DeleteChatInputPanelNode() - panel.context = context + let panel = ChatChannelSubscriberInputPanelNode() panel.interfaceInteraction = interfaceInteraction + panel.context = context return panel } - case .member, .left: + } + case .group: + switch channel.participationStatus { + case .kicked, .left: + if let currentPanel = currentPanel as? ChatChannelSubscriberInputPanelNode { + return currentPanel + } else { + let panel = ChatChannelSubscriberInputPanelNode() + panel.interfaceInteraction = interfaceInteraction + panel.context = context + return panel + } + case .member: break - } - switch channel.info { - case .broadcast: - if chatPresentationInterfaceState.interfaceState.editMessage != nil, channel.hasPermission(.editAllMessages) { - displayInputTextPanel = true - } else if !channel.hasPermission(.sendMessages) { - if let currentPanel = currentPanel as? ChatChannelSubscriberInputPanelNode { - return currentPanel - } else { - let panel = ChatChannelSubscriberInputPanelNode() - panel.interfaceInteraction = interfaceInteraction - panel.context = context - return panel - } - } - case .group: - switch channel.participationStatus { - case .kicked, .left: - if let currentPanel = currentPanel as? ChatChannelSubscriberInputPanelNode { - return currentPanel - } else { - let panel = ChatChannelSubscriberInputPanelNode() - panel.interfaceInteraction = interfaceInteraction - panel.context = context - return panel - } - case .member: - break - } + } } } else if let group = peer as? TelegramGroup { switch group.membership { - case .Removed, .Left: - if let currentPanel = currentPanel as? DeleteChatInputPanelNode { - return currentPanel - } else { - let panel = DeleteChatInputPanelNode() - panel.context = context - panel.interfaceInteraction = interfaceInteraction - return panel - } - case .Member: - break + case .Removed, .Left: + if let currentPanel = currentPanel as? DeleteChatInputPanelNode { + return currentPanel + } else { + let panel = DeleteChatInputPanelNode() + panel.context = context + panel.interfaceInteraction = interfaceInteraction + return panel + } + case .Member: + break } if group.hasBannedPermission(.banSendMessages) { diff --git a/submodules/TelegramUI/TelegramUI/LegacyUserDataImport.swift b/submodules/TelegramUI/TelegramUI/LegacyUserDataImport.swift index e734efb6d0..e4019e944c 100644 --- a/submodules/TelegramUI/TelegramUI/LegacyUserDataImport.swift +++ b/submodules/TelegramUI/TelegramUI/LegacyUserDataImport.swift @@ -23,7 +23,7 @@ func loadLegacyUser(database: SqliteInterface, id: Int32) -> (TelegramUser, Tele photo.append(TelegramMediaImageRepresentation(dimensions: CGSize(width: 600.0, height: 600.0), resource: resource)) } - let user = TelegramUser(id: PeerId(namespace: Namespaces.Peer.CloudUser, id: cursor.getInt32(at: 0)), accessHash: accessHash == 0 ? nil : accessHash, firstName: firstName.isEmpty ? nil : firstName, lastName: lastName.isEmpty ? nil : lastName, username: username.isEmpty ? nil : username, phone: phone.isEmpty ? nil : phone, photo: photo, botInfo: nil, restrictionInfo: nil, flags: []) + let user = TelegramUser(id: PeerId(namespace: Namespaces.Peer.CloudUser, id: cursor.getInt32(at: 0)), accessHash: accessHash == 0 ? nil : .personal(accessHash), firstName: firstName.isEmpty ? nil : firstName, lastName: lastName.isEmpty ? nil : lastName, username: username.isEmpty ? nil : username, phone: phone.isEmpty ? nil : phone, photo: photo, botInfo: nil, restrictionInfo: nil, flags: []) let status: UserPresenceStatus let lastSeen = cursor.getInt32(at: 7) diff --git a/submodules/TelegramUI/TelegramUI_Xcode.xcodeproj/project.pbxproj b/submodules/TelegramUI/TelegramUI_Xcode.xcodeproj/project.pbxproj index 1a91a019e9..6f94f522e0 100644 --- a/submodules/TelegramUI/TelegramUI_Xcode.xcodeproj/project.pbxproj +++ b/submodules/TelegramUI/TelegramUI_Xcode.xcodeproj/project.pbxproj @@ -338,6 +338,8 @@ D03AA4DF202DBF6F0056C405 /* ChatContextResultPeekContentNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D03AA4DE202DBF6F0056C405 /* ChatContextResultPeekContentNode.swift */; }; D03AA4E5202DF8840056C405 /* StickerPreviewPeekContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D03AA4E4202DF8840056C405 /* StickerPreviewPeekContent.swift */; }; D03AA4E7202DFB160056C405 /* ItemListEditableReorderControlNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D03AA4E6202DFB160056C405 /* ItemListEditableReorderControlNode.swift */; }; + D03AE67322B9459C0078411C /* HockeySDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D03AE67222B9459C0078411C /* HockeySDK.framework */; }; + D03AE67522B945D30078411C /* BuildConfig.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D03AE67422B945D30078411C /* BuildConfig.framework */; }; D04203152037162700490EA5 /* MediaInputPaneTrendingItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04203142037162700490EA5 /* MediaInputPaneTrendingItem.swift */; }; D04281ED200E3B28009DDE36 /* ItemListControllerSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04281EC200E3B28009DDE36 /* ItemListControllerSearch.swift */; }; D04281EF200E3D88009DDE36 /* GroupInfoSearchItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04281EE200E3D88009DDE36 /* GroupInfoSearchItem.swift */; }; @@ -1611,6 +1613,8 @@ D03ADB4A1D70443F005A521C /* ReplyAccessoryPanelNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReplyAccessoryPanelNode.swift; sourceTree = ""; }; D03ADB4C1D7045C9005A521C /* ChatInterfaceStateAccessoryPanels.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatInterfaceStateAccessoryPanels.swift; sourceTree = ""; }; D03ADB4E1D70546B005A521C /* AccessoryPanelNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccessoryPanelNode.swift; sourceTree = ""; }; + D03AE67222B9459C0078411C /* HockeySDK.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = HockeySDK.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + D03AE67422B945D30078411C /* BuildConfig.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = BuildConfig.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D03E5E081E55C49C0029569A /* DebugAccountsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DebugAccountsController.swift; sourceTree = ""; }; D03E5E0E1E55F8B90029569A /* ChannelVisibilityController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChannelVisibilityController.swift; sourceTree = ""; }; D04203142037162700490EA5 /* MediaInputPaneTrendingItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaInputPaneTrendingItem.swift; sourceTree = ""; }; @@ -2395,6 +2399,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + D03AE67522B945D30078411C /* BuildConfig.framework in Frameworks */, + D03AE67322B9459C0078411C /* HockeySDK.framework in Frameworks */, D02D634A22B85B94006BE519 /* PushKit.framework in Frameworks */, D00818CD22B595CB008A895F /* LightweightAccountData.framework in Frameworks */, D008184A22B57225008A895F /* WatchCommon.framework in Frameworks */, @@ -3514,6 +3520,8 @@ D08D45281D5E340200A7428A /* Frameworks */ = { isa = PBXGroup; children = ( + D03AE67422B945D30078411C /* BuildConfig.framework */, + D03AE67222B9459C0078411C /* HockeySDK.framework */, D02D634922B85B94006BE519 /* PushKit.framework */, D00818CC22B595CB008A895F /* LightweightAccountData.framework */, D008184922B57225008A895F /* WatchCommon.framework */,