[WIP] Topics

This commit is contained in:
Ali
2022-10-14 01:21:57 +04:00
parent c2d84dc649
commit ddf208edfb
36 changed files with 766 additions and 133 deletions

View File

@@ -59,7 +59,7 @@ public enum ChatListItemContent {
}
}
case peer(messages: [EngineMessage], peer: EngineRenderedPeer, threadInfo: ThreadInfo?, combinedReadState: EnginePeerReadCounters?, isRemovedFromTotalUnreadCount: Bool, presence: EnginePeer.Presence?, hasUnseenMentions: Bool, hasUnseenReactions: Bool, draftState: DraftState?, inputActivities: [(EnginePeer, PeerInputActivity)]?, promoInfo: ChatListNodeEntryPromoInfo?, ignoreUnreadBadge: Bool, displayAsMessage: Bool, hasFailedMessages: Bool, forumThreadTitle: String?)
case peer(messages: [EngineMessage], peer: EngineRenderedPeer, threadInfo: ThreadInfo?, combinedReadState: EnginePeerReadCounters?, isRemovedFromTotalUnreadCount: Bool, presence: EnginePeer.Presence?, hasUnseenMentions: Bool, hasUnseenReactions: Bool, draftState: DraftState?, inputActivities: [(EnginePeer, PeerInputActivity)]?, promoInfo: ChatListNodeEntryPromoInfo?, ignoreUnreadBadge: Bool, displayAsMessage: Bool, hasFailedMessages: Bool, forumTopicData: EngineChatList.ForumTopicData?)
case groupReference(groupId: EngineChatList.Group, peers: [EngineChatList.GroupItem.Item], message: EngineMessage?, unreadCount: Int, hiddenByDefault: Bool)
public var chatLocation: ChatLocation? {
@@ -1045,12 +1045,12 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
let displayAsMessage: Bool
let hasFailedMessages: Bool
var threadInfo: ChatListItemContent.ThreadInfo?
var forumThreadTitle: String?
var forumTopicData: EngineChatList.ForumTopicData?
var groupHiddenByDefault = false
switch item.content {
case let .peer(messagesValue, peerValue, threadInfoValue, combinedReadStateValue, isRemovedFromTotalUnreadCountValue, peerPresenceValue, hasUnseenMentionsValue, hasUnseenReactionsValue, draftStateValue, inputActivitiesValue, promoInfoValue, ignoreUnreadBadge, displayAsMessageValue, _, forumThreadTitleValue):
case let .peer(messagesValue, peerValue, threadInfoValue, combinedReadStateValue, isRemovedFromTotalUnreadCountValue, peerPresenceValue, hasUnseenMentionsValue, hasUnseenReactionsValue, draftStateValue, inputActivitiesValue, promoInfoValue, ignoreUnreadBadge, displayAsMessageValue, _, forumTopicDataValue):
messages = messagesValue
contentPeer = .chat(peerValue)
combinedReadState = combinedReadStateValue
@@ -1071,7 +1071,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
threadInfo = threadInfoValue
hasUnseenMentions = hasUnseenMentionsValue
hasUnseenReactions = hasUnseenReactionsValue
forumThreadTitle = forumThreadTitleValue
forumTopicData = forumTopicDataValue
switch peerValue.peer {
case .user, .secretChat:
@@ -1272,8 +1272,8 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
}
if let peerTextValue = peerText, case let .channel(channel) = itemPeer.chatMainPeer, channel.flags.contains(.isForum), threadInfo == nil {
if let forumThreadTitle = forumThreadTitle {
peerText = "\(peerTextValue)\(forumThreadTitle)"
if let forumTopicData = forumTopicData {
peerText = "\(peerTextValue)\(forumTopicData.title)"
} else {
//TODO:localize
peerText = "\(peerTextValue) → General"
@@ -1547,6 +1547,12 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
} else {
statusState = .delivered(item.presentationData.theme.chatList.checkmarkColor)
}
} else if case .forum = item.chatListLocation {
if let forumTopicData = forumTopicData, message.id.namespace == forumTopicData.maxOutgoingReadMessageId.namespace, message.id.id >= forumTopicData.maxOutgoingReadMessageId.id {
statusState = .read(item.presentationData.theme.chatList.checkmarkColor)
} else {
statusState = .delivered(item.presentationData.theme.chatList.checkmarkColor)
}
}
}
}
@@ -2690,6 +2696,10 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
case RevealOptionKey.unmute.rawValue:
item.interaction.setPeerThreadMuted(peerId, threadId, false)
close = false
case RevealOptionKey.close.rawValue:
item.interaction.setPeerThreadStopped(peerId, threadId, true)
case RevealOptionKey.open.rawValue:
item.interaction.setPeerThreadStopped(peerId, threadId, false)
default:
break
}

View File

@@ -70,6 +70,7 @@ public final class ChatListNodeInteraction {
let setPeerThreadMuted: (EnginePeer.Id, Int64?, Bool) -> Void
let deletePeer: (EnginePeer.Id, Bool) -> Void
let deletePeerThread: (EnginePeer.Id, Int64) -> Void
let setPeerThreadStopped: (EnginePeer.Id, Int64, Bool) -> Void
let updatePeerGrouping: (EnginePeer.Id, Bool) -> Void
let togglePeerMarkedUnread: (EnginePeer.Id, Bool) -> Void
let toggleArchivedFolderHiddenByDefault: () -> Void
@@ -102,6 +103,7 @@ public final class ChatListNodeInteraction {
setPeerThreadMuted: @escaping (EnginePeer.Id, Int64?, Bool) -> Void,
deletePeer: @escaping (EnginePeer.Id, Bool) -> Void,
deletePeerThread: @escaping (EnginePeer.Id, Int64) -> Void,
setPeerThreadStopped: @escaping (EnginePeer.Id, Int64, Bool) -> Void,
updatePeerGrouping: @escaping (EnginePeer.Id, Bool) -> Void,
togglePeerMarkedUnread: @escaping (EnginePeer.Id, Bool) -> Void,
toggleArchivedFolderHiddenByDefault: @escaping () -> Void,
@@ -124,6 +126,7 @@ public final class ChatListNodeInteraction {
self.setPeerThreadMuted = setPeerThreadMuted
self.deletePeer = deletePeer
self.deletePeerThread = deletePeerThread
self.setPeerThreadStopped = setPeerThreadStopped
self.updatePeerGrouping = updatePeerGrouping
self.togglePeerMarkedUnread = togglePeerMarkedUnread
self.toggleArchivedFolderHiddenByDefault = toggleArchivedFolderHiddenByDefault
@@ -248,7 +251,7 @@ private func mappedInsertEntries(context: AccountContext, nodeInteraction: ChatL
nodeInteraction.additionalCategorySelected(id)
}
), directionHint: entry.directionHint)
case let .PeerEntry(index, presentationData, messages, combinedReadState, isRemovedFromTotalUnreadCount, draftState, peer, threadInfo, presence, hasUnseenMentions, hasUnseenReactions, editing, hasActiveRevealControls, selected, inputActivities, promoInfo, hasFailedMessages, isContact, forumThreadTitle):
case let .PeerEntry(index, presentationData, messages, combinedReadState, isRemovedFromTotalUnreadCount, draftState, peer, threadInfo, presence, hasUnseenMentions, hasUnseenReactions, editing, hasActiveRevealControls, selected, inputActivities, promoInfo, hasFailedMessages, isContact, forumTopicData):
switch mode {
case .chatList:
return ListViewInsertItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListItem(
@@ -272,7 +275,7 @@ private func mappedInsertEntries(context: AccountContext, nodeInteraction: ChatL
ignoreUnreadBadge: false,
displayAsMessage: false,
hasFailedMessages: hasFailedMessages,
forumThreadTitle: forumThreadTitle
forumTopicData: forumTopicData
),
editing: editing,
hasActiveRevealControls: hasActiveRevealControls,
@@ -439,7 +442,7 @@ private func mappedInsertEntries(context: AccountContext, nodeInteraction: ChatL
private func mappedUpdateEntries(context: AccountContext, nodeInteraction: ChatListNodeInteraction, location: ChatListControllerLocation, filterData: ChatListItemFilterData?, mode: ChatListNodeMode, entries: [ChatListNodeViewTransitionUpdateEntry]) -> [ListViewUpdateItem] {
return entries.map { entry -> ListViewUpdateItem in
switch entry.entry {
case let .PeerEntry(index, presentationData, messages, combinedReadState, isRemovedFromTotalUnreadCount, draftState, peer, threadInfo, presence, hasUnseenMentions, hasUnseenReactions, editing, hasActiveRevealControls, selected, inputActivities, promoInfo, hasFailedMessages, isContact, forumThreadTitle):
case let .PeerEntry(index, presentationData, messages, combinedReadState, isRemovedFromTotalUnreadCount, draftState, peer, threadInfo, presence, hasUnseenMentions, hasUnseenReactions, editing, hasActiveRevealControls, selected, inputActivities, promoInfo, hasFailedMessages, isContact, forumTopicData):
switch mode {
case .chatList:
return ListViewUpdateItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListItem(
@@ -463,7 +466,7 @@ private func mappedUpdateEntries(context: AccountContext, nodeInteraction: ChatL
ignoreUnreadBadge: false,
displayAsMessage: false,
hasFailedMessages: hasFailedMessages,
forumThreadTitle: forumThreadTitle
forumTopicData: forumTopicData
),
editing: editing,
hasActiveRevealControls: hasActiveRevealControls,
@@ -662,6 +665,7 @@ public final class ChatListNode: ListView {
public var activateSearch: (() -> Void)?
public var deletePeerChat: ((EnginePeer.Id, Bool) -> Void)?
public var deletePeerThread: ((EnginePeer.Id, Int64) -> Void)?
public var setPeerThreadStopped: ((EnginePeer.Id, Int64, Bool) -> Void)?
public var updatePeerGrouping: ((EnginePeer.Id, Bool) -> Void)?
public var presentAlert: ((String) -> Void)?
public var present: ((ViewController) -> Void)?
@@ -973,6 +977,8 @@ public final class ChatListNode: ListView {
self?.deletePeerChat?(peerId, joined)
}, deletePeerThread: { [weak self] peerId, threadId in
self?.deletePeerThread?(peerId, threadId)
}, setPeerThreadStopped: { [weak self] peerId, threadId, isStopped in
self?.setPeerThreadStopped?(peerId, threadId, isStopped)
}, updatePeerGrouping: { [weak self] peerId, group in
self?.updatePeerGrouping?(peerId, group)
}, togglePeerMarkedUnread: { [weak self, weak context] peerId, animated in

View File

@@ -66,7 +66,7 @@ enum ChatListNodeEntry: Comparable, Identifiable {
promoInfo: ChatListNodeEntryPromoInfo?,
hasFailedMessages: Bool,
isContact: Bool,
forumThreadTitle: String?
forumTopicData: EngineChatList.ForumTopicData?
)
case HoleEntry(EngineMessage.Index, theme: PresentationTheme)
case GroupReferenceEntry(index: EngineChatList.Item.Index, presentationData: ChatListPresentationData, groupId: EngineChatList.Group, peers: [EngineChatList.GroupItem.Item], message: EngineMessage?, editing: Bool, unreadCount: Int, revealed: Bool, hiddenByDefault: Bool)
@@ -386,7 +386,7 @@ func chatListNodeEntriesForView(_ view: EngineChatList, state: ChatListNodeState
break
}
result.append(.PeerEntry(index: offsetPinnedIndex(entry.index, offset: pinnedIndexOffset), presentationData: state.presentationData, messages: updatedMessages, readState: updatedCombinedReadState, isRemovedFromTotalUnreadCount: entry.isMuted, draftState: draftState, peer: entry.renderedPeer, threadInfo: entry.threadInfo.flatMap { ChatListItemContent.ThreadInfo(id: threadId, info: $0) }, presence: entry.presence, hasUnseenMentions: entry.hasUnseenMentions, hasUnseenReactions: entry.hasUnseenReactions, editing: state.editing, hasActiveRevealControls: hasActiveRevealControls, selected: isSelected, inputActivities: inputActivities, promoInfo: nil, hasFailedMessages: entry.hasFailed, isContact: entry.isContact, forumThreadTitle: entry.forumTopicTitle))
result.append(.PeerEntry(index: offsetPinnedIndex(entry.index, offset: pinnedIndexOffset), presentationData: state.presentationData, messages: updatedMessages, readState: updatedCombinedReadState, isRemovedFromTotalUnreadCount: entry.isMuted, draftState: draftState, peer: entry.renderedPeer, threadInfo: entry.threadInfo.flatMap { ChatListItemContent.ThreadInfo(id: threadId, info: $0) }, presence: entry.presence, hasUnseenMentions: entry.hasUnseenMentions, hasUnseenReactions: entry.hasUnseenReactions, editing: state.editing, hasActiveRevealControls: hasActiveRevealControls, selected: isSelected, inputActivities: inputActivities, promoInfo: nil, hasFailedMessages: entry.hasFailed, isContact: entry.isContact, forumTopicData: entry.forumTopicData))
}
if !view.hasLater {
var pinningIndex: UInt16 = UInt16(pinnedIndexOffset == 0 ? 0 : (pinnedIndexOffset - 1))
@@ -420,7 +420,7 @@ func chatListNodeEntriesForView(_ view: EngineChatList, state: ChatListNodeState
promoInfo: nil,
hasFailedMessages: false,
isContact: false,
forumThreadTitle: nil
forumTopicData: nil
))
if foundPinningIndex != 0 {
foundPinningIndex -= 1
@@ -428,7 +428,7 @@ func chatListNodeEntriesForView(_ view: EngineChatList, state: ChatListNodeState
}
}
result.append(.PeerEntry(index: .chatList(EngineChatList.Item.Index.ChatList.absoluteUpperBound.predecessor), presentationData: state.presentationData, messages: [], readState: nil, isRemovedFromTotalUnreadCount: false, draftState: nil, peer: EngineRenderedPeer(peerId: savedMessagesPeer.id, peers: [savedMessagesPeer.id: savedMessagesPeer], associatedMedia: [:]), threadInfo: nil, presence: nil, hasUnseenMentions: false, hasUnseenReactions: false, editing: state.editing, hasActiveRevealControls: false, selected: state.selectedPeerIds.contains(savedMessagesPeer.id), inputActivities: nil, promoInfo: nil, hasFailedMessages: false, isContact: false, forumThreadTitle: nil))
result.append(.PeerEntry(index: .chatList(EngineChatList.Item.Index.ChatList.absoluteUpperBound.predecessor), presentationData: state.presentationData, messages: [], readState: nil, isRemovedFromTotalUnreadCount: false, draftState: nil, peer: EngineRenderedPeer(peerId: savedMessagesPeer.id, peers: [savedMessagesPeer.id: savedMessagesPeer], associatedMedia: [:]), threadInfo: nil, presence: nil, hasUnseenMentions: false, hasUnseenReactions: false, editing: state.editing, hasActiveRevealControls: false, selected: state.selectedPeerIds.contains(savedMessagesPeer.id), inputActivities: nil, promoInfo: nil, hasFailedMessages: false, isContact: false, forumTopicData: nil))
} else {
if !filteredAdditionalItemEntries.isEmpty {
for item in filteredAdditionalItemEntries.reversed() {
@@ -475,7 +475,7 @@ func chatListNodeEntriesForView(_ view: EngineChatList, state: ChatListNodeState
promoInfo: promoInfo,
hasFailedMessages: item.item.hasFailed,
isContact: item.item.isContact,
forumThreadTitle: item.item.forumTopicTitle
forumTopicData: item.item.forumTopicData
))
if pinningIndex != 0 {
pinningIndex -= 1

View File

@@ -237,7 +237,7 @@ func chatListViewForLocation(chatListLocation: ChatListControllerLocation, locat
presence: nil,
hasUnseenMentions: hasUnseenMentions,
hasUnseenReactions: hasUnseenReactions,
forumTopicTitle: nil,
forumTopicData: nil,
hasFailed: false,
isContact: false
))