diff --git a/TelegramCore.xcodeproj/project.pbxproj b/TelegramCore.xcodeproj/project.pbxproj index 39749dcb19..2186714f95 100644 --- a/TelegramCore.xcodeproj/project.pbxproj +++ b/TelegramCore.xcodeproj/project.pbxproj @@ -2931,6 +2931,7 @@ CLANG_WARN_SUSPICIOUS_MOVES = YES; CODE_SIGN_IDENTITY = "-"; COMBINE_HIDPI_IMAGES = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; @@ -2950,7 +2951,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 4.0; }; name = "Debug Hockeyapp"; diff --git a/TelegramCore/Authorization.swift b/TelegramCore/Authorization.swift index 86e9acd33a..9e0f3bd9bd 100644 --- a/TelegramCore/Authorization.swift +++ b/TelegramCore/Authorization.swift @@ -27,7 +27,7 @@ public func sendAuthorizationCode(account: UnauthorizedAccount, phoneNumber: Str switch error.errorDescription { case Regex("(PHONE_|USER_|NETWORK_)MIGRATE_(\\d+)"): let range = error.errorDescription.range(of: "MIGRATE_")! - let updatedMasterDatacenterId = Int32(error.errorDescription.substring(from: range.upperBound))! + let updatedMasterDatacenterId = Int32(error.errorDescription[range.upperBound ..< error.errorDescription.endIndex])! let updatedAccount = account.changedMasterDatacenterId(updatedMasterDatacenterId) return updatedAccount |> mapToSignalPromotingError { updatedAccount -> Signal<(Api.auth.SentCode, UnauthorizedAccount), MTRpcError> in diff --git a/TelegramCore/Download.swift b/TelegramCore/Download.swift index 220db0f5e7..d6ab254831 100644 --- a/TelegramCore/Download.swift +++ b/TelegramCore/Download.swift @@ -22,6 +22,12 @@ private func roundUp(_ value: Int, to multiple: Int) -> Int { return value + multiple - remainder } +enum UploadPartError { + case generic + case invalidMedia +} + + class Download: NSObject, MTRequestMessageServiceDelegate { let datacenterId: Int let isCdn: Bool @@ -75,7 +81,7 @@ class Download: NSObject, MTRequestMessageServiceDelegate { self.context.authTokenForDatacenter(withIdRequired: self.datacenterId, authToken:self.mtProto.requiredAuthToken, masterDatacenterId: self.mtProto.authTokenMasterDatacenterId) } - func uploadPart(fileId: Int64, index: Int, data: Data, bigTotalParts: Int? = nil) -> Signal { + func uploadPart(fileId: Int64, index: Int, data: Data, bigTotalParts: Int? = nil) -> Signal { return Signal { subscriber in let request = MTRequest() @@ -110,7 +116,13 @@ class Download: NSObject, MTRequestMessageServiceDelegate { return ActionDisposable { self.requestService.removeRequest(byInternalId: internalId) } - } |> retryRequest + } |> `catch` { value -> Signal in + if value.errorCode == 400 { + return .fail(.invalidMedia) + } else { + return .fail(.generic) + } + } } func webFilePart(location: Api.InputWebFileLocation, offset: Int, length: Int) -> Signal { @@ -160,7 +172,7 @@ class Download: NSObject, MTRequestMessageServiceDelegate { } |> retryRequest } - func part(location: Api.InputFileLocation, offset: Int, length: Int) -> Signal { + func part(location: Api.InputFileLocation, offset: Int, length: Int) -> Signal { return Signal { subscriber in let request = MTRequest() diff --git a/TelegramCore/EnqueueMessage.swift b/TelegramCore/EnqueueMessage.swift index f433039c31..bd5b793b6c 100644 --- a/TelegramCore/EnqueueMessage.swift +++ b/TelegramCore/EnqueueMessage.swift @@ -173,7 +173,7 @@ public func resendMessages(account: Account, messageIds: [MessageId]) -> Signal< } func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messages: [(Bool, EnqueueMessage)]) -> [MessageId?] { - if let peer = modifier.getPeer(peerId) { + if let peer = modifier.getPeer(peerId), let accountPeer = modifier.getPeer(account.peerId) { var storeMessages: [StoreMessage] = [] var timestamp = Int32(account.network.context.globalTime()) switch peerId.namespace { @@ -231,6 +231,17 @@ func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messa attributes.append(ConsumableContentMessageAttribute(consumed: false)) } } + if let peer = peer as? TelegramChannel { + switch peer.info { + case let .broadcast(info): + attributes.append(ViewCountMessageAttribute(count: 1)) + if info.flags.contains(.messagesShouldHaveSignatures) { + attributes.append(AuthorSignatureMessageAttribute(signature: accountPeer.displayTitle)) + } + case .group: + break + } + } var entitiesAttribute: TextEntitiesMessageAttribute? for attribute in attributes { diff --git a/TelegramCore/MultipartUpload.swift b/TelegramCore/MultipartUpload.swift index d03d978cd5..3ba0003aee 100644 --- a/TelegramCore/MultipartUpload.swift +++ b/TelegramCore/MultipartUpload.swift @@ -145,7 +145,7 @@ private final class MultipartUploadManager { let dataSignal: Signal var committedOffset: Int - let uploadPart: (UploadPart) -> Signal + let uploadPart: (UploadPart) -> Signal let progress: (Float) -> Void let completed: (MultipartIntermediateResult?) -> Void @@ -159,7 +159,7 @@ private final class MultipartUploadManager { let state: MultipartUploadState - init(headerSize: Int32, data: Signal, encryptionKey: SecretFileEncryptionKey?, hintFileSize: Int?, uploadPart: @escaping (UploadPart) -> Signal, progress: @escaping (Float) -> Void, completed: @escaping (MultipartIntermediateResult?) -> Void) { + init(headerSize: Int32, data: Signal, encryptionKey: SecretFileEncryptionKey?, hintFileSize: Int?, uploadPart: @escaping (UploadPart) -> Signal, progress: @escaping (Float) -> Void, completed: @escaping (MultipartIntermediateResult?) -> Void) { self.dataSignal = data var fileId: Int64 = 0 @@ -256,7 +256,9 @@ private final class MultipartUploadManager { } let part = self.uploadPart(UploadPart(fileId: self.fileId, index: partIndex, data: partData, bigTotalParts: currentBigTotalParts)) |> deliverOn(self.queue) - self.uploadingParts[0] = (partSize, part.start(completed: { [weak self] in + self.uploadingParts[0] = (partSize, part.start(error: { [weak self] error in + self?.completed(nil) + }, completed: { [weak self] in if let strongSelf = self { let _ = strongSelf.uploadingParts.removeValue(forKey: 0) strongSelf.headerPartReady = true @@ -295,7 +297,9 @@ private final class MultipartUploadManager { } let part = self.uploadPart(UploadPart(fileId: self.fileId, index: partIndex, data: partData, bigTotalParts: currentBigTotalParts)) |> deliverOn(self.queue) - self.uploadingParts[nextOffset] = (partSize, part.start(completed: { [weak self] in + self.uploadingParts[nextOffset] = (partSize, part.start(error: { [weak self] error in + self?.completed(nil) + }, completed: { [weak self] in if let strongSelf = self { let _ = strongSelf.uploadingParts.removeValue(forKey: nextOffset) strongSelf.uploadedParts[partOffset] = partSize diff --git a/TelegramCore/PendingMessageManager.swift b/TelegramCore/PendingMessageManager.swift index f3150bf8bf..e5fa6524fd 100644 --- a/TelegramCore/PendingMessageManager.swift +++ b/TelegramCore/PendingMessageManager.swift @@ -381,7 +381,23 @@ public final class PendingMessageManager { subscriber(status) } - messageContext.disposable.set((uploadSignal |> deliverOn(self.queue)).start(next: { [weak self] next in + + + messageContext.disposable.set((uploadSignal |> deliverOn(self.queue) |> `catch` { [weak self] _ -> Signal in + if let strongSelf = self { + let modify = strongSelf.postbox.modify { modifier -> Void in + modifier.updateMessage(id, update: { currentMessage in + var storeForwardInfo: StoreMessageForwardInfo? + if let forwardInfo = currentMessage.forwardInfo { + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) + } + return .update(StoreMessage(id: id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) + }) + } + return modify |> mapToSignal { _ in return .complete() } + } + return .fail(Void()) + }).start(next: { [weak self] next in if let strongSelf = self { assert(strongSelf.queue.isCurrent()) diff --git a/TelegramCore/RecentAccountSessions.swift b/TelegramCore/RecentAccountSessions.swift index 296bae143b..2ee8e6b3f9 100644 --- a/TelegramCore/RecentAccountSessions.swift +++ b/TelegramCore/RecentAccountSessions.swift @@ -22,11 +22,19 @@ public func requestRecentAccountSessions(account: Account) -> Signal<[RecentAcco } } -public func terminateAccountSession(account: Account, hash: Int64) -> Signal { +public enum TerminateSessionError { + case generic + case freshReset +} + +public func terminateAccountSession(account: Account, hash: Int64) -> Signal { return account.network.request(Api.functions.account.resetAuthorization(hash: hash)) - |> retryRequest - |> mapToSignal { _ -> Signal in - return .complete() + |> map {_ in} + |> mapError { error -> TerminateSessionError in + if error.errorCode == 406 { + return .freshReset + } + return .generic } } diff --git a/TelegramCore/SearchPeers.swift b/TelegramCore/SearchPeers.swift index 0e8f8f77c2..64a9755cc7 100644 --- a/TelegramCore/SearchPeers.swift +++ b/TelegramCore/SearchPeers.swift @@ -24,7 +24,7 @@ public struct FoundPeer: Equatable { } public func searchPeers(account: Account, query: String) -> Signal<([FoundPeer], [FoundPeer]), NoError> { - let searchResult = account.network.request(Api.functions.contacts.search(q: query, limit: 20)) + let searchResult = account.network.request(Api.functions.contacts.search(q: query, limit: 20), automaticFloodWait: false) |> map { Optional($0) } |> `catch` { _ in return Signal.single(nil)