Various improvements

This commit is contained in:
Ilya Laktyushin
2022-07-13 12:15:10 +02:00
parent aa46e81a49
commit 9a115af042
53 changed files with 27836 additions and 27476 deletions

View File

@@ -12,7 +12,7 @@ public enum AssignAppStoreTransactionError {
public enum AppStoreTransactionPurpose {
case subscription
case gift(EnginePeer.Id)
case gift(peerId: EnginePeer.Id, currency: String, amount: Int64)
case restore
}
@@ -25,11 +25,11 @@ func _internal_sendAppStoreReceipt(account: Account, receipt: Data, purpose: App
flags |= (1 << 0)
}
purposeSignal = .single(.inputStorePaymentPremiumSubscription(flags: flags))
case let .gift(peerId):
case let .gift(peerId, currency, amount):
purposeSignal = account.postbox.loadedPeerWithId(peerId)
|> mapToSignal { peer -> Signal<Api.InputStorePaymentPurpose, NoError> in
if let inputUser = apiInputUser(peer) {
return .single(.inputStorePaymentGiftPremium(userId: inputUser))
return .single(.inputStorePaymentGiftPremium(userId: inputUser, currency: currency, amount: amount))
} else {
return .complete()
}

View File

@@ -239,11 +239,13 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
let isBlocked = (userFullFlags & (1 << 0)) != 0
let voiceCallsAvailable = (userFullFlags & (1 << 4)) != 0
let videoCallsAvailable = (userFullFlags & (1 << 13)) != 0
let voiceMessagesAvailable = (userFullFlags & (1 << 20)) == 0
let callsPrivate = (userFullFlags & (1 << 5)) != 0
let canPinMessages = (userFullFlags & (1 << 7)) != 0
let pinnedMessageId = userFullPinnedMsgId.flatMap({ MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: $0) })
let peerStatusSettings = PeerStatusSettings(apiSettings: userFullSettings)
let hasScheduledMessages = (userFullFlags & 1 << 12) != 0
@@ -271,6 +273,7 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
.withUpdatedThemeEmoticon(userFullThemeEmoticon)
.withUpdatedPhoto(photo)
.withUpdatedPremiumGiftOptions(premiumGiftOptions)
.withUpdatedVoiceMessagesAvailable(voiceMessagesAvailable)
}
})
}

View File

@@ -13,13 +13,14 @@ func _internal_requestAccountPrivacySettings(account: Account) -> Signal<Account
let forwardPrivacy = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyForwards))
let phoneNumberPrivacy = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyPhoneNumber))
let phoneDiscoveryPrivacy = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyAddedByPhone))
let voiceMessagesPrivacy = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyVoiceMessages))
let autoremoveTimeout = account.network.request(Api.functions.account.getAccountTTL())
let globalPrivacySettings = account.network.request(Api.functions.account.getGlobalPrivacySettings())
return combineLatest(lastSeenPrivacy, groupPrivacy, voiceCallPrivacy, voiceCallP2P, profilePhotoPrivacy, forwardPrivacy, phoneNumberPrivacy, phoneDiscoveryPrivacy, autoremoveTimeout, globalPrivacySettings)
return combineLatest(lastSeenPrivacy, groupPrivacy, voiceCallPrivacy, voiceCallP2P, profilePhotoPrivacy, forwardPrivacy, phoneNumberPrivacy, phoneDiscoveryPrivacy, voiceMessagesPrivacy, autoremoveTimeout, globalPrivacySettings)
|> `catch` { _ in
return .complete()
}
|> mapToSignal { lastSeenPrivacy, groupPrivacy, voiceCallPrivacy, voiceCallP2P, profilePhotoPrivacy, forwardPrivacy, phoneNumberPrivacy, phoneDiscoveryPrivacy, autoremoveTimeout, globalPrivacySettings -> Signal<AccountPrivacySettings, NoError> in
|> mapToSignal { lastSeenPrivacy, groupPrivacy, voiceCallPrivacy, voiceCallP2P, profilePhotoPrivacy, forwardPrivacy, phoneNumberPrivacy, phoneDiscoveryPrivacy, voiceMessagesPrivacy, autoremoveTimeout, globalPrivacySettings -> Signal<AccountPrivacySettings, NoError> in
let accountTimeoutSeconds: Int32
switch autoremoveTimeout {
case let .accountDaysTTL(days):
@@ -33,6 +34,7 @@ func _internal_requestAccountPrivacySettings(account: Account) -> Signal<Account
let profilePhotoRules: [Api.PrivacyRule]
let forwardRules: [Api.PrivacyRule]
let phoneNumberRules: [Api.PrivacyRule]
let voiceMessagesRules: [Api.PrivacyRule]
var apiUsers: [Api.User] = []
var apiChats: [Api.Chat] = []
@@ -98,6 +100,13 @@ func _internal_requestAccountPrivacySettings(account: Account) -> Signal<Account
}
}
switch voiceMessagesPrivacy {
case let .privacyRules(rules, chats, users):
apiUsers.append(contentsOf: users)
apiChats.append(contentsOf: chats)
voiceMessagesRules = rules
}
var peers: [SelectivePrivacyPeer] = []
for user in apiUsers {
peers.append(SelectivePrivacyPeer(peer: TelegramUser(user: user), participantCount: nil))
@@ -134,7 +143,7 @@ func _internal_requestAccountPrivacySettings(account: Account) -> Signal<Account
return updated
})
return AccountPrivacySettings(presence: SelectivePrivacySettings(apiRules: lastSeenRules, peers: peerMap), groupInvitations: SelectivePrivacySettings(apiRules: groupRules, peers: peerMap), voiceCalls: SelectivePrivacySettings(apiRules: voiceRules, peers: peerMap), voiceCallsP2P: SelectivePrivacySettings(apiRules: voiceP2PRules, peers: peerMap), profilePhoto: SelectivePrivacySettings(apiRules: profilePhotoRules, peers: peerMap), forwards: SelectivePrivacySettings(apiRules: forwardRules, peers: peerMap), phoneNumber: SelectivePrivacySettings(apiRules: phoneNumberRules, peers: peerMap), phoneDiscoveryEnabled: phoneDiscoveryValue, automaticallyArchiveAndMuteNonContacts: automaticallyArchiveAndMuteNonContacts, accountRemovalTimeout: accountTimeoutSeconds)
return AccountPrivacySettings(presence: SelectivePrivacySettings(apiRules: lastSeenRules, peers: peerMap), groupInvitations: SelectivePrivacySettings(apiRules: groupRules, peers: peerMap), voiceCalls: SelectivePrivacySettings(apiRules: voiceRules, peers: peerMap), voiceCallsP2P: SelectivePrivacySettings(apiRules: voiceP2PRules, peers: peerMap), profilePhoto: SelectivePrivacySettings(apiRules: profilePhotoRules, peers: peerMap), forwards: SelectivePrivacySettings(apiRules: forwardRules, peers: peerMap), phoneNumber: SelectivePrivacySettings(apiRules: phoneNumberRules, peers: peerMap), phoneDiscoveryEnabled: phoneDiscoveryValue, voiceMessages: SelectivePrivacySettings(apiRules: voiceMessagesRules, peers: peerMap), automaticallyArchiveAndMuteNonContacts: automaticallyArchiveAndMuteNonContacts, accountRemovalTimeout: accountTimeoutSeconds)
}
}
}
@@ -177,6 +186,7 @@ public enum UpdateSelectiveAccountPrivacySettingsType {
case profilePhoto
case forwards
case phoneNumber
case voiceMessages
var apiKey: Api.InputPrivacyKey {
switch self {
@@ -194,6 +204,8 @@ public enum UpdateSelectiveAccountPrivacySettingsType {
return .inputPrivacyKeyForwards
case .phoneNumber:
return .inputPrivacyKeyPhoneNumber
case .voiceMessages:
return .inputPrivacyKeyVoiceMessages
}
}
}

View File

@@ -124,6 +124,20 @@ func _internal_cachedStickerPack(postbox: Postbox, network: Network, reference:
} else {
return (.fetching, true, nil)
}
case .premiumGifts:
let namespace = Namespaces.ItemCollection.CloudPremiumGifts
let id: ItemCollectionId.Id = 0
if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id))))?.get(CachedStickerPack.self), let info = cached.info {
previousHash = cached.hash
let current: CachedStickerPackResult = .result(info, cached.items, false)
if cached.hash != info.hash {
return (current, true, previousHash)
} else {
return (current, false, previousHash)
}
} else {
return (.fetching, true, nil)
}
}
}
|> mapToSignal { result, loadRemote, previousHash in
@@ -220,6 +234,18 @@ func cachedStickerPack(transaction: Transaction, reference: StickerPackReference
if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id))))?.get(CachedStickerPack.self), let info = cached.info {
return (info, cached.items, false)
}
case .premiumGifts:
let namespace = Namespaces.ItemCollection.CloudPremiumGifts
let id: ItemCollectionId.Id = 0
if let currentInfo = transaction.getItemCollectionInfo(collectionId: ItemCollectionId(namespace: namespace, id: id)) as? StickerPackCollectionInfo {
let items = transaction.getItemCollectionItems(collectionId: ItemCollectionId(namespace: namespace, id: id))
if !items.isEmpty {
return (currentInfo, items.compactMap { $0 as? StickerPackItem }, true)
}
}
if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id))))?.get(CachedStickerPack.self), let info = cached.info {
return (info, cached.items, false)
}
}
return nil
}

View File

@@ -20,6 +20,8 @@ extension StickerPackReference {
return .inputStickerSetDice(emoticon: emoji)
case .animatedEmojiAnimations:
return .inputStickerSetAnimatedEmojiAnimations
case .premiumGifts:
return .inputStickerSetPremiumGifts
}
}
}

View File

@@ -43,6 +43,9 @@ func _internal_requestStickerSet(postbox: Postbox, network: Network, reference:
case .animatedEmojiAnimations:
collectionId = nil
input = .inputStickerSetAnimatedEmojiAnimations
case .premiumGifts:
collectionId = nil
input = .inputStickerSetPremiumGifts
}
let localSignal: (ItemCollectionId) -> Signal<(ItemCollectionInfo, [ItemCollectionItem])?, NoError> = { collectionId in