mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Various improvements
This commit is contained in:
@@ -130,6 +130,7 @@ public final class EngineChatList: Equatable {
|
||||
public let autoremoveTimeout: Int32?
|
||||
public let storyStats: StoryStats?
|
||||
public let displayAsTopicList: Bool
|
||||
public let isPremiumRequiredToMessage: Bool
|
||||
|
||||
public init(
|
||||
id: Id,
|
||||
@@ -149,7 +150,8 @@ public final class EngineChatList: Equatable {
|
||||
isContact: Bool,
|
||||
autoremoveTimeout: Int32?,
|
||||
storyStats: StoryStats?,
|
||||
displayAsTopicList: Bool
|
||||
displayAsTopicList: Bool,
|
||||
isPremiumRequiredToMessage: Bool
|
||||
) {
|
||||
self.id = id
|
||||
self.index = index
|
||||
@@ -169,6 +171,7 @@ public final class EngineChatList: Equatable {
|
||||
self.autoremoveTimeout = autoremoveTimeout
|
||||
self.storyStats = storyStats
|
||||
self.displayAsTopicList = displayAsTopicList
|
||||
self.isPremiumRequiredToMessage = isPremiumRequiredToMessage
|
||||
}
|
||||
|
||||
public static func ==(lhs: Item, rhs: Item) -> Bool {
|
||||
@@ -226,6 +229,9 @@ public final class EngineChatList: Equatable {
|
||||
if lhs.displayAsTopicList != rhs.displayAsTopicList {
|
||||
return false
|
||||
}
|
||||
if lhs.isPremiumRequiredToMessage != rhs.isPremiumRequiredToMessage {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -424,8 +430,21 @@ public extension EngineChatList.RelativePosition {
|
||||
}
|
||||
}
|
||||
|
||||
private func calculateIsPremiumRequiredToMessage(isPremium: Bool, targetPeer: Peer, cachedIsPremiumRequired: Bool) -> Bool {
|
||||
if isPremium {
|
||||
return false
|
||||
}
|
||||
guard let targetPeer = targetPeer as? TelegramUser else {
|
||||
return false
|
||||
}
|
||||
if !targetPeer.flags.contains(.requirePremium) {
|
||||
return false
|
||||
}
|
||||
return cachedIsPremiumRequired
|
||||
}
|
||||
|
||||
extension EngineChatList.Item {
|
||||
convenience init?(_ entry: ChatListEntry, displayAsTopicList: Bool) {
|
||||
convenience init?(_ entry: ChatListEntry, isPremium: Bool, displayAsTopicList: Bool) {
|
||||
switch entry {
|
||||
case let .MessageEntry(entryData):
|
||||
let index = entryData.index
|
||||
@@ -442,6 +461,11 @@ extension EngineChatList.Item {
|
||||
let isContact = entryData.isContact
|
||||
let autoremoveTimeout = entryData.autoremoveTimeout
|
||||
|
||||
var isPremiumRequiredToMessage = false
|
||||
if let targetPeer = renderedPeer.chatMainPeer, let extractedData = entryData.extractedCachedData?.base as? ExtractedChatListItemCachedData {
|
||||
isPremiumRequiredToMessage = calculateIsPremiumRequiredToMessage(isPremium: isPremium, targetPeer: targetPeer, cachedIsPremiumRequired: extractedData.isPremiumRequiredToMessage)
|
||||
}
|
||||
|
||||
var draft: EngineChatList.Draft?
|
||||
if let embeddedState = embeddedState, let _ = embeddedState.overrideChatTimestamp {
|
||||
if let opaqueState = _internal_decodeStoredChatInterfaceState(state: embeddedState) {
|
||||
@@ -511,7 +535,8 @@ extension EngineChatList.Item {
|
||||
isContact: isContact,
|
||||
autoremoveTimeout: autoremoveTimeout,
|
||||
storyStats: entryData.storyStats,
|
||||
displayAsTopicList: displayAsTopicList
|
||||
displayAsTopicList: displayAsTopicList,
|
||||
isPremiumRequiredToMessage: isPremiumRequiredToMessage
|
||||
)
|
||||
case .HoleEntry:
|
||||
return nil
|
||||
@@ -551,7 +576,7 @@ extension EngineChatList.AdditionalItem.PromoInfo {
|
||||
|
||||
extension EngineChatList.AdditionalItem {
|
||||
convenience init?(_ entry: ChatListAdditionalItemEntry) {
|
||||
guard let item = EngineChatList.Item(entry.entry, displayAsTopicList: false) else {
|
||||
guard let item = EngineChatList.Item(entry.entry, isPremium: false, displayAsTopicList: false) else {
|
||||
return nil
|
||||
}
|
||||
guard let promoInfo = (entry.info as? PromoChatListItem).flatMap(EngineChatList.AdditionalItem.PromoInfo.init) else {
|
||||
@@ -569,12 +594,14 @@ public extension EngineChatList {
|
||||
if let value = view.displaySavedMessagesAsTopicList?.get(EngineDisplaySavedChatsAsTopics.self) {
|
||||
displaySavedMessagesAsTopicList = value.value
|
||||
}
|
||||
|
||||
let isPremium = view.accountPeer?.isPremium ?? false
|
||||
|
||||
var items: [EngineChatList.Item] = []
|
||||
loop: for entry in view.entries {
|
||||
switch entry {
|
||||
case .MessageEntry:
|
||||
if let item = EngineChatList.Item(entry, displayAsTopicList: entry.index.messageIndex.id.peerId == accountPeerId ? displaySavedMessagesAsTopicList : false) {
|
||||
if let item = EngineChatList.Item(entry, isPremium: isPremium, displayAsTopicList: entry.index.messageIndex.id.peerId == accountPeerId ? displaySavedMessagesAsTopicList : false) {
|
||||
items.append(item)
|
||||
}
|
||||
case .HoleEntry:
|
||||
|
||||
Reference in New Issue
Block a user