mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Refactoring
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
import TelegramApi
|
||||
import SwiftSignalKit
|
||||
import SyncCore
|
||||
|
||||
extension PeerStatusSettings {
|
||||
init(apiSettings: Api.PeerSettings) {
|
||||
switch apiSettings {
|
||||
case let .peerSettings(flags, geoDistance):
|
||||
var result = PeerStatusSettings.Flags()
|
||||
if (flags & (1 << 1)) != 0 {
|
||||
result.insert(.canAddContact)
|
||||
}
|
||||
if (flags & (1 << 0)) != 0 {
|
||||
result.insert(.canReport)
|
||||
}
|
||||
if (flags & (1 << 2)) != 0 {
|
||||
result.insert(.canBlock)
|
||||
}
|
||||
if (flags & (1 << 3)) != 0 {
|
||||
result.insert(.canShareContact)
|
||||
}
|
||||
if (flags & (1 << 4)) != 0 {
|
||||
result.insert(.addExceptionWhenAddingContact)
|
||||
}
|
||||
if (flags & (1 << 5)) != 0 {
|
||||
result.insert(.canReportIrrelevantGeoLocation)
|
||||
}
|
||||
if (flags & (1 << 7)) != 0 {
|
||||
result.insert(.autoArchived)
|
||||
}
|
||||
if (flags & (1 << 8)) != 0 {
|
||||
result.insert(.suggestAddMembers)
|
||||
}
|
||||
self = PeerStatusSettings(flags: result, geoDistance: geoDistance)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func unarchiveAutomaticallyArchivedPeer(account: Account, peerId: PeerId) {
|
||||
let _ = (account.postbox.transaction { transaction -> Void in
|
||||
updatePeerGroupIdInteractively(transaction: transaction, peerId: peerId, groupId: .root)
|
||||
transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in
|
||||
if let currentData = current as? CachedUserData, let currentStatusSettings = currentData.peerStatusSettings {
|
||||
var statusSettings = currentStatusSettings
|
||||
statusSettings.flags.remove(.canBlock)
|
||||
statusSettings.flags.remove(.canReport)
|
||||
statusSettings.flags.remove(.autoArchived)
|
||||
return currentData.withUpdatedPeerStatusSettings(statusSettings)
|
||||
} else if let currentData = current as? CachedGroupData, let currentStatusSettings = currentData.peerStatusSettings {
|
||||
var statusSettings = currentStatusSettings
|
||||
statusSettings.flags.remove(.canReport)
|
||||
statusSettings.flags.remove(.autoArchived)
|
||||
return currentData.withUpdatedPeerStatusSettings(statusSettings)
|
||||
} else if let currentData = current as? CachedChannelData, let currentStatusSettings = currentData.peerStatusSettings {
|
||||
var statusSettings = currentStatusSettings
|
||||
statusSettings.flags.remove(.canReport)
|
||||
statusSettings.flags.remove(.autoArchived)
|
||||
return currentData.withUpdatedPeerStatusSettings(statusSettings)
|
||||
}else {
|
||||
return current
|
||||
}
|
||||
})
|
||||
}
|
||||
|> deliverOnMainQueue).start()
|
||||
|
||||
let _ = updatePeerMuteSetting(account: account, peerId: peerId, muteInterval: nil).start()
|
||||
}
|
||||
Reference in New Issue
Block a user