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 = [
"-e",
"_WKExtensionMain",
"-lWKExtensionMainLegacy",
],
configs = watch_extension_binary_configs(),
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.ShareAddress" = "Share Wallet Address";
"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.AmountText" = "Grams to receive";
"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
cd tools/buck
cd tools/buck-build
sh ./prepare_buck_source.sh $HOME/buck_source
```

View File

@ -651,7 +651,7 @@ final class AppDelegate: NSObject, UIApplicationDelegate {
print("Starting with \(documentsPath)")
#endif
let storage = WalletStorageInterfaceImpl(path: documentsPath + "/data", configurationPath: documentsPath + "/configuration")
let storage = WalletStorageInterfaceImpl(path: documentsPath + "/data", configurationPath: documentsPath + "/configuration_v2")
let initialConfigValue = storage.mergedLocalWalletConfiguration()
|> take(1)
@ -828,6 +828,6 @@ struct MergedLocalWalletConfiguration: Codable, Equatable {
private extension 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.ShareAddress" = "Share Wallet Address";
"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.AmountText" = "Grams to receive";
"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
}
context.timestamp = CFAbsoluteTimeGetCurrent()
if let account = self.account {
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())
guard let account = self.account else {
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)
if dataUpdated {
if let account = self.account {
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())
guard let account = self.account else {
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 TelegramApi
import SwiftSignalKit
import SyncCore
func fetchAndUpdateSupplementalCachedPeerData(peerId rawPeerId: PeerId, network: Network, postbox: Postbox) -> Signal<Void, NoError> {
return postbox.transaction { transaction -> Signal<Void, NoError> in
guard let rawPeer = transaction.getPeer(rawPeerId) else {
func fetchAndUpdateSupplementalCachedPeerData(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 -> Signal<Bool, NoError> in
guard let rawPeer = transaction.getPeer(rawPeerId) else {
return .single(false)
}
let peer: Peer
if let secretChat = rawPeer as? TelegramSecretChat {
guard let user = transaction.getPeer(secretChat.regularPeerId) else {
return .complete()
return .single(false)
}
peer = user
} else {
@ -25,24 +36,24 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId rawPeerId: PeerId, network:
if let cachedData = cachedData as? CachedUserData {
if cachedData.peerStatusSettings != nil {
return .complete()
return .single(true)
}
} else if let cachedData = cachedData as? CachedGroupData {
if cachedData.peerStatusSettings != nil {
return .complete()
return .single(true)
}
} else if let cachedData = cachedData as? CachedChannelData {
if cachedData.peerStatusSettings != nil {
return .complete()
return .single(true)
}
} else if let cachedData = cachedData as? CachedSecretChatData {
if cachedData.peerStatusSettings != nil {
return .complete()
return .single(true)
}
}
if peer.id.namespace == Namespaces.Peer.SecretChat {
return postbox.transaction { transaction -> Void in
return postbox.transaction { transaction -> Bool in
var peerStatusSettings: PeerStatusSettings
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 {
@ -64,14 +75,16 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId rawPeerId: PeerId, network:
return CachedSecretChatData(peerStatusSettings: peerStatusSettings)
}
})
return true
}
} else if let inputPeer = apiInputPeer(peer) {
return network.request(Api.functions.messages.getPeerSettings(peer: inputPeer))
|> retryRequest
|> mapToSignal { peerSettings -> Signal<Void, NoError> in
|> mapToSignal { peerSettings -> Signal<Bool, NoError> in
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
switch peer.id.namespace {
case Namespaces.Peer.CloudUser:
@ -103,16 +116,30 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId rawPeerId: PeerId, network:
}
return current
})
return true
}
}
} else {
return .complete()
return .single(false)
}
}
|> 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
guard let rawPeer = transaction.getPeer(rawPeerId) else {
if rawPeerId == accountPeerId {
@ -138,12 +165,12 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPeerId: PeerI
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 {
return network.request(Api.functions.users.getFullUser(id: inputUser))
|> retryRequest
|> mapToSignal { result -> Signal<Void, NoError> in
return postbox.transaction { transaction -> Void in
|> mapToSignal { result -> Signal<Bool, NoError> in
return postbox.transaction { transaction -> Bool in
switch result {
case let .userFull(userFull):
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 true
}
}
} else if peerId.namespace == Namespaces.Peer.CloudGroup {
return network.request(Api.functions.messages.getFullChat(chatId: peerId.id))
|> retryRequest
|> mapToSignal { result -> Signal<Void, NoError> in
return postbox.transaction { transaction -> Void in
|> mapToSignal { result -> Signal<Bool, NoError> in
return postbox.transaction { transaction -> Bool in
switch result {
case let .chatFull(fullChat, chats, users):
switch fullChat {
@ -263,6 +291,7 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPeerId: PeerI
break
}
}
return true
}
}
} else if let inputChannel = maybePeer.flatMap(apiInputChannel) {
@ -272,10 +301,10 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPeerId: PeerI
if error.errorDescription == "CHANNEL_PRIVATE" {
return .single(nil)
}
return .complete()
return .single(nil)
}
|> mapToSignal { result -> Signal<Void, NoError> in
return postbox.transaction { transaction -> Void in
|> mapToSignal { result -> Signal<Bool, NoError> in
return postbox.transaction { transaction -> Bool in
if let result = result {
switch result {
case let .chatFull(fullChat, chats, users):
@ -440,10 +469,12 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPeerId: PeerI
return updated
})
}
return true
}
}
} 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_Receive_CommentHeader: String { return self._s[219]! }
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 stringValue = walletStringsFormattedNumber(value, self.groupingSeparator)
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 stringValue = walletStringsFormattedNumber(value, self.groupingSeparator)
return String(format: self._ps[1 * 6 + Int(form.rawValue)]!, stringValue)