mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Refactoring
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
import SwiftSignalKit
|
||||
|
||||
import SyncCore
|
||||
|
||||
func managedNotificationSettingsBehaviors(postbox: Postbox) -> Signal<Never, NoError> {
|
||||
return postbox.combinedView(keys: [.peerNotificationSettingsBehaviorTimestampView])
|
||||
|> mapToSignal { views -> Signal<Never, NoError> in
|
||||
guard let view = views.views[.peerNotificationSettingsBehaviorTimestampView] as? PeerNotificationSettingsBehaviorTimestampView else {
|
||||
return .complete()
|
||||
}
|
||||
guard let earliestTimestamp = view.earliestTimestamp else {
|
||||
return .complete()
|
||||
}
|
||||
|
||||
let checkSignal = postbox.transaction { transaction -> Void in
|
||||
let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970)
|
||||
for (peerId, notificationSettings) in transaction.getPeerIdsAndNotificationSettingsWithBehaviorTimestampLessThanOrEqualTo(timestamp) {
|
||||
if let notificationSettings = notificationSettings as? TelegramPeerNotificationSettings {
|
||||
if case let .muted(untilTimestamp) = notificationSettings.muteState, untilTimestamp <= timestamp {
|
||||
transaction.updateCurrentPeerNotificationSettings([peerId: notificationSettings.withUpdatedMuteState(.unmuted)])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|> ignoreValues
|
||||
|
||||
let timeout = earliestTimestamp - Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970)
|
||||
if timeout <= 0 {
|
||||
return checkSignal
|
||||
} else {
|
||||
return checkSignal |> delay(Double(timeout), queue: .mainQueue())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user