Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Mikhail Filimonov
2024-01-29 09:15:35 +04:00
79 changed files with 1705 additions and 687 deletions

View File

@@ -18,6 +18,14 @@ public enum EnginePeerCachedInfoItem<T> {
}
}
public struct EngineDisplaySavedChatsAsTopics: Codable, Equatable {
public var value: Bool
public init(value: Bool) {
self.value = value
}
}
extension EnginePeerCachedInfoItem: Equatable where T: Equatable {
public static func ==(lhs: EnginePeerCachedInfoItem<T>, rhs: EnginePeerCachedInfoItem<T>) -> Bool {
switch lhs {
@@ -1245,5 +1253,28 @@ public extension TelegramEngine.EngineData.Item {
}
}
public struct DisplaySavedChatsAsTopics: TelegramEngineDataItem, PostboxViewDataItem {
public typealias Result = Bool
public init() {
}
var key: PostboxViewKey {
return .preferences(keys: Set([PreferencesKeys.displaySavedChatsAsTopics()]))
}
func extract(view: PostboxView) -> Result {
guard let view = view as? PreferencesView else {
preconditionFailure()
}
if let value = view.values[PreferencesKeys.displaySavedChatsAsTopics()]?.get(EngineDisplaySavedChatsAsTopics.self) {
return value.value
} else {
return false
}
}
}
}
}

View File

@@ -129,6 +129,7 @@ public final class EngineChatList: Equatable {
public let isContact: Bool
public let autoremoveTimeout: Int32?
public let storyStats: StoryStats?
public let displayAsTopicList: Bool
public init(
id: Id,
@@ -147,7 +148,8 @@ public final class EngineChatList: Equatable {
hasFailed: Bool,
isContact: Bool,
autoremoveTimeout: Int32?,
storyStats: StoryStats?
storyStats: StoryStats?,
displayAsTopicList: Bool
) {
self.id = id
self.index = index
@@ -166,6 +168,7 @@ public final class EngineChatList: Equatable {
self.isContact = isContact
self.autoremoveTimeout = autoremoveTimeout
self.storyStats = storyStats
self.displayAsTopicList = displayAsTopicList
}
public static func ==(lhs: Item, rhs: Item) -> Bool {
@@ -220,6 +223,9 @@ public final class EngineChatList: Equatable {
if lhs.storyStats != rhs.storyStats {
return false
}
if lhs.displayAsTopicList != rhs.displayAsTopicList {
return false
}
return true
}
}
@@ -419,7 +425,7 @@ public extension EngineChatList.RelativePosition {
}
extension EngineChatList.Item {
convenience init?(_ entry: ChatListEntry) {
convenience init?(_ entry: ChatListEntry, displayAsTopicList: Bool) {
switch entry {
case let .MessageEntry(entryData):
let index = entryData.index
@@ -504,7 +510,8 @@ extension EngineChatList.Item {
hasFailed: hasFailed,
isContact: isContact,
autoremoveTimeout: autoremoveTimeout,
storyStats: entryData.storyStats
storyStats: entryData.storyStats,
displayAsTopicList: displayAsTopicList
)
case .HoleEntry:
return nil
@@ -544,7 +551,7 @@ extension EngineChatList.AdditionalItem.PromoInfo {
extension EngineChatList.AdditionalItem {
convenience init?(_ entry: ChatListAdditionalItemEntry) {
guard let item = EngineChatList.Item(entry.entry) else {
guard let item = EngineChatList.Item(entry.entry, displayAsTopicList: false) else {
return nil
}
guard let promoInfo = (entry.info as? PromoChatListItem).flatMap(EngineChatList.AdditionalItem.PromoInfo.init) else {
@@ -555,14 +562,19 @@ extension EngineChatList.AdditionalItem {
}
public extension EngineChatList {
convenience init(_ view: ChatListView) {
convenience init(_ view: ChatListView, accountPeerId: PeerId) {
var isLoading = false
var displaySavedMessagesAsTopicList = false
if let value = view.displaySavedMessagesAsTopicList?.get(EngineDisplaySavedChatsAsTopics.self) {
displaySavedMessagesAsTopicList = value.value
}
var items: [EngineChatList.Item] = []
loop: for entry in view.entries {
switch entry {
case .MessageEntry:
if let item = EngineChatList.Item(entry) {
if let item = EngineChatList.Item(entry, displayAsTopicList: entry.index.messageIndex.id.peerId == accountPeerId ? displaySavedMessagesAsTopicList : false) {
items.append(item)
}
case .HoleEntry:

View File

@@ -328,9 +328,10 @@ public extension TelegramEngine {
}
public func chatList(group: EngineChatList.Group, count: Int) -> Signal<EngineChatList, NoError> {
let accountPeerId = self.account.peerId
return self.account.postbox.tailChatListView(groupId: group._asGroup(), count: count, summaryComponents: ChatListEntrySummaryComponents())
|> map { view -> EngineChatList in
return EngineChatList(view.0)
return EngineChatList(view.0, accountPeerId: accountPeerId)
}
}

View File

@@ -1346,6 +1346,14 @@ public extension TelegramEngine {
|> distinctUntilChanged
}
}
public func updateSavedMessagesViewAsTopics(value: Bool) {
let _ = (self.account.postbox.transaction { transaction -> Void in
transaction.updatePreferencesEntry(key: PreferencesKeys.displaySavedChatsAsTopics(), { _ in
return PreferencesEntry(EngineDisplaySavedChatsAsTopics(value: value))
})
}).start()
}
}
}