diff --git a/TelegramCore.xcodeproj/project.pbxproj b/TelegramCore.xcodeproj/project.pbxproj index b7402ef7fe..37eaf63f77 100644 --- a/TelegramCore.xcodeproj/project.pbxproj +++ b/TelegramCore.xcodeproj/project.pbxproj @@ -312,6 +312,10 @@ D050F26C1E4A5B6D00988324 /* UpdatePeers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BC386F1E40853E0044D6FE /* UpdatePeers.swift */; }; D050F26D1E4A5B6D00988324 /* CreateGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BC386D1E3FDAB70044D6FE /* CreateGroup.swift */; }; D050F26E1E4A5B6D00988324 /* RemovePeerChat.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BC38741E40A7F70044D6FE /* RemovePeerChat.swift */; }; + D051DB14215EC5A300F30F92 /* AppChangelogState.swift in Sources */ = {isa = PBXBuildFile; fileRef = D051DB13215EC5A300F30F92 /* AppChangelogState.swift */; }; + D051DB15215EC5A300F30F92 /* AppChangelogState.swift in Sources */ = {isa = PBXBuildFile; fileRef = D051DB13215EC5A300F30F92 /* AppChangelogState.swift */; }; + D051DB17215ECC4D00F30F92 /* AppChangelog.swift in Sources */ = {isa = PBXBuildFile; fileRef = D051DB16215ECC4D00F30F92 /* AppChangelog.swift */; }; + D051DB18215ECC4D00F30F92 /* AppChangelog.swift in Sources */ = {isa = PBXBuildFile; fileRef = D051DB16215ECC4D00F30F92 /* AppChangelog.swift */; }; D0528E5A1E658B3600E2FEF5 /* ManagedLocalInputActivities.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0528E591E658B3600E2FEF5 /* ManagedLocalInputActivities.swift */; }; D0528E5B1E658B3600E2FEF5 /* ManagedLocalInputActivities.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0528E591E658B3600E2FEF5 /* ManagedLocalInputActivities.swift */; }; D0528E601E65B94E00E2FEF5 /* SingleMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0528E5F1E65B94E00E2FEF5 /* SingleMessageView.swift */; }; @@ -915,6 +919,8 @@ D04D8FF3209A4B0700865719 /* NetworkSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkSettings.swift; sourceTree = ""; }; D050F20F1E48AB0600988324 /* InteractivePhoneFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InteractivePhoneFormatter.swift; sourceTree = ""; }; D050F2501E4A59C200988324 /* JoinLink.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JoinLink.swift; sourceTree = ""; }; + D051DB13215EC5A300F30F92 /* AppChangelogState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppChangelogState.swift; sourceTree = ""; }; + D051DB16215ECC4D00F30F92 /* AppChangelog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppChangelog.swift; sourceTree = ""; }; D0528E591E658B3600E2FEF5 /* ManagedLocalInputActivities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedLocalInputActivities.swift; sourceTree = ""; }; D0528E5F1E65B94E00E2FEF5 /* SingleMessageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleMessageView.swift; sourceTree = ""; }; D0528E641E65C82400E2FEF5 /* UpdateContactName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateContactName.swift; sourceTree = ""; }; @@ -1206,6 +1212,7 @@ D0AF32301FACEDEC0097362B /* CoreSettings.swift */, D0FA08BA2046B37900DD23FC /* ContentPrivacySettings.swift */, D026099D20C695AF006C34AC /* Wallpapers.swift */, + D051DB13215EC5A300F30F92 /* AppChangelogState.swift */, ); name = Settings; sourceTree = ""; @@ -1533,6 +1540,7 @@ D099D7481EEF418D00A3128C /* HistoryViewChannelStateValidation.swift */, D0B1671C1F9EA2C300976B40 /* ChatHistoryPreloadManager.swift */, D06ECFC720B810D300C576C2 /* TermsOfService.swift */, + D051DB16215ECC4D00F30F92 /* AppChangelog.swift */, ); name = Account; sourceTree = ""; @@ -2267,6 +2275,7 @@ D0FA8BB91E2240B4001E855B /* SecretChatIncomingDecryptedOperation.swift in Sources */, D0561DE31E5737FC00E6B9E9 /* UpdatePeerInfo.swift in Sources */, D0DF0C8A1D819C7E008AEB01 /* JoinChannel.swift in Sources */, + D051DB14215EC5A300F30F92 /* AppChangelogState.swift in Sources */, D04CAA5A1E83310D0047E51F /* MD5.swift in Sources */, D0E817492010E7E300B82BBB /* ChannelAdminEventLogContext.swift in Sources */, D05452071E7B5093006EEF19 /* LoadedStickerPack.swift in Sources */, @@ -2369,6 +2378,7 @@ D0575AF41E9FFDDE006F2541 /* ManagedSynchronizeSavedGifsOperations.swift in Sources */, C2F4ED1D1EC60064005F2696 /* RateCall.swift in Sources */, D021E0E21DB5401A00C6B04F /* StickerManagement.swift in Sources */, + D051DB17215ECC4D00F30F92 /* AppChangelog.swift in Sources */, D0BC38701E40853E0044D6FE /* UpdatePeers.swift in Sources */, D0F3A8A81E82CD7D00B4C64C /* UpdatePeerChatInterfaceState.swift in Sources */, D03B0CE21D62249B00955575 /* InlineBotMessageAttribute.swift in Sources */, @@ -2445,6 +2455,7 @@ D03229F51E6B39700000AF9C /* ImportAccount.swift in Sources */, C239BE981E62F0D200C2C453 /* LoadMessagesIfNecessary.swift in Sources */, D01C7ED41EF5DF83008305F1 /* LimitsConfiguration.swift in Sources */, + D051DB15215EC5A300F30F92 /* AppChangelogState.swift in Sources */, C26A37EF1E5E0C41006977AC /* ChannelParticipants.swift in Sources */, D00D343D1E6EC9770057B307 /* TelegramMediaGame.swift in Sources */, D02609C020C6EC08006C34AC /* Crypto.m in Sources */, @@ -2607,6 +2618,7 @@ D073CEA51DCBF3F5007511FD /* StickerManagement.swift in Sources */, D06AFE8A20BF66BF00EA5124 /* DeserializeFunctionResponse.swift in Sources */, D03C536D1DAD5CA9004C17B3 /* ApiGroupOrChannel.swift in Sources */, + D051DB18215ECC4D00F30F92 /* AppChangelog.swift in Sources */, D01C06B81FBBA269001561AB /* CanSendMessagesToPeer.swift in Sources */, D0E35A151DE4C6A200BC6096 /* OutgoingMessageWithChatContextResult.swift in Sources */, D0B418A91D7E0597004562A4 /* Buffer.swift in Sources */, diff --git a/TelegramCore.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/TelegramCoreMac.xcscheme b/TelegramCore.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/TelegramCoreMac.xcscheme deleted file mode 100644 index ff4f8cfe5a..0000000000 --- a/TelegramCore.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/TelegramCoreMac.xcscheme +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/TelegramCore.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist b/TelegramCore.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist index 7678cfa759..264fdfd149 100644 --- a/TelegramCore.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/TelegramCore.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist @@ -9,11 +9,6 @@ orderHint 0 - TelegramCoreMac.xcscheme - - orderHint - 2 - SuppressBuildableAutocreation diff --git a/TelegramCore/Account.swift b/TelegramCore/Account.swift index 4ba028da95..e2c9928dda 100644 --- a/TelegramCore/Account.swift +++ b/TelegramCore/Account.swift @@ -267,6 +267,7 @@ private var declaredEncodables: Void = { declareEncodable(TelegramWallpaper.self, f: { TelegramWallpaper(decoder: $0) }) declareEncodable(SynchronizeMarkAllUnseenPersonalMessagesOperation.self, f: { SynchronizeMarkAllUnseenPersonalMessagesOperation(decoder: $0) }) declareEncodable(CachedRecentPeers.self, f: { CachedRecentPeers(decoder: $0) }) + declareEncodable(AppChangelogState.self, f: { AppChangelogState(decoder: $0) }) return @@ -339,7 +340,7 @@ public func accountWithId(networkArguments: NetworkInitializationArguments, id: |> mapToSignal { phoneNumber in return initializedNetwork(arguments: networkArguments, supplementary: supplementary, datacenterId: Int(authorizedState.masterDatacenterId), keychain: keychain, basePath: path, testingEnvironment: authorizedState.isTestingEnvironment, languageCode: localizationSettings?.languageCode, proxySettings: proxySettings, networkSettings: networkSettings, phoneNumber: phoneNumber) |> map { network -> AccountResult in - return .authorized(Account(id: id, basePath: path, testingEnvironment: authorizedState.isTestingEnvironment, postbox: postbox, network: network, peerId: authorizedState.peerId, auxiliaryMethods: auxiliaryMethods)) + return .authorized(Account(id: id, basePath: path, testingEnvironment: authorizedState.isTestingEnvironment, postbox: postbox, network: network, networkArguments: networkArguments, peerId: authorizedState.peerId, auxiliaryMethods: auxiliaryMethods)) } } case _: @@ -857,6 +858,7 @@ public class Account { public let testingEnvironment: Bool public let postbox: Postbox public let network: Network + let networkArguments: NetworkInitializationArguments public let peerId: PeerId public let auxiliaryMethods: AccountAuxiliaryMethods @@ -928,12 +930,13 @@ public class Account { var transformOutgoingMessageMedia: TransformOutgoingMessageMedia? - public init(id: AccountRecordId, basePath: String, testingEnvironment: Bool, postbox: Postbox, network: Network, peerId: PeerId, auxiliaryMethods: AccountAuxiliaryMethods) { + public init(id: AccountRecordId, basePath: String, testingEnvironment: Bool, postbox: Postbox, network: Network, networkArguments: NetworkInitializationArguments, peerId: PeerId, auxiliaryMethods: AccountAuxiliaryMethods) { self.id = id self.basePath = basePath self.testingEnvironment = testingEnvironment self.postbox = postbox self.network = network + self.networkArguments = networkArguments self.peerId = peerId self.auxiliaryMethods = auxiliaryMethods @@ -1044,15 +1047,15 @@ public class Account { #endif return masterNotificationsKey(account: self, ignoreDisabled: false) - |> mapToSignal { secret -> Signal in - return network.request(Api.functions.account.registerDevice(tokenType: 1, token: tokenString, appSandbox: appSandbox, secret: Buffer(data: secret.data), otherUids: [])) - |> retryRequest - |> mapToSignal { _ -> Signal in - return .complete() - } + |> mapToSignal { secret -> Signal in + return network.request(Api.functions.account.registerDevice(tokenType: 1, token: tokenString, appSandbox: appSandbox, secret: Buffer(data: secret.data), otherUids: [])) + |> retryRequest + |> mapToSignal { _ -> Signal in + return .complete() + } } } - self.notificationTokenDisposable.set(appliedNotificationToken.start()) + //self.notificationTokenDisposable.set(appliedNotificationToken.start()) let appliedVoipToken = combineLatest(self.voipToken.get(), self.notificationTokensVersionPromise.get()) |> distinctUntilChanged(isEqual: { $0 == $1 }) @@ -1071,8 +1074,8 @@ public class Account { #endif return masterNotificationsKey(account: self, ignoreDisabled: false) - |> mapToSignal { secret -> Signal in - return network.request(Api.functions.account.registerDevice(tokenType: 9, token: tokenString, appSandbox: appSandbox, secret: Buffer(data: secret.data), otherUids: [])) + |> mapToSignal { secret -> Signal in + return network.request(Api.functions.account.registerDevice(tokenType: 9, token: tokenString, appSandbox: appSandbox, secret: Buffer(data: secret.data), otherUids: [])) |> retryRequest |> mapToSignal { _ -> Signal in return .complete() @@ -1162,6 +1165,7 @@ public class Account { })) self.managedOperationsDisposable.add(managedConfigurationUpdates(postbox: self.postbox, network: self.network).start()) self.managedOperationsDisposable.add(managedTermsOfServiceUpdates(postbox: self.postbox, network: self.network, stateManager: self.stateManager).start()) + self.managedOperationsDisposable.add(managedAppChangelog(postbox: self.postbox, network: self.network, stateManager: self.stateManager, appVersion: self.networkArguments.appVersion).start()) self.managedOperationsDisposable.add(managedProxyInfoUpdates(postbox: self.postbox, network: self.network, viewTracker: self.viewTracker).start()) self.managedOperationsDisposable.add(managedLocalizationUpdatesOperations(postbox: self.postbox, network: self.network).start()) self.managedOperationsDisposable.add(managedPendingPeerNotificationSettings(postbox: self.postbox, network: self.network).start()) diff --git a/TelegramCore/AppChangelog.swift b/TelegramCore/AppChangelog.swift new file mode 100644 index 0000000000..79e702fa40 --- /dev/null +++ b/TelegramCore/AppChangelog.swift @@ -0,0 +1,55 @@ +import Foundation +#if os(macOS) +import PostboxMac +import SwiftSignalKitMac +import MtProtoKitMac +#else +import Postbox +import SwiftSignalKit +import MtProtoKitDynamic +#endif + +func initializedAppChangelogAfterLogin(transaction: Transaction, appVersion: String) { + updateAppChangelogState(transaction: transaction, { state in + var state = state + state.checkedVersion = appVersion + state.previousVersion = appVersion + return state + }) +} + +func managedAppChangelog(postbox: Postbox, network: Network, stateManager: AccountStateManager, appVersion: String) -> Signal { + return stateManager.pollStateUpdateCompletion() + |> take(1) + |> mapToSignal { _ -> Signal in + return postbox.transaction { transaction -> AppChangelogState in + return transaction.getPreferencesEntry(key: PreferencesKeys.appChangelogState) as? AppChangelogState ?? AppChangelogState.default + } + |> mapToSignal { appChangelogState -> Signal in + if appChangelogState.checkedVersion == appVersion { + return .complete() + } + let previousVersion = appChangelogState.previousVersion + return network.request(Api.functions.help.getAppChangelog(prevAppVersion: previousVersion)) + |> map(Optional.init) + |> `catch` { _ -> Signal in + return .single(nil) + } + |> mapToSignal { updates -> Signal in + if let updates = updates { + stateManager.addUpdates(updates) + } + + return postbox.transaction { transaction in + updateAppChangelogState(transaction: transaction, { state in + var state = state + state.checkedVersion = appVersion + state.previousVersion = appVersion + return state + }) + } + } + } + } +} + diff --git a/TelegramCore/AppChangelogState.swift b/TelegramCore/AppChangelogState.swift new file mode 100644 index 0000000000..47e71e7566 --- /dev/null +++ b/TelegramCore/AppChangelogState.swift @@ -0,0 +1,46 @@ +import Foundation +#if os(macOS) +import PostboxMac +import SwiftSignalKitMac +import MtProtoKitMac +#else +import Postbox +import SwiftSignalKit +import MtProtoKitDynamic +#endif + +struct AppChangelogState: PreferencesEntry, Equatable { + var checkedVersion: String + var previousVersion: String + + static var `default` = AppChangelogState(checkedVersion: "", previousVersion: "5.0.8") + + init(checkedVersion: String, previousVersion: String) { + self.checkedVersion = checkedVersion + self.previousVersion = previousVersion + } + + init(decoder: PostboxDecoder) { + self.checkedVersion = decoder.decodeStringForKey("checkedVersion", orElse: "") + self.previousVersion = decoder.decodeStringForKey("previousVersion", orElse: "") + } + + func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.checkedVersion, forKey: "checkedVersion") + encoder.encodeString(self.previousVersion, forKey: "previousVersion") + } + + func isEqual(to: PreferencesEntry) -> Bool { + guard let to = to as? AppChangelogState else { + return false + } + + return self == to + } +} + +func updateAppChangelogState(transaction: Transaction, _ f: @escaping (AppChangelogState) -> AppChangelogState) { + transaction.updatePreferencesEntry(key: PreferencesKeys.appChangelogState, { current in + return f((current as? AppChangelogState) ?? AppChangelogState.default) + }) +} diff --git a/TelegramCore/Authorization.swift b/TelegramCore/Authorization.swift index e88d1b032c..3384480c5c 100644 --- a/TelegramCore/Authorization.swift +++ b/TelegramCore/Authorization.swift @@ -222,6 +222,7 @@ public func authorizeWithCode(account: UnauthorizedAccount, code: String, termsO case let .authorization(_, _, user): let user = TelegramUser(user: user) let state = AuthorizedAccountState(isTestingEnvironment: account.testingEnvironment, masterDatacenterId: account.masterDatacenterId, peerId: user.id, state: nil) + initializedAppChangelogAfterLogin(transaction: transaction, appVersion: account.networkArguments.appVersion) transaction.setState(state) } return .loggedIn @@ -277,6 +278,7 @@ public func authorizeWithPassword(account: UnauthorizedAccount, password: String /*transaction.updatePeersInternal([user], update: { current, peer -> Peer? in return peer })*/ + initializedAppChangelogAfterLogin(transaction: transaction, appVersion: account.networkArguments.appVersion) transaction.setState(state) } } @@ -346,6 +348,7 @@ public func performPasswordRecovery(account: UnauthorizedAccount, code: String) /*transaction.updatePeersInternal([user], update: { current, peer -> Peer? in return peer })*/ + initializedAppChangelogAfterLogin(transaction: transaction, appVersion: account.networkArguments.appVersion) transaction.setState(state) } } |> mapError { _ in return PasswordRecoveryError.expired } @@ -429,6 +432,7 @@ public func signUpWithName(account: UnauthorizedAccount, firstName: String, last let user = TelegramUser(user: user) let appliedState = account.postbox.transaction { transaction -> Void in let state = AuthorizedAccountState(isTestingEnvironment: account.testingEnvironment, masterDatacenterId: account.masterDatacenterId, peerId: user.id, state: nil) + initializedAppChangelogAfterLogin(transaction: transaction, appVersion: account.networkArguments.appVersion) transaction.setState(state) } |> introduceError(SignUpError.self) diff --git a/TelegramCore/Namespaces.swift b/TelegramCore/Namespaces.swift index 71f70b36b9..e83bccfbdc 100644 --- a/TelegramCore/Namespaces.swift +++ b/TelegramCore/Namespaces.swift @@ -140,6 +140,7 @@ private enum PreferencesKeyValues: Int32 { case networkSettings = 9 case remoteStorageConfiguration = 10 case voipConfiguration = 11 + case appChangelogState = 12 } public func applicationSpecificPreferencesKey(_ value: Int32) -> ValueBoxKey { @@ -220,4 +221,10 @@ public struct PreferencesKeys { key.setInt32(0, value: PreferencesKeyValues.voipConfiguration.rawValue) return key }() + + public static let appChangelogState: ValueBoxKey = { + let key = ValueBoxKey(length: 4) + key.setInt32(0, value: PreferencesKeyValues.appChangelogState.rawValue) + return key + }() } diff --git a/TelegramCore/Network.swift b/TelegramCore/Network.swift index ac54377524..9bf52fca1f 100644 --- a/TelegramCore/Network.swift +++ b/TelegramCore/Network.swift @@ -334,10 +334,12 @@ func networkUsageStats(basePath: String, reset: ResetNetworkUsageStats) -> Signa public struct NetworkInitializationArguments { public let apiId: Int32 public let languagesCategory: String + public let appVersion: String - public init(apiId: Int32, languagesCategory: String) { + public init(apiId: Int32, languagesCategory: String, appVersion: String) { self.apiId = apiId self.languagesCategory = languagesCategory + self.appVersion = appVersion } } diff --git a/TelegramCore/PendingMessageManager.swift b/TelegramCore/PendingMessageManager.swift index e16f309459..59ad2c3848 100644 --- a/TelegramCore/PendingMessageManager.swift +++ b/TelegramCore/PendingMessageManager.swift @@ -153,6 +153,7 @@ public final class PendingMessageManager { self.queue.async { let addedMessageIds = messageIds.subtracting(self.pendingMessageIds) let removedMessageIds = self.pendingMessageIds.subtracting(messageIds) + let removedSecretMessageIds = Set(removedMessageIds.filter({ $0.peerId.namespace == Namespaces.Peer.SecretChat })) var updateUploadingPeerIds = Set() var updateUploadingGroupIds = Set() @@ -194,6 +195,32 @@ public final class PendingMessageManager { self.beginSendingGroupIfPossible(groupId: groupId) } + if !removedSecretMessageIds.isEmpty { + let _ = (self.postbox.transaction { transaction -> Set in + var peerIdsWithDeliveredMessages = Set() + for id in removedSecretMessageIds { + if let message = transaction.getMessage(id) { + if message.isSentOrAcknowledged { + peerIdsWithDeliveredMessages.insert(id.peerId) + } + } + } + return peerIdsWithDeliveredMessages + } + |> deliverOn(self.queue)).start(next: { [weak self] peerIdsWithDeliveredMessages in + guard let strongSelf = self else { + return + } + for peerId in peerIdsWithDeliveredMessages { + if let context = strongSelf.peerSummaryContexts[peerId] { + for subscriber in context.messageDeliveredSubscribers.copyItems() { + subscriber() + } + } + } + }) + } + self._hasPendingMessages.set(!self.pendingMessageIds.isEmpty) } } @@ -962,7 +989,8 @@ public final class PendingMessageManager { } private func applySentMessage(postbox: Postbox, stateManager: AccountStateManager, message: Message, result: Api.Updates) -> Signal { - return applyUpdateMessage(postbox: postbox, stateManager: stateManager, message: message, result: result) |> afterDisposed { [weak self] in + return applyUpdateMessage(postbox: postbox, stateManager: stateManager, message: message, result: result) + |> afterDisposed { [weak self] in if let strongSelf = self { strongSelf.queue.async { if let context = strongSelf.peerSummaryContexts[message.id.peerId] { diff --git a/TelegramCore/ProxySettings.swift b/TelegramCore/ProxySettings.swift index 47fcc356fc..2e6d00efed 100644 --- a/TelegramCore/ProxySettings.swift +++ b/TelegramCore/ProxySettings.swift @@ -169,9 +169,9 @@ extension ProxyServerSettings { var mtProxySettings: MTSocksProxySettings { switch self.connection { case let .socks5(username, password): - return MTSocksProxySettings(ip: self.host, port: UInt16(self.port), username: username, password: password, secret: nil) + return MTSocksProxySettings(ip: self.host, port: UInt16(clamping: self.port), username: username, password: password, secret: nil) case let .mtp(secret): - return MTSocksProxySettings(ip: self.host, port: UInt16(self.port), username: nil, password: nil, secret: secret) + return MTSocksProxySettings(ip: self.host, port: UInt16(clamping: self.port), username: nil, password: nil, secret: secret) } } } diff --git a/TelegramCore/TelegramMediaFile.swift b/TelegramCore/TelegramMediaFile.swift index 29c850fcbd..8cdf53471a 100644 --- a/TelegramCore/TelegramMediaFile.swift +++ b/TelegramCore/TelegramMediaFile.swift @@ -269,7 +269,7 @@ public final class TelegramMediaFile: Media, Equatable { public init(decoder: PostboxDecoder) { self.fileId = MediaId(decoder.decodeBytesForKeyNoCopy("i")!) self.partialReference = decoder.decodeAnyObjectForKey("prf", decoder: { PartialMediaReference(decoder: $0) }) as? PartialMediaReference - self.resource = decoder.decodeObjectForKey("r") as! TelegramMediaResource + self.resource = decoder.decodeObjectForKey("r") as? TelegramMediaResource ?? EmptyMediaResource() self.previewRepresentations = decoder.decodeObjectArrayForKey("pr") self.mimeType = decoder.decodeStringForKey("mt", orElse: "") if let size = decoder.decodeOptionalInt32ForKey("s") { diff --git a/TelegramCore/TelegramMediaImage.swift b/TelegramCore/TelegramMediaImage.swift index 80eea838d4..a1e468e2d0 100644 --- a/TelegramCore/TelegramMediaImage.swift +++ b/TelegramCore/TelegramMediaImage.swift @@ -171,7 +171,7 @@ public final class TelegramMediaImageRepresentation: PostboxCoding, Equatable, C public init(decoder: PostboxDecoder) { self.dimensions = CGSize(width: CGFloat(decoder.decodeInt32ForKey("dx", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("dy", orElse: 0))) - self.resource = decoder.decodeObjectForKey("r") as! TelegramMediaResource + self.resource = decoder.decodeObjectForKey("r") as? TelegramMediaResource ?? EmptyMediaResource() } public func encode(_ encoder: PostboxEncoder) {