no message

This commit is contained in:
Mikhail Filimonov 2018-02-07 13:39:41 +04:00
parent 82783ba8ba
commit cf4f84a1b7
8 changed files with 68 additions and 16 deletions

View File

@ -2931,6 +2931,7 @@
CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES;
CODE_SIGN_IDENTITY = "-"; CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_COMPATIBILITY_VERSION = 1;
@ -2950,7 +2951,7 @@
SDKROOT = macosx; SDKROOT = macosx;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0; SWIFT_VERSION = 4.0;
}; };
name = "Debug Hockeyapp"; name = "Debug Hockeyapp";

View File

@ -27,7 +27,7 @@ public func sendAuthorizationCode(account: UnauthorizedAccount, phoneNumber: Str
switch error.errorDescription { switch error.errorDescription {
case Regex("(PHONE_|USER_|NETWORK_)MIGRATE_(\\d+)"): case Regex("(PHONE_|USER_|NETWORK_)MIGRATE_(\\d+)"):
let range = error.errorDescription.range(of: "MIGRATE_")! 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) let updatedAccount = account.changedMasterDatacenterId(updatedMasterDatacenterId)
return updatedAccount return updatedAccount
|> mapToSignalPromotingError { updatedAccount -> Signal<(Api.auth.SentCode, UnauthorizedAccount), MTRpcError> in |> mapToSignalPromotingError { updatedAccount -> Signal<(Api.auth.SentCode, UnauthorizedAccount), MTRpcError> in

View File

@ -22,6 +22,12 @@ private func roundUp(_ value: Int, to multiple: Int) -> Int {
return value + multiple - remainder return value + multiple - remainder
} }
enum UploadPartError {
case generic
case invalidMedia
}
class Download: NSObject, MTRequestMessageServiceDelegate { class Download: NSObject, MTRequestMessageServiceDelegate {
let datacenterId: Int let datacenterId: Int
let isCdn: Bool 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) 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<Void, NoError> { func uploadPart(fileId: Int64, index: Int, data: Data, bigTotalParts: Int? = nil) -> Signal<Void, UploadPartError> {
return Signal<Void, MTRpcError> { subscriber in return Signal<Void, MTRpcError> { subscriber in
let request = MTRequest() let request = MTRequest()
@ -110,7 +116,13 @@ class Download: NSObject, MTRequestMessageServiceDelegate {
return ActionDisposable { return ActionDisposable {
self.requestService.removeRequest(byInternalId: internalId) self.requestService.removeRequest(byInternalId: internalId)
} }
} |> retryRequest } |> `catch` { value -> Signal<Void, UploadPartError> in
if value.errorCode == 400 {
return .fail(.invalidMedia)
} else {
return .fail(.generic)
}
}
} }
func webFilePart(location: Api.InputWebFileLocation, offset: Int, length: Int) -> Signal<Data, NoError> { func webFilePart(location: Api.InputWebFileLocation, offset: Int, length: Int) -> Signal<Data, NoError> {
@ -160,7 +172,7 @@ class Download: NSObject, MTRequestMessageServiceDelegate {
} |> retryRequest } |> retryRequest
} }
func part(location: Api.InputFileLocation, offset: Int, length: Int) -> Signal<Data, NoError> { func part(location: Api.InputFileLocation, offset: Int, length: Int) -> Signal<Data, Void> {
return Signal<Data, MTRpcError> { subscriber in return Signal<Data, MTRpcError> { subscriber in
let request = MTRequest() let request = MTRequest()

View File

@ -173,7 +173,7 @@ public func resendMessages(account: Account, messageIds: [MessageId]) -> Signal<
} }
func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messages: [(Bool, EnqueueMessage)]) -> [MessageId?] { 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 storeMessages: [StoreMessage] = []
var timestamp = Int32(account.network.context.globalTime()) var timestamp = Int32(account.network.context.globalTime())
switch peerId.namespace { switch peerId.namespace {
@ -231,6 +231,17 @@ func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messa
attributes.append(ConsumableContentMessageAttribute(consumed: false)) 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? var entitiesAttribute: TextEntitiesMessageAttribute?
for attribute in attributes { for attribute in attributes {

View File

@ -145,7 +145,7 @@ private final class MultipartUploadManager {
let dataSignal: Signal<MultipartUploadData, NoError> let dataSignal: Signal<MultipartUploadData, NoError>
var committedOffset: Int var committedOffset: Int
let uploadPart: (UploadPart) -> Signal<Void, NoError> let uploadPart: (UploadPart) -> Signal<Void, UploadPartError>
let progress: (Float) -> Void let progress: (Float) -> Void
let completed: (MultipartIntermediateResult?) -> Void let completed: (MultipartIntermediateResult?) -> Void
@ -159,7 +159,7 @@ private final class MultipartUploadManager {
let state: MultipartUploadState let state: MultipartUploadState
init(headerSize: Int32, data: Signal<MultipartUploadData, NoError>, encryptionKey: SecretFileEncryptionKey?, hintFileSize: Int?, uploadPart: @escaping (UploadPart) -> Signal<Void, NoError>, progress: @escaping (Float) -> Void, completed: @escaping (MultipartIntermediateResult?) -> Void) { init(headerSize: Int32, data: Signal<MultipartUploadData, NoError>, encryptionKey: SecretFileEncryptionKey?, hintFileSize: Int?, uploadPart: @escaping (UploadPart) -> Signal<Void, UploadPartError>, progress: @escaping (Float) -> Void, completed: @escaping (MultipartIntermediateResult?) -> Void) {
self.dataSignal = data self.dataSignal = data
var fileId: Int64 = 0 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)) let part = self.uploadPart(UploadPart(fileId: self.fileId, index: partIndex, data: partData, bigTotalParts: currentBigTotalParts))
|> deliverOn(self.queue) |> 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 { if let strongSelf = self {
let _ = strongSelf.uploadingParts.removeValue(forKey: 0) let _ = strongSelf.uploadingParts.removeValue(forKey: 0)
strongSelf.headerPartReady = true 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)) let part = self.uploadPart(UploadPart(fileId: self.fileId, index: partIndex, data: partData, bigTotalParts: currentBigTotalParts))
|> deliverOn(self.queue) |> 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 { if let strongSelf = self {
let _ = strongSelf.uploadingParts.removeValue(forKey: nextOffset) let _ = strongSelf.uploadingParts.removeValue(forKey: nextOffset)
strongSelf.uploadedParts[partOffset] = partSize strongSelf.uploadedParts[partOffset] = partSize

View File

@ -381,7 +381,23 @@ public final class PendingMessageManager {
subscriber(status) 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<PendingMessageUploadedContentResult, NoError> 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 { if let strongSelf = self {
assert(strongSelf.queue.isCurrent()) assert(strongSelf.queue.isCurrent())

View File

@ -22,11 +22,19 @@ public func requestRecentAccountSessions(account: Account) -> Signal<[RecentAcco
} }
} }
public func terminateAccountSession(account: Account, hash: Int64) -> Signal<Void, NoError> { public enum TerminateSessionError {
case generic
case freshReset
}
public func terminateAccountSession(account: Account, hash: Int64) -> Signal<Void, TerminateSessionError> {
return account.network.request(Api.functions.account.resetAuthorization(hash: hash)) return account.network.request(Api.functions.account.resetAuthorization(hash: hash))
|> retryRequest |> map {_ in}
|> mapToSignal { _ -> Signal<Void, NoError> in |> mapError { error -> TerminateSessionError in
return .complete() if error.errorCode == 406 {
return .freshReset
}
return .generic
} }
} }

View File

@ -24,7 +24,7 @@ public struct FoundPeer: Equatable {
} }
public func searchPeers(account: Account, query: String) -> Signal<([FoundPeer], [FoundPeer]), NoError> { 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) } |> map { Optional($0) }
|> `catch` { _ in |> `catch` { _ in
return Signal<Api.contacts.Found?, NoError>.single(nil) return Signal<Api.contacts.Found?, NoError>.single(nil)