From 657567195261427c43f77d40bc9808b2cc47f157 Mon Sep 17 00:00:00 2001 From: overtake Date: Wed, 15 Mar 2017 00:43:20 +0300 Subject: [PATCH] some changes --- TelegramCore/AccountState.swift | 1 - TelegramCore/Authorization.swift | 27 ++++++++++++++++++------ TelegramCore/EnqueueMessage.swift | 2 +- TelegramCore/PendingMessageManager.swift | 10 ++++++++- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/TelegramCore/AccountState.swift b/TelegramCore/AccountState.swift index 9f532d4443..10fb03209a 100644 --- a/TelegramCore/AccountState.swift +++ b/TelegramCore/AccountState.swift @@ -99,7 +99,6 @@ public enum UnauthorizedAccountStateContents: Coding, Equatable { case phoneEntry(countryCode: Int32, number: String) case confirmationCodeEntry(number: String, type: SentAuthorizationCodeType, hash: String, timeout: Int32?, nextType: AuthorizationCodeNextType?) case passwordEntry(hint: String) - public init(decoder: Decoder) { switch decoder.decodeInt32ForKey("v") as Int32 { case UnauthorizedAccountStateContentsValue.empty.rawValue: diff --git a/TelegramCore/Authorization.swift b/TelegramCore/Authorization.swift index 5add250b90..7130100337 100644 --- a/TelegramCore/Authorization.swift +++ b/TelegramCore/Authorization.swift @@ -12,6 +12,7 @@ import Foundation public enum AuthorizationCodeRequestError { case invalidPhoneNumber case limitExceeded + case unregistred case generic } @@ -50,14 +51,25 @@ public func sendAuthorizationCode(account: UnauthorizedAccount, phoneNumber: Str return codeAndAccount |> mapToSignal { (sentCode, account) -> Signal in + + switch sentCode { + case let .sentCode(flags, type, phoneCodeHash, nextType, timeout): + if (flags & (1 << 0)) == 0 { + return .fail(.unregistred) + } + } + return account.postbox.modify { modifier -> UnauthorizedAccount in switch sentCode { - case let .sentCode(_, type, phoneCodeHash, nextType, timeout): + case let .sentCode(flags, type, phoneCodeHash, nextType, timeout): var parsedNextType: AuthorizationCodeNextType? if let nextType = nextType { parsedNextType = AuthorizationCodeNextType(apiType: nextType) } + modifier.setState(UnauthorizedAccountState(masterDatacenterId: account.masterDatacenterId, contents: .confirmationCodeEntry(number: phoneNumber, type: SentAuthorizationCodeType(apiType: type), hash: phoneCodeHash, timeout: timeout, nextType: parsedNextType))) + + } return account } |> mapError { _ -> AuthorizationCodeRequestError in return .generic } @@ -84,11 +96,14 @@ public func resendAuthorizationCode(account: UnauthorizedAccount) -> Signal Void in switch sentCode { case let .sentCode(_, type, phoneCodeHash, nextType, timeout): - var parsedNextType: AuthorizationCodeNextType? - if let nextType = nextType { - parsedNextType = AuthorizationCodeNextType(apiType: nextType) - } - modifier.setState(UnauthorizedAccountState(masterDatacenterId: account.masterDatacenterId, contents: .confirmationCodeEntry(number: number, type: SentAuthorizationCodeType(apiType: type), hash: phoneCodeHash, timeout: timeout, nextType: parsedNextType))) + + var parsedNextType: AuthorizationCodeNextType? + if let nextType = nextType { + parsedNextType = AuthorizationCodeNextType(apiType: nextType) + } + + modifier.setState(UnauthorizedAccountState(masterDatacenterId: account.masterDatacenterId, contents: .confirmationCodeEntry(number: number, type: SentAuthorizationCodeType(apiType: type), hash: phoneCodeHash, timeout: timeout, nextType: parsedNextType))) + } } |> mapError { _ -> AuthorizationCodeRequestError in return .generic } } diff --git a/TelegramCore/EnqueueMessage.swift b/TelegramCore/EnqueueMessage.swift index 0ee421d686..d1aac2cacb 100644 --- a/TelegramCore/EnqueueMessage.swift +++ b/TelegramCore/EnqueueMessage.swift @@ -191,7 +191,7 @@ func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messa let authorId:PeerId? if let peer = peer as? TelegramChannel, case let .broadcast(info) = peer.info, !info.flags.contains(.messagesShouldHaveSignatures) { - authorId = nil + authorId = peer.id } else { authorId = account.peerId } diff --git a/TelegramCore/PendingMessageManager.swift b/TelegramCore/PendingMessageManager.swift index 5980d169e7..646640ef7f 100644 --- a/TelegramCore/PendingMessageManager.swift +++ b/TelegramCore/PendingMessageManager.swift @@ -390,7 +390,15 @@ public final class PendingMessageManager { return modify } } else { - return .complete() + return postbox.modify { modifier -> Void in + modifier.updateMessage(message.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) + } + return StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) + }) + } } } |> switchToLatest }