This commit is contained in:
Ali
2020-03-11 16:13:03 +05:30
parent 773ed45e7b
commit 6f0598a7ab
27 changed files with 477 additions and 324 deletions

View File

@@ -374,11 +374,6 @@ public enum ChatListGlobalScrollOption {
case unread
}
private struct ChatListVisibleUnreadCounts: Equatable {
var raw: Int32 = 0
var filtered: Int32 = 0
}
public enum ChatListNodeScrollPosition {
case auto
case autoUp
@@ -478,15 +473,6 @@ public final class ChatListNode: ListView {
public var contentOffsetChanged: ((ListViewVisibleContentOffset) -> Void)?
public var contentScrollingEnded: ((ListView) -> Bool)?
private let visibleUnreadCounts = ValuePromise<ChatListVisibleUnreadCounts>(ChatListVisibleUnreadCounts())
private var visibleUnreadCountsValue = ChatListVisibleUnreadCounts() {
didSet {
if self.visibleUnreadCountsValue != oldValue {
self.visibleUnreadCounts.set(self.visibleUnreadCountsValue)
}
}
}
var isEmptyUpdated: ((ChatListNodeEmptyState, Bool, ContainedViewLayoutTransition) -> Void)?
private var currentIsEmptyState: ChatListNodeEmptyState?
@@ -900,8 +886,6 @@ public final class ChatListNode: ListView {
strongSelf.enqueueHistoryPreloadUpdate()
}
var rawUnreadCount: Int32 = 0
var filteredUnreadCount: Int32 = 0
var archiveVisible = false
if let range = range.visibleRange {
let entryCount = chatListView.filteredEntries.count
@@ -911,14 +895,8 @@ public final class ChatListNode: ListView {
continue
}
switch chatListView.filteredEntries[entryCount - i - 1] {
case let .PeerEntry(_, _, _, readState, notificationSettings, _, _, _, _, _, _, _, _, _, _, _):
if let readState = readState {
let count = readState.count
rawUnreadCount += count
if let notificationSettings = notificationSettings, !notificationSettings.isRemovedFromTotalUnreadCount {
filteredUnreadCount += count
}
}
case .PeerEntry:
break
case .GroupReferenceEntry:
archiveVisible = true
default:
@@ -926,10 +904,6 @@ public final class ChatListNode: ListView {
}
}
}
var visibleUnreadCountsValue = strongSelf.visibleUnreadCountsValue
visibleUnreadCountsValue.raw = rawUnreadCount
visibleUnreadCountsValue.filtered = filteredUnreadCount
strongSelf.visibleUnreadCountsValue = visibleUnreadCountsValue
if !archiveVisible && strongSelf.currentState.archiveShouldBeTemporaryRevealed {
strongSelf.updateState { state in
var state = state
@@ -1161,25 +1135,10 @@ public final class ChatListNode: ListView {
self.scrollToTopOptionPromise.set(combineLatest(
renderedTotalUnreadCount(accountManager: self.context.sharedContext.accountManager, postbox: self.context.account.postbox) |> deliverOnMainQueue,
self.visibleUnreadCounts.get(),
self.scrolledAtTop.get()
) |> map { badge, visibleUnreadCounts, scrolledAtTop -> ChatListGlobalScrollOption in
) |> map { badge, scrolledAtTop -> ChatListGlobalScrollOption in
if scrolledAtTop {
if badge.0 != 0 {
switch badge.1 {
case .raw:
if visibleUnreadCounts.raw < badge.0 {
return .unread
}
case .filtered:
if visibleUnreadCounts.filtered < badge.0 {
return .unread
}
}
return .none
} else {
return .none
}
return .none
} else {
return .top
}