App changelog support

Fixed message sent events in secret chats
Fixed crash when processing invalid proxy settings
This commit is contained in:
Peter 2018-10-03 01:36:40 +04:00
parent bcc7d11fdb
commit 7929819c87
13 changed files with 175 additions and 102 deletions

View File

@ -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 = "<group>"; };
D050F20F1E48AB0600988324 /* InteractivePhoneFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InteractivePhoneFormatter.swift; sourceTree = "<group>"; };
D050F2501E4A59C200988324 /* JoinLink.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JoinLink.swift; sourceTree = "<group>"; };
D051DB13215EC5A300F30F92 /* AppChangelogState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppChangelogState.swift; sourceTree = "<group>"; };
D051DB16215ECC4D00F30F92 /* AppChangelog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppChangelog.swift; sourceTree = "<group>"; };
D0528E591E658B3600E2FEF5 /* ManagedLocalInputActivities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedLocalInputActivities.swift; sourceTree = "<group>"; };
D0528E5F1E65B94E00E2FEF5 /* SingleMessageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleMessageView.swift; sourceTree = "<group>"; };
D0528E641E65C82400E2FEF5 /* UpdateContactName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateContactName.swift; sourceTree = "<group>"; };
@ -1206,6 +1212,7 @@
D0AF32301FACEDEC0097362B /* CoreSettings.swift */,
D0FA08BA2046B37900DD23FC /* ContentPrivacySettings.swift */,
D026099D20C695AF006C34AC /* Wallpapers.swift */,
D051DB13215EC5A300F30F92 /* AppChangelogState.swift */,
);
name = Settings;
sourceTree = "<group>";
@ -1533,6 +1540,7 @@
D099D7481EEF418D00A3128C /* HistoryViewChannelStateValidation.swift */,
D0B1671C1F9EA2C300976B40 /* ChatHistoryPreloadManager.swift */,
D06ECFC720B810D300C576C2 /* TermsOfService.swift */,
D051DB16215ECC4D00F30F92 /* AppChangelog.swift */,
);
name = Account;
sourceTree = "<group>";
@ -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 */,

View File

@ -1,80 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D0B418661D7E03D5004562A4"
BuildableName = "TelegramCoreMac.framework"
BlueprintName = "TelegramCoreMac"
ReferencedContainer = "container:TelegramCore.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D0B418661D7E03D5004562A4"
BuildableName = "TelegramCoreMac.framework"
BlueprintName = "TelegramCoreMac"
ReferencedContainer = "container:TelegramCore.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D0B418661D7E03D5004562A4"
BuildableName = "TelegramCoreMac.framework"
BlueprintName = "TelegramCoreMac"
ReferencedContainer = "container:TelegramCore.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -9,11 +9,6 @@
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>TelegramCoreMac.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>

View File

@ -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<Void, NoError> in
return network.request(Api.functions.account.registerDevice(tokenType: 1, token: tokenString, appSandbox: appSandbox, secret: Buffer(data: secret.data), otherUids: []))
|> retryRequest
|> mapToSignal { _ -> Signal<Void, NoError> in
return .complete()
}
|> mapToSignal { secret -> Signal<Void, NoError> in
return network.request(Api.functions.account.registerDevice(tokenType: 1, token: tokenString, appSandbox: appSandbox, secret: Buffer(data: secret.data), otherUids: []))
|> retryRequest
|> mapToSignal { _ -> Signal<Void, NoError> 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<Void, NoError> in
return network.request(Api.functions.account.registerDevice(tokenType: 9, token: tokenString, appSandbox: appSandbox, secret: Buffer(data: secret.data), otherUids: []))
|> mapToSignal { secret -> Signal<Void, NoError> in
return network.request(Api.functions.account.registerDevice(tokenType: 9, token: tokenString, appSandbox: appSandbox, secret: Buffer(data: secret.data), otherUids: []))
|> retryRequest
|> mapToSignal { _ -> Signal<Void, NoError> 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())

View File

@ -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<Void, NoError> {
return stateManager.pollStateUpdateCompletion()
|> take(1)
|> mapToSignal { _ -> Signal<Void, NoError> in
return postbox.transaction { transaction -> AppChangelogState in
return transaction.getPreferencesEntry(key: PreferencesKeys.appChangelogState) as? AppChangelogState ?? AppChangelogState.default
}
|> mapToSignal { appChangelogState -> Signal<Void, NoError> 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<Api.Updates?, NoError> in
return .single(nil)
}
|> mapToSignal { updates -> Signal<Void, NoError> 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
})
}
}
}
}
}

View File

@ -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)
})
}

View File

@ -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)

View File

@ -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
}()
}

View File

@ -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
}
}

View File

@ -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<PeerId>()
var updateUploadingGroupIds = Set<Int64>()
@ -194,6 +195,32 @@ public final class PendingMessageManager {
self.beginSendingGroupIfPossible(groupId: groupId)
}
if !removedSecretMessageIds.isEmpty {
let _ = (self.postbox.transaction { transaction -> Set<PeerId> in
var peerIdsWithDeliveredMessages = Set<PeerId>()
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<Void, NoError> {
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] {

View File

@ -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)
}
}
}

View File

@ -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") {

View File

@ -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) {