Various improvements [skip ci]

This commit is contained in:
Ilya Laktyushin
2025-02-12 22:15:02 +04:00
parent 8c523ec741
commit 2f2a27f0d2
130 changed files with 5126 additions and 1700 deletions

View File

@@ -16,19 +16,28 @@ func _internal_updateGlobalPrivacySettings(account: Account) -> Signal<Never, No
}
let globalSettings: GlobalPrivacySettings
switch result {
case let .globalPrivacySettings(flags):
case let .globalPrivacySettings(flags, nonContactPeersPaidStars):
let automaticallyArchiveAndMuteNonContacts = (flags & (1 << 0)) != 0
let keepArchivedUnmuted = (flags & (1 << 1)) != 0
let keepArchivedFolders = (flags & (1 << 2)) != 0
let hideReadTime = (flags & (1 << 3)) != 0
let nonContactChatsRequirePremium = (flags & (1 << 4)) != 0
let nonContactChatsPrivacy: GlobalPrivacySettings.NonContactChatsPrivacy
if let nonContactPeersPaidStars, nonContactPeersPaidStars > 0 {
nonContactChatsPrivacy = .paidMessages(StarsAmount(value: nonContactPeersPaidStars, nanos: 0))
} else if nonContactChatsRequirePremium {
nonContactChatsPrivacy = .requirePremium
} else {
nonContactChatsPrivacy = .everybody
}
globalSettings = GlobalPrivacySettings(
automaticallyArchiveAndMuteNonContacts: automaticallyArchiveAndMuteNonContacts,
keepArchivedUnmuted: keepArchivedUnmuted,
keepArchivedFolders: keepArchivedFolders,
hideReadTime: hideReadTime,
nonContactChatsRequirePremium: nonContactChatsRequirePremium
nonContactChatsPrivacy: nonContactChatsPrivacy
)
}
updateGlobalPrivacySettings(transaction: transaction, { _ in
@@ -52,15 +61,17 @@ func _internal_requestAccountPrivacySettings(account: Account) -> Signal<Account
let bioPrivacy = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyAbout))
let birthdayPrivacy = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyBirthday))
let giftsAutoSavePrivacy = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyStarGiftsAutoSave))
let noPaidMessagesPrivacy = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyNoPaidMessages))
let autoremoveTimeout = account.network.request(Api.functions.account.getAccountTTL())
let globalPrivacySettings = account.network.request(Api.functions.account.getGlobalPrivacySettings())
let messageAutoremoveTimeout = account.network.request(Api.functions.messages.getDefaultHistoryTTL())
return combineLatest(lastSeenPrivacy, groupPrivacy, voiceCallPrivacy, voiceCallP2P, profilePhotoPrivacy, forwardPrivacy, phoneNumberPrivacy, phoneDiscoveryPrivacy, voiceMessagesPrivacy, bioPrivacy, birthdayPrivacy, giftsAutoSavePrivacy, autoremoveTimeout, globalPrivacySettings, messageAutoremoveTimeout)
return combineLatest(lastSeenPrivacy, groupPrivacy, voiceCallPrivacy, voiceCallP2P, profilePhotoPrivacy, forwardPrivacy, phoneNumberPrivacy, phoneDiscoveryPrivacy, voiceMessagesPrivacy, bioPrivacy, birthdayPrivacy, giftsAutoSavePrivacy, noPaidMessagesPrivacy, autoremoveTimeout, globalPrivacySettings, messageAutoremoveTimeout)
|> `catch` { _ in
return .complete()
}
|> mapToSignal { lastSeenPrivacy, groupPrivacy, voiceCallPrivacy, voiceCallP2P, profilePhotoPrivacy, forwardPrivacy, phoneNumberPrivacy, phoneDiscoveryPrivacy, voiceMessagesPrivacy, bioPrivacy, birthdayPrivacy, giftsAutoSavePrivacy, autoremoveTimeout, globalPrivacySettings, messageAutoremoveTimeout -> Signal<AccountPrivacySettings, NoError> in
|> mapToSignal { lastSeenPrivacy, groupPrivacy, voiceCallPrivacy, voiceCallP2P, profilePhotoPrivacy, forwardPrivacy, phoneNumberPrivacy, phoneDiscoveryPrivacy, voiceMessagesPrivacy, bioPrivacy, birthdayPrivacy, giftsAutoSavePrivacy, noPaidMessagesPrivacy, autoremoveTimeout, globalPrivacySettings, messageAutoremoveTimeout -> Signal<AccountPrivacySettings, NoError> in
let accountTimeoutSeconds: Int32
switch autoremoveTimeout {
case let .accountDaysTTL(days):
@@ -88,6 +99,7 @@ func _internal_requestAccountPrivacySettings(account: Account) -> Signal<Account
let bioRules: [Api.PrivacyRule]
let birthdayRules: [Api.PrivacyRule]
let giftsAutoSaveRules: [Api.PrivacyRule]
let noPaidMessagesRules: [Api.PrivacyRule]
var apiUsers: [Api.User] = []
var apiChats: [Api.Chat] = []
@@ -180,6 +192,12 @@ func _internal_requestAccountPrivacySettings(account: Account) -> Signal<Account
apiChats.append(contentsOf: chats)
giftsAutoSaveRules = rules
}
switch noPaidMessagesPrivacy {
case let .privacyRules(rules, chats, users):
apiUsers.append(contentsOf: users)
apiChats.append(contentsOf: chats)
noPaidMessagesRules = rules
}
var peers: [SelectivePrivacyPeer] = []
for user in apiUsers {
@@ -204,18 +222,28 @@ func _internal_requestAccountPrivacySettings(account: Account) -> Signal<Account
let globalSettings: GlobalPrivacySettings
switch globalPrivacySettings {
case let .globalPrivacySettings(flags):
case let .globalPrivacySettings(flags, nonContactPeersPaidStars):
let automaticallyArchiveAndMuteNonContacts = (flags & (1 << 0)) != 0
let keepArchivedUnmuted = (flags & (1 << 1)) != 0
let keepArchivedFolders = (flags & (1 << 2)) != 0
let hideReadTime = (flags & (1 << 3)) != 0
let nonContactChatsRequirePremium = (flags & (1 << 4)) != 0
let nonContactChatsPrivacy: GlobalPrivacySettings.NonContactChatsPrivacy
if let nonContactPeersPaidStars, nonContactPeersPaidStars > 0 {
nonContactChatsPrivacy = .paidMessages(StarsAmount(value: nonContactPeersPaidStars, nanos: 0))
} else if nonContactChatsRequirePremium {
nonContactChatsPrivacy = .requirePremium
} else {
nonContactChatsPrivacy = .everybody
}
globalSettings = GlobalPrivacySettings(
automaticallyArchiveAndMuteNonContacts: automaticallyArchiveAndMuteNonContacts,
keepArchivedUnmuted: keepArchivedUnmuted,
keepArchivedFolders: keepArchivedFolders,
hideReadTime: hideReadTime,
nonContactChatsRequirePremium: nonContactChatsRequirePremium
nonContactChatsPrivacy: nonContactChatsPrivacy
)
}
@@ -247,6 +275,7 @@ func _internal_requestAccountPrivacySettings(account: Account) -> Signal<Account
bio: SelectivePrivacySettings(apiRules: bioRules, peers: peerMap),
birthday: SelectivePrivacySettings(apiRules: birthdayRules, peers: peerMap),
giftsAutoSave: SelectivePrivacySettings(apiRules: giftsAutoSaveRules, peers: peerMap),
noPaidMessages: SelectivePrivacySettings(apiRules: noPaidMessagesRules, peers: peerMap),
globalSettings: globalSettings,
accountRemovalTimeout: accountTimeoutSeconds,
messageAutoremoveTimeout: messageAutoremoveSeconds
@@ -266,13 +295,13 @@ func _internal_updateAccountAutoArchiveChats(account: Account, value: Bool) -> S
}
}
func _internal_updateNonContactChatsRequirePremium(account: Account, value: Bool) -> Signal<Never, NoError> {
func _internal_updateNonContactChatsPrivacy(account: Account, value: GlobalPrivacySettings.NonContactChatsPrivacy) -> Signal<Never, NoError> {
return account.postbox.transaction { transaction -> GlobalPrivacySettings in
return fetchGlobalPrivacySettings(transaction: transaction)
}
|> mapToSignal { settings -> Signal<Never, NoError> in
var settings = settings
settings.nonContactChatsRequirePremium = value
settings.nonContactChatsPrivacy = value
return _internal_updateGlobalPrivacySettings(account: account, settings: settings)
}
}
@@ -319,12 +348,20 @@ func _internal_updateGlobalPrivacySettings(account: Account, settings: GlobalPri
if settings.hideReadTime {
flags |= 1 << 3
}
if settings.nonContactChatsRequirePremium {
var noncontactPeersPaidStars: Int64?
switch settings.nonContactChatsPrivacy {
case .everybody:
break
case .requirePremium:
flags |= 1 << 4
case let .paidMessages(starsAmount):
flags |= 1 << 5
noncontactPeersPaidStars = starsAmount.value
}
return account.network.request(Api.functions.account.setGlobalPrivacySettings(
settings: .globalPrivacySettings(flags: flags)
settings: .globalPrivacySettings(flags: flags, noncontactPeersPaidStars: noncontactPeersPaidStars)
))
|> retryRequest
|> ignoreValues
@@ -382,6 +419,7 @@ public enum UpdateSelectiveAccountPrivacySettingsType {
case bio
case birthday
case giftsAutoSave
case noPaidMessages
var apiKey: Api.InputPrivacyKey {
switch self {
@@ -407,6 +445,8 @@ public enum UpdateSelectiveAccountPrivacySettingsType {
return .inputPrivacyKeyBirthday
case .giftsAutoSave:
return .inputPrivacyKeyStarGiftsAutoSave
case .noPaidMessages:
return .inputPrivacyKeyNoPaidMessages
}
}
}