Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Ilya Laktyushin 2019-11-17 22:26:52 +04:00
commit 0f081f9ac3
11 changed files with 955 additions and 897 deletions

1
BUCK
View File

@ -466,6 +466,7 @@ apple_binary(
linker_flags = [ linker_flags = [
"-e", "-e",
"_WKExtensionMain", "_WKExtensionMain",
"-lWKExtensionMainLegacy",
], ],
configs = watch_extension_binary_configs(), configs = watch_extension_binary_configs(),
frameworks = [ frameworks = [

View File

@ -4814,7 +4814,7 @@ Any member of this group will be able to see messages in the channel.";
"Wallet.Receive.CopyInvoiceUrl" = "Copy Invoice URL"; "Wallet.Receive.CopyInvoiceUrl" = "Copy Invoice URL";
"Wallet.Receive.ShareAddress" = "Share Wallet Address"; "Wallet.Receive.ShareAddress" = "Share Wallet Address";
"Wallet.Receive.ShareInvoiceUrl" = "Share Invoice URL"; "Wallet.Receive.ShareInvoiceUrl" = "Share Invoice URL";
"Wallet.Receive.ShareUrlInfo" = "Share this link with other Gram wallet owners to receive Grams from them."; "Wallet.Receive.ShareUrlInfo" = "Share this link with other Gram wallet owners to receive Grams from them. Note: this link won't work for real Grams.";
"Wallet.Receive.AmountHeader" = "AMOUNT"; "Wallet.Receive.AmountHeader" = "AMOUNT";
"Wallet.Receive.AmountText" = "Grams to receive"; "Wallet.Receive.AmountText" = "Grams to receive";
"Wallet.Receive.AmountInfo" = "You can specify the amount and purpose of the payment to save the sender some time."; "Wallet.Receive.AmountInfo" = "You can specify the amount and purpose of the payment to save the sender some time.";

View File

@ -26,7 +26,7 @@ brew install cmake ant
``` ```
mkdir -p $HOME/buck_source mkdir -p $HOME/buck_source
cd tools/buck cd tools/buck-build
sh ./prepare_buck_source.sh $HOME/buck_source sh ./prepare_buck_source.sh $HOME/buck_source
``` ```

View File

@ -651,7 +651,7 @@ final class AppDelegate: NSObject, UIApplicationDelegate {
print("Starting with \(documentsPath)") print("Starting with \(documentsPath)")
#endif #endif
let storage = WalletStorageInterfaceImpl(path: documentsPath + "/data", configurationPath: documentsPath + "/configuration") let storage = WalletStorageInterfaceImpl(path: documentsPath + "/data", configurationPath: documentsPath + "/configuration_v2")
let initialConfigValue = storage.mergedLocalWalletConfiguration() let initialConfigValue = storage.mergedLocalWalletConfiguration()
|> take(1) |> take(1)
@ -828,6 +828,6 @@ struct MergedLocalWalletConfiguration: Codable, Equatable {
private extension MergedLocalWalletConfiguration { private extension MergedLocalWalletConfiguration {
static var `default`: MergedLocalWalletConfiguration { static var `default`: MergedLocalWalletConfiguration {
return MergedLocalWalletConfiguration(configuration: LocalWalletConfiguration(source: .url("https://test.ton.org/config.json"), blockchainName: "testnet"), resolved: nil) return MergedLocalWalletConfiguration(configuration: LocalWalletConfiguration(source: .url("https://test.ton.org/config.json"), blockchainName: "testnet2"), resolved: nil)
} }
} }

View File

@ -39,7 +39,7 @@
"Wallet.Receive.CopyInvoiceUrl" = "Copy Invoice URL"; "Wallet.Receive.CopyInvoiceUrl" = "Copy Invoice URL";
"Wallet.Receive.ShareAddress" = "Share Wallet Address"; "Wallet.Receive.ShareAddress" = "Share Wallet Address";
"Wallet.Receive.ShareInvoiceUrl" = "Share Invoice URL"; "Wallet.Receive.ShareInvoiceUrl" = "Share Invoice URL";
"Wallet.Receive.ShareUrlInfo" = "Share this link with other Gram wallet owners to receive Grams from them."; "Wallet.Receive.ShareUrlInfo" = "Share this link with other Gram wallet owners to receive Grams from them. Note: this link won't work for real Grams.";
"Wallet.Receive.AmountHeader" = "AMOUNT"; "Wallet.Receive.AmountHeader" = "AMOUNT";
"Wallet.Receive.AmountText" = "Grams to receive"; "Wallet.Receive.AmountText" = "Grams to receive";
"Wallet.Receive.AmountInfo" = "You can specify the amount and purpose of the payment to save the sender some time."; "Wallet.Receive.AmountInfo" = "You can specify the amount and purpose of the payment to save the sender some time.";

View File

@ -772,9 +772,22 @@ public final class AccountViewTracker {
self.cachedDataContexts[peerId] = context self.cachedDataContexts[peerId] = context
} }
context.timestamp = CFAbsoluteTimeGetCurrent() context.timestamp = CFAbsoluteTimeGetCurrent()
if let account = self.account { guard let account = self.account else {
context.disposable.set(combineLatest(fetchAndUpdateSupplementalCachedPeerData(peerId: peerId, network: account.network, postbox: account.postbox), fetchAndUpdateCachedPeerData(accountPeerId: account.peerId, peerId: peerId, network: account.network, postbox: account.postbox)).start()) return
} }
let queue = self.queue
context.disposable.set(combineLatest(fetchAndUpdateSupplementalCachedPeerData(peerId: peerId, network: account.network, postbox: account.postbox), fetchAndUpdateCachedPeerData(accountPeerId: account.peerId, peerId: peerId, network: account.network, postbox: account.postbox)).start(next: { [weak self] supplementalStatus, cachedStatus in
queue.async {
guard let strongSelf = self else {
return
}
if !supplementalStatus || !cachedStatus {
if let existingContext = strongSelf.cachedDataContexts[peerId] {
existingContext.timestamp = nil
}
}
}
}))
} }
} }
@ -801,9 +814,22 @@ public final class AccountViewTracker {
context.viewIds.insert(viewId) context.viewIds.insert(viewId)
if dataUpdated { if dataUpdated {
if let account = self.account { guard let account = self.account else {
context.disposable.set(combineLatest(fetchAndUpdateSupplementalCachedPeerData(peerId: peerId, network: account.network, postbox: account.postbox), fetchAndUpdateCachedPeerData(accountPeerId: account.peerId, peerId: peerId, network: account.network, postbox: account.postbox)).start()) return
} }
let queue = self.queue
context.disposable.set(combineLatest(fetchAndUpdateSupplementalCachedPeerData(peerId: peerId, network: account.network, postbox: account.postbox), fetchAndUpdateCachedPeerData(accountPeerId: account.peerId, peerId: peerId, network: account.network, postbox: account.postbox)).start(next: { [weak self] supplementalStatus, cachedStatus in
queue.async {
guard let strongSelf = self else {
return
}
if !supplementalStatus || !cachedStatus {
if let existingContext = strongSelf.cachedDataContexts[peerId] {
existingContext.timestamp = nil
}
}
}
}))
} }
} }
} }

View File

@ -2,19 +2,30 @@ import Foundation
import Postbox import Postbox
import TelegramApi import TelegramApi
import SwiftSignalKit import SwiftSignalKit
import SyncCore import SyncCore
func fetchAndUpdateSupplementalCachedPeerData(peerId rawPeerId: PeerId, network: Network, postbox: Postbox) -> Signal<Void, NoError> { func fetchAndUpdateSupplementalCachedPeerData(peerId rawPeerId: PeerId, network: Network, postbox: Postbox) -> Signal<Bool, NoError> {
return postbox.transaction { transaction -> Signal<Void, NoError> in return postbox.combinedView(keys: [.basicPeer(rawPeerId)])
guard let rawPeer = transaction.getPeer(rawPeerId) else { |> mapToSignal { views -> Signal<Peer, NoError> in
guard let view = views.views[.basicPeer(rawPeerId)] as? BasicPeerView else {
return .complete() return .complete()
} }
guard let peer = view.peer else {
return .complete()
}
return .single(peer)
}
|> take(1)
|> mapToSignal { _ -> Signal<Bool, NoError> in
return postbox.transaction { transaction -> Signal<Bool, NoError> in
guard let rawPeer = transaction.getPeer(rawPeerId) else {
return .single(false)
}
let peer: Peer let peer: Peer
if let secretChat = rawPeer as? TelegramSecretChat { if let secretChat = rawPeer as? TelegramSecretChat {
guard let user = transaction.getPeer(secretChat.regularPeerId) else { guard let user = transaction.getPeer(secretChat.regularPeerId) else {
return .complete() return .single(false)
} }
peer = user peer = user
} else { } else {
@ -25,24 +36,24 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId rawPeerId: PeerId, network:
if let cachedData = cachedData as? CachedUserData { if let cachedData = cachedData as? CachedUserData {
if cachedData.peerStatusSettings != nil { if cachedData.peerStatusSettings != nil {
return .complete() return .single(true)
} }
} else if let cachedData = cachedData as? CachedGroupData { } else if let cachedData = cachedData as? CachedGroupData {
if cachedData.peerStatusSettings != nil { if cachedData.peerStatusSettings != nil {
return .complete() return .single(true)
} }
} else if let cachedData = cachedData as? CachedChannelData { } else if let cachedData = cachedData as? CachedChannelData {
if cachedData.peerStatusSettings != nil { if cachedData.peerStatusSettings != nil {
return .complete() return .single(true)
} }
} else if let cachedData = cachedData as? CachedSecretChatData { } else if let cachedData = cachedData as? CachedSecretChatData {
if cachedData.peerStatusSettings != nil { if cachedData.peerStatusSettings != nil {
return .complete() return .single(true)
} }
} }
if peer.id.namespace == Namespaces.Peer.SecretChat { if peer.id.namespace == Namespaces.Peer.SecretChat {
return postbox.transaction { transaction -> Void in return postbox.transaction { transaction -> Bool in
var peerStatusSettings: PeerStatusSettings var peerStatusSettings: PeerStatusSettings
if let peer = transaction.getPeer(peer.id), let associatedPeerId = peer.associatedPeerId, !transaction.isPeerContact(peerId: associatedPeerId) { if let peer = transaction.getPeer(peer.id), let associatedPeerId = peer.associatedPeerId, !transaction.isPeerContact(peerId: associatedPeerId) {
if let peer = peer as? TelegramSecretChat, case .creator = peer.role { if let peer = peer as? TelegramSecretChat, case .creator = peer.role {
@ -64,14 +75,16 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId rawPeerId: PeerId, network:
return CachedSecretChatData(peerStatusSettings: peerStatusSettings) return CachedSecretChatData(peerStatusSettings: peerStatusSettings)
} }
}) })
return true
} }
} else if let inputPeer = apiInputPeer(peer) { } else if let inputPeer = apiInputPeer(peer) {
return network.request(Api.functions.messages.getPeerSettings(peer: inputPeer)) return network.request(Api.functions.messages.getPeerSettings(peer: inputPeer))
|> retryRequest |> retryRequest
|> mapToSignal { peerSettings -> Signal<Void, NoError> in |> mapToSignal { peerSettings -> Signal<Bool, NoError> in
let peerStatusSettings = PeerStatusSettings(apiSettings: peerSettings) let peerStatusSettings = PeerStatusSettings(apiSettings: peerSettings)
return postbox.transaction { transaction -> Void in return postbox.transaction { transaction -> Bool in
transaction.updatePeerCachedData(peerIds: Set([peer.id]), update: { _, current in transaction.updatePeerCachedData(peerIds: Set([peer.id]), update: { _, current in
switch peer.id.namespace { switch peer.id.namespace {
case Namespaces.Peer.CloudUser: case Namespaces.Peer.CloudUser:
@ -103,16 +116,30 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId rawPeerId: PeerId, network:
} }
return current return current
}) })
return true
} }
} }
} else { } else {
return .complete() return .single(false)
} }
} }
|> switchToLatest |> switchToLatest
} }
}
func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPeerId: PeerId, network: Network, postbox: Postbox) -> Signal<Void, NoError> { func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPeerId: PeerId, network: Network, postbox: Postbox) -> Signal<Bool, NoError> {
return postbox.combinedView(keys: [.basicPeer(rawPeerId)])
|> mapToSignal { views -> Signal<Peer, NoError> in
guard let view = views.views[.basicPeer(rawPeerId)] as? BasicPeerView else {
return .complete()
}
guard let peer = view.peer else {
return .complete()
}
return .single(peer)
}
|> take(1)
|> mapToSignal { _ -> Signal<Bool, NoError> in
return postbox.transaction { transaction -> (Api.InputUser?, Peer?, PeerId) in return postbox.transaction { transaction -> (Api.InputUser?, Peer?, PeerId) in
guard let rawPeer = transaction.getPeer(rawPeerId) else { guard let rawPeer = transaction.getPeer(rawPeerId) else {
if rawPeerId == accountPeerId { if rawPeerId == accountPeerId {
@ -138,12 +165,12 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPeerId: PeerI
return (apiInputUser(peer), peer, peer.id) return (apiInputUser(peer), peer, peer.id)
} }
} }
|> mapToSignal { inputUser, maybePeer, peerId -> Signal<Void, NoError> in |> mapToSignal { inputUser, maybePeer, peerId -> Signal<Bool, NoError> in
if let inputUser = inputUser { if let inputUser = inputUser {
return network.request(Api.functions.users.getFullUser(id: inputUser)) return network.request(Api.functions.users.getFullUser(id: inputUser))
|> retryRequest |> retryRequest
|> mapToSignal { result -> Signal<Void, NoError> in |> mapToSignal { result -> Signal<Bool, NoError> in
return postbox.transaction { transaction -> Void in return postbox.transaction { transaction -> Bool in
switch result { switch result {
case let .userFull(userFull): case let .userFull(userFull):
let telegramUser = TelegramUser(user: userFull.user) let telegramUser = TelegramUser(user: userFull.user)
@ -181,13 +208,14 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPeerId: PeerI
return previous.withUpdatedAbout(userFull.about).withUpdatedBotInfo(botInfo).withUpdatedCommonGroupCount(userFull.commonChatsCount).withUpdatedIsBlocked(isBlocked).withUpdatedCallsAvailable(callsAvailable).withUpdatedCallsPrivate(callsPrivate).withUpdatedCanPinMessages(canPinMessages).withUpdatedPeerStatusSettings(peerStatusSettings).withUpdatedPinnedMessageId(pinnedMessageId).withUpdatedHasScheduledMessages(hasScheduledMessages) return previous.withUpdatedAbout(userFull.about).withUpdatedBotInfo(botInfo).withUpdatedCommonGroupCount(userFull.commonChatsCount).withUpdatedIsBlocked(isBlocked).withUpdatedCallsAvailable(callsAvailable).withUpdatedCallsPrivate(callsPrivate).withUpdatedCanPinMessages(canPinMessages).withUpdatedPeerStatusSettings(peerStatusSettings).withUpdatedPinnedMessageId(pinnedMessageId).withUpdatedHasScheduledMessages(hasScheduledMessages)
} }
}) })
return true
} }
} }
} else if peerId.namespace == Namespaces.Peer.CloudGroup { } else if peerId.namespace == Namespaces.Peer.CloudGroup {
return network.request(Api.functions.messages.getFullChat(chatId: peerId.id)) return network.request(Api.functions.messages.getFullChat(chatId: peerId.id))
|> retryRequest |> retryRequest
|> mapToSignal { result -> Signal<Void, NoError> in |> mapToSignal { result -> Signal<Bool, NoError> in
return postbox.transaction { transaction -> Void in return postbox.transaction { transaction -> Bool in
switch result { switch result {
case let .chatFull(fullChat, chats, users): case let .chatFull(fullChat, chats, users):
switch fullChat { switch fullChat {
@ -263,6 +291,7 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPeerId: PeerI
break break
} }
} }
return true
} }
} }
} else if let inputChannel = maybePeer.flatMap(apiInputChannel) { } else if let inputChannel = maybePeer.flatMap(apiInputChannel) {
@ -272,10 +301,10 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPeerId: PeerI
if error.errorDescription == "CHANNEL_PRIVATE" { if error.errorDescription == "CHANNEL_PRIVATE" {
return .single(nil) return .single(nil)
} }
return .complete() return .single(nil)
} }
|> mapToSignal { result -> Signal<Void, NoError> in |> mapToSignal { result -> Signal<Bool, NoError> in
return postbox.transaction { transaction -> Void in return postbox.transaction { transaction -> Bool in
if let result = result { if let result = result {
switch result { switch result {
case let .chatFull(fullChat, chats, users): case let .chatFull(fullChat, chats, users):
@ -440,10 +469,12 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPeerId: PeerI
return updated return updated
}) })
} }
return true
} }
} }
} else { } else {
return .complete() return .single(false)
}
} }
} }
} }

View File

@ -448,12 +448,12 @@ public final class WalletStrings: Equatable {
public var Wallet_SecureStorageReset_Title: String { return self._s[218]! } public var Wallet_SecureStorageReset_Title: String { return self._s[218]! }
public var Wallet_Receive_CommentHeader: String { return self._s[219]! } public var Wallet_Receive_CommentHeader: String { return self._s[219]! }
public var Wallet_Info_ReceiveGrams: String { return self._s[220]! } public var Wallet_Info_ReceiveGrams: String { return self._s[220]! }
public func Wallet_Updated_MinutesAgo(_ value: Int32) -> String { public func Wallet_Updated_HoursAgo(_ value: Int32) -> String {
let form = getPluralizationForm(self.lc, value) let form = getPluralizationForm(self.lc, value)
let stringValue = walletStringsFormattedNumber(value, self.groupingSeparator) let stringValue = walletStringsFormattedNumber(value, self.groupingSeparator)
return String(format: self._ps[0 * 6 + Int(form.rawValue)]!, stringValue) return String(format: self._ps[0 * 6 + Int(form.rawValue)]!, stringValue)
} }
public func Wallet_Updated_HoursAgo(_ value: Int32) -> String { public func Wallet_Updated_MinutesAgo(_ value: Int32) -> String {
let form = getPluralizationForm(self.lc, value) let form = getPluralizationForm(self.lc, value)
let stringValue = walletStringsFormattedNumber(value, self.groupingSeparator) let stringValue = walletStringsFormattedNumber(value, self.groupingSeparator)
return String(format: self._ps[1 * 6 + Int(form.rawValue)]!, stringValue) return String(format: self._ps[1 * 6 + Int(form.rawValue)]!, stringValue)