mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-07 05:25:12 +00:00
Experimental chat list filtering
This commit is contained in:
@@ -40,7 +40,7 @@ public struct InAppNotificationSettings: PreferencesEntry, Equatable {
|
||||
public var displayNotificationsFromAllAccounts: Bool
|
||||
|
||||
public static var defaultSettings: InAppNotificationSettings {
|
||||
return InAppNotificationSettings(playSounds: true, vibrate: false, displayPreviews: true, totalUnreadCountDisplayStyle: .filtered, totalUnreadCountDisplayCategory: .messages, totalUnreadCountIncludeTags: [.regularChatsAndPrivateGroups], displayNameOnLockscreen: true, displayNotificationsFromAllAccounts: true)
|
||||
return InAppNotificationSettings(playSounds: true, vibrate: false, displayPreviews: true, totalUnreadCountDisplayStyle: .filtered, totalUnreadCountDisplayCategory: .messages, totalUnreadCountIncludeTags: [.privateChat, .secretChat, .bot, .privateGroup], displayNameOnLockscreen: true, displayNotificationsFromAllAccounts: true)
|
||||
}
|
||||
|
||||
public init(playSounds: Bool, vibrate: Bool, displayPreviews: Bool, totalUnreadCountDisplayStyle: TotalUnreadCountDisplayStyle, totalUnreadCountDisplayCategory: TotalUnreadCountDisplayCategory, totalUnreadCountIncludeTags: PeerSummaryCounterTags, displayNameOnLockscreen: Bool, displayNotificationsFromAllAccounts: Bool) {
|
||||
@@ -60,10 +60,25 @@ public struct InAppNotificationSettings: PreferencesEntry, Equatable {
|
||||
self.displayPreviews = decoder.decodeInt32ForKey("p", orElse: 0) != 0
|
||||
self.totalUnreadCountDisplayStyle = TotalUnreadCountDisplayStyle(rawValue: decoder.decodeInt32ForKey("cds", orElse: 0)) ?? .filtered
|
||||
self.totalUnreadCountDisplayCategory = TotalUnreadCountDisplayCategory(rawValue: decoder.decodeInt32ForKey("totalUnreadCountDisplayCategory", orElse: 1)) ?? .messages
|
||||
if let value = decoder.decodeOptionalInt32ForKey("totalUnreadCountIncludeTags") {
|
||||
if let value = decoder.decodeOptionalInt32ForKey("totalUnreadCountIncludeTags_2") {
|
||||
self.totalUnreadCountIncludeTags = PeerSummaryCounterTags(rawValue: value)
|
||||
} else if let value = decoder.decodeOptionalInt32ForKey("totalUnreadCountIncludeTags") {
|
||||
var resultTags: PeerSummaryCounterTags = []
|
||||
for legacyTag in LegacyPeerSummaryCounterTags(rawValue: value) {
|
||||
if legacyTag == .regularChatsAndPrivateGroups {
|
||||
resultTags.insert(.privateChat)
|
||||
resultTags.insert(.secretChat)
|
||||
resultTags.insert(.bot)
|
||||
resultTags.insert(.privateGroup)
|
||||
} else if legacyTag == .publicGroups {
|
||||
resultTags.insert(.publicGroup)
|
||||
} else if legacyTag == .channels {
|
||||
resultTags.insert(.channel)
|
||||
}
|
||||
}
|
||||
self.totalUnreadCountIncludeTags = resultTags
|
||||
} else {
|
||||
self.totalUnreadCountIncludeTags = [.regularChatsAndPrivateGroups]
|
||||
self.totalUnreadCountIncludeTags = [.privateChat, .secretChat, .bot, .privateGroup]
|
||||
}
|
||||
self.displayNameOnLockscreen = decoder.decodeInt32ForKey("displayNameOnLockscreen", orElse: 1) != 0
|
||||
self.displayNotificationsFromAllAccounts = decoder.decodeInt32ForKey("displayNotificationsFromAllAccounts", orElse: 1) != 0
|
||||
@@ -75,7 +90,7 @@ public struct InAppNotificationSettings: PreferencesEntry, Equatable {
|
||||
encoder.encodeInt32(self.displayPreviews ? 1 : 0, forKey: "p")
|
||||
encoder.encodeInt32(self.totalUnreadCountDisplayStyle.rawValue, forKey: "cds")
|
||||
encoder.encodeInt32(self.totalUnreadCountDisplayCategory.rawValue, forKey: "totalUnreadCountDisplayCategory")
|
||||
encoder.encodeInt32(self.totalUnreadCountIncludeTags.rawValue, forKey: "totalUnreadCountIncludeTags")
|
||||
encoder.encodeInt32(self.totalUnreadCountIncludeTags.rawValue, forKey: "totalUnreadCountIncludeTags_2")
|
||||
encoder.encodeInt32(self.displayNameOnLockscreen ? 1 : 0, forKey: "displayNameOnLockscreen")
|
||||
encoder.encodeInt32(self.displayNotificationsFromAllAccounts ? 1 : 0, forKey: "displayNotificationsFromAllAccounts")
|
||||
}
|
||||
|
||||
@@ -1,9 +1,43 @@
|
||||
import PostboxDataTypes
|
||||
|
||||
struct LegacyPeerSummaryCounterTags: OptionSet, Sequence, Hashable {
|
||||
var rawValue: Int32
|
||||
|
||||
init(rawValue: Int32) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
static let regularChatsAndPrivateGroups = LegacyPeerSummaryCounterTags(rawValue: 1 << 0)
|
||||
static let publicGroups = LegacyPeerSummaryCounterTags(rawValue: 1 << 1)
|
||||
static let channels = LegacyPeerSummaryCounterTags(rawValue: 1 << 2)
|
||||
|
||||
public func makeIterator() -> AnyIterator<LegacyPeerSummaryCounterTags> {
|
||||
var index = 0
|
||||
return AnyIterator { () -> LegacyPeerSummaryCounterTags? in
|
||||
while index < 31 {
|
||||
let currentTags = self.rawValue >> UInt32(index)
|
||||
let tag = LegacyPeerSummaryCounterTags(rawValue: 1 << UInt32(index))
|
||||
index += 1
|
||||
if currentTags == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
if (currentTags & 1) != 0 {
|
||||
return tag
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension PeerSummaryCounterTags {
|
||||
static let regularChatsAndPrivateGroups = PeerSummaryCounterTags(rawValue: 1 << 0)
|
||||
static let publicGroups = PeerSummaryCounterTags(rawValue: 1 << 1)
|
||||
static let channels = PeerSummaryCounterTags(rawValue: 1 << 2)
|
||||
static let privateChat = PeerSummaryCounterTags(rawValue: 1 << 3)
|
||||
static let secretChat = PeerSummaryCounterTags(rawValue: 1 << 4)
|
||||
static let privateGroup = PeerSummaryCounterTags(rawValue: 1 << 5)
|
||||
static let bot = PeerSummaryCounterTags(rawValue: 1 << 6)
|
||||
static let channel = PeerSummaryCounterTags(rawValue: 1 << 7)
|
||||
static let publicGroup = PeerSummaryCounterTags(rawValue: 1 << 8)
|
||||
}
|
||||
|
||||
struct Namespaces {
|
||||
@@ -17,4 +51,4 @@ struct Namespaces {
|
||||
static let CloudChannel: Int32 = 2
|
||||
static let SecretChat: Int32 = 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,19 +94,21 @@ enum SyncProviderImpl {
|
||||
if let channel = peerTable.get(peerId) as? TelegramChannel {
|
||||
switch channel.info {
|
||||
case .broadcast:
|
||||
tag = .channels
|
||||
tag = .channel
|
||||
case .group:
|
||||
if channel.username != nil {
|
||||
tag = .publicGroups
|
||||
tag = .publicGroup
|
||||
} else {
|
||||
tag = .regularChatsAndPrivateGroups
|
||||
tag = .privateGroup
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tag = .channels
|
||||
tag = .channel
|
||||
}
|
||||
} else if peerId.namespace == Namespaces.Peer.CloudGroup {
|
||||
tag = .privateGroup
|
||||
} else {
|
||||
tag = .regularChatsAndPrivateGroups
|
||||
tag = .privateChat
|
||||
}
|
||||
|
||||
var totalCount: Int32 = -1
|
||||
|
||||
Reference in New Issue
Block a user