some changes

This commit is contained in:
overtake
2017-03-15 00:43:20 +03:00
parent 652832e32b
commit 6575671952
4 changed files with 31 additions and 9 deletions

View File

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

View File

@@ -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<UnauthorizedAccount, AuthorizationCodeRequestError> 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
return account.postbox.modify { modifier -> 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)))
}
} |> mapError { _ -> AuthorizationCodeRequestError in return .generic }
}

View File

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

View File

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