Folder improvements

This commit is contained in:
Ali
2023-04-01 23:18:58 +04:00
parent 195b4a0159
commit dfe8e80232
6 changed files with 141 additions and 71 deletions

View File

@@ -175,6 +175,7 @@ extension ChatListFilterIncludePeers {
public struct ChatListFilterData: Equatable, Hashable {
public var isShared: Bool
public var hasSharedLinks: Bool
public var categories: ChatListFilterPeerCategories
public var excludeMuted: Bool
public var excludeRead: Bool
@@ -184,6 +185,7 @@ public struct ChatListFilterData: Equatable, Hashable {
public init(
isShared: Bool,
hasSharedLinks: Bool,
categories: ChatListFilterPeerCategories,
excludeMuted: Bool,
excludeRead: Bool,
@@ -192,6 +194,7 @@ public struct ChatListFilterData: Equatable, Hashable {
excludePeers: [PeerId]
) {
self.isShared = isShared
self.hasSharedLinks = hasSharedLinks
self.categories = categories
self.excludeMuted = excludeMuted
self.excludeRead = excludeRead
@@ -250,6 +253,7 @@ public enum ChatListFilter: Codable, Equatable {
let data = ChatListFilterData(
isShared: try container.decodeIfPresent(Bool.self, forKey: "isShared") ?? false,
hasSharedLinks: try container.decodeIfPresent(Bool.self, forKey: "hasSharedLinks") ?? false,
categories: ChatListFilterPeerCategories(rawValue: try container.decode(Int32.self, forKey: "categories")),
excludeMuted: (try container.decode(Int32.self, forKey: "excludeMuted")) != 0,
excludeRead: (try container.decode(Int32.self, forKey: "excludeRead")) != 0,
@@ -280,6 +284,7 @@ public enum ChatListFilter: Codable, Equatable {
try container.encodeIfPresent(emoticon, forKey: "emoticon")
try container.encode(data.isShared, forKey: "isShared")
try container.encode(data.hasSharedLinks, forKey: "hasSharedLinks")
try container.encode(data.categories.rawValue, forKey: "categories")
try container.encode((data.excludeMuted ? 1 : 0) as Int32, forKey: "excludeMuted")
try container.encode((data.excludeRead ? 1 : 0) as Int32, forKey: "excludeRead")
@@ -303,6 +308,7 @@ extension ChatListFilter {
emoticon: emoticon,
data: ChatListFilterData(
isShared: false,
hasSharedLinks: false,
categories: ChatListFilterPeerCategories(apiFlags: flags),
excludeMuted: (flags & (1 << 11)) != 0,
excludeRead: (flags & (1 << 12)) != 0,
@@ -344,13 +350,14 @@ extension ChatListFilter {
}
)
)
case let .dialogFilterCommunity(_, id, title, emoticon, pinnedPeers, includePeers):
case let .dialogFilterCommunity(flags, id, title, emoticon, pinnedPeers, includePeers):
self = .filter(
id: id,
title: title,
emoticon: emoticon,
data: ChatListFilterData(
isShared: true,
hasSharedLinks: (flags & (1 << 26)) != 0,
categories: [],
excludeMuted: false,
excludeRead: false,
@@ -1078,7 +1085,8 @@ public struct ChatListFeaturedFilter: Codable, Equatable {
self.title = try container.decode(String.self, forKey: "title")
self.description = try container.decode(String.self, forKey: "description")
self.data = ChatListFilterData(
isShared: try container.decodeIfPresent(Bool.self, forKey: "isShared") ?? false,
isShared: false,
hasSharedLinks: false,
categories: ChatListFilterPeerCategories(rawValue: try container.decode(Int32.self, forKey: "categories")),
excludeMuted: (try container.decode(Int32.self, forKey: "excludeMuted")) != 0,
excludeRead: (try container.decode(Int32.self, forKey: "excludeRead")) != 0,

View File

@@ -539,24 +539,29 @@ private struct FirstTimeFolderUpdatesKey: Hashable {
private var firstTimeFolderUpdates = Set<FirstTimeFolderUpdatesKey>()
func _internal_pollChatFolderUpdatesOnce(account: Account, folderId: Int32) -> Signal<Never, NoError> {
return account.postbox.transaction { transaction -> ChatListFiltersState in
return _internal_currentChatListFiltersState(transaction: transaction)
return account.postbox.transaction { transaction -> (ChatListFiltersState, AppConfiguration) in
return (_internal_currentChatListFiltersState(transaction: transaction), currentAppConfiguration(transaction: transaction))
}
|> mapToSignal { state -> Signal<Never, NoError> in
|> mapToSignal { state, appConfig -> Signal<Never, NoError> in
let timestamp = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
let key = FirstTimeFolderUpdatesKey(accountId: account.id, folderId: folderId)
if firstTimeFolderUpdates.contains(key) {
if let current = state.updates.first(where: { $0.folderId == folderId }) {
let updateInterval: Int32
var updateInterval: Int32 = 3600
if let data = appConfig.data {
if let value = data["community_update_period"] as? Double {
updateInterval = Int32(value)
}
}
#if DEBUG
updateInterval = 5
#else
updateInterval = 60 * 60
if "".isEmpty {
updateInterval = 5
}
#endif
if current.timestamp + updateInterval >= timestamp {
return .complete()
}
}