import Foundation import Postbox import SwiftSignalKit import TelegramApi import SyncCore public enum ServerProvidedSuggestion: String { case autoarchivePopular = "AUTOARCHIVE_POPULAR" case newcomerTicks = "NEWCOMER_TICKS" } public func getServerProvidedSuggestions(postbox: Postbox) -> Signal<[ServerProvidedSuggestion], NoError> { let key: PostboxViewKey = .preferences(keys: Set([PreferencesKeys.appConfiguration])) return postbox.combinedView(keys: [key]) |> map { views -> [ServerProvidedSuggestion] in guard let view = views.views[key] as? PreferencesView else { return [] } guard let appConfiguration = view.values[PreferencesKeys.appConfiguration] as? AppConfiguration else { return [] } guard let data = appConfiguration.data, let list = data["pending_suggestions"] as? [String] else { return [] } return list.compactMap { item -> ServerProvidedSuggestion? in return ServerProvidedSuggestion(rawValue: item) } } |> distinctUntilChanged } public func dismissServerProvidedSuggestion(account: Account, suggestion: ServerProvidedSuggestion) -> Signal { return account.network.request(Api.functions.help.dismissSuggestion(suggestion: suggestion.rawValue)) |> `catch` { _ -> Signal in return .single(.boolFalse) } |> ignoreValues }