mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import AsyncDisplayKit
|
||||
import Postbox
|
||||
import Display
|
||||
import SwiftSignalKit
|
||||
import TelegramCore
|
||||
@@ -20,8 +19,23 @@ import ContextUI
|
||||
import ChatInterfaceState
|
||||
|
||||
public enum ChatListItemContent {
|
||||
case peer(messages: [Message], peer: RenderedPeer, combinedReadState: CombinedPeerReadState?, isRemovedFromTotalUnreadCount: Bool, presence: PeerPresence?, summaryInfo: ChatListMessageTagSummaryInfo, embeddedState: StoredPeerChatInterfaceState?, inputActivities: [(Peer, PeerInputActivity)]?, promoInfo: ChatListNodeEntryPromoInfo?, ignoreUnreadBadge: Bool, displayAsMessage: Bool, hasFailedMessages: Bool)
|
||||
case groupReference(groupId: PeerGroupId, peers: [ChatListGroupReferencePeer], message: Message?, unreadState: PeerGroupUnreadCountersCombinedSummary, hiddenByDefault: Bool)
|
||||
public final class DraftState: Equatable {
|
||||
let text: String
|
||||
|
||||
public init(text: String) {
|
||||
self.text = text
|
||||
}
|
||||
|
||||
public static func ==(lhs: DraftState, rhs: DraftState) -> Bool {
|
||||
if lhs.text != rhs.text {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
case peer(messages: [EngineMessage], peer: EngineRenderedPeer, combinedReadState: EnginePeerReadCounters?, isRemovedFromTotalUnreadCount: Bool, presence: EnginePeer.Presence?, hasUnseenMentions: Bool, draftState: DraftState?, inputActivities: [(EnginePeer, PeerInputActivity)]?, promoInfo: ChatListNodeEntryPromoInfo?, ignoreUnreadBadge: Bool, displayAsMessage: Bool, hasFailedMessages: Bool)
|
||||
case groupReference(groupId: EngineChatList.Group, peers: [EngineChatList.GroupItem.Item], message: EngineMessage?, unreadCount: Int, hiddenByDefault: Bool)
|
||||
|
||||
public var chatLocation: ChatLocation? {
|
||||
switch self {
|
||||
@@ -36,9 +50,9 @@ public enum ChatListItemContent {
|
||||
public class ChatListItem: ListViewItem, ChatListSearchItemNeighbour {
|
||||
let presentationData: ChatListPresentationData
|
||||
let context: AccountContext
|
||||
let peerGroupId: PeerGroupId
|
||||
let peerGroupId: EngineChatList.Group
|
||||
let filterData: ChatListItemFilterData?
|
||||
let index: ChatListIndex
|
||||
let index: EngineChatList.Item.Index
|
||||
public let content: ChatListItemContent
|
||||
let editing: Bool
|
||||
let hasActiveRevealControls: Bool
|
||||
@@ -59,7 +73,7 @@ public class ChatListItem: ListViewItem, ChatListSearchItemNeighbour {
|
||||
return self.index.pinningIndex != nil
|
||||
}
|
||||
|
||||
public init(presentationData: ChatListPresentationData, context: AccountContext, peerGroupId: PeerGroupId, filterData: ChatListItemFilterData?, index: ChatListIndex, content: ChatListItemContent, editing: Bool, hasActiveRevealControls: Bool, selected: Bool, header: ListViewItemHeader?, enableContextActions: Bool, hiddenOffset: Bool, interaction: ChatListNodeInteraction) {
|
||||
public init(presentationData: ChatListPresentationData, context: AccountContext, peerGroupId: EngineChatList.Group, filterData: ChatListItemFilterData?, index: EngineChatList.Item.Index, content: ChatListItemContent, editing: Bool, hasActiveRevealControls: Bool, selected: Bool, header: ListViewItemHeader?, enableContextActions: Bool, hiddenOffset: Bool, interaction: ChatListNodeInteraction) {
|
||||
self.presentationData = presentationData
|
||||
self.peerGroupId = peerGroupId
|
||||
self.filterData = filterData
|
||||
@@ -195,7 +209,7 @@ private enum RevealOptionKey: Int32 {
|
||||
case hidePsa
|
||||
}
|
||||
|
||||
private func canArchivePeer(id: PeerId, accountPeerId: PeerId) -> Bool {
|
||||
private func canArchivePeer(id: EnginePeer.Id, accountPeerId: EnginePeer.Id) -> Bool {
|
||||
if id.namespace == Namespaces.Peer.CloudUser && id.id._internalGetInt64Value() == 777000 {
|
||||
return false
|
||||
}
|
||||
@@ -213,10 +227,10 @@ public struct ChatListItemFilterData: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
private func revealOptions(strings: PresentationStrings, theme: PresentationTheme, isPinned: Bool, isMuted: Bool?, groupId: PeerGroupId, peerId: PeerId, accountPeerId: PeerId, canDelete: Bool, isEditing: Bool, filterData: ChatListItemFilterData?) -> [ItemListRevealOption] {
|
||||
private func revealOptions(strings: PresentationStrings, theme: PresentationTheme, isPinned: Bool, isMuted: Bool?, groupId: EngineChatList.Group, peerId: EnginePeer.Id, accountPeerId: EnginePeer.Id, canDelete: Bool, isEditing: Bool, filterData: ChatListItemFilterData?) -> [ItemListRevealOption] {
|
||||
var options: [ItemListRevealOption] = []
|
||||
if !isEditing {
|
||||
if case .group = groupId {
|
||||
if case .archive = groupId {
|
||||
if isPinned {
|
||||
options.append(ItemListRevealOption(key: RevealOptionKey.unpin.rawValue, title: strings.DialogList_Unpin, icon: unpinIcon, color: theme.list.itemDisclosureActions.constructive.fillColor, textColor: theme.list.itemDisclosureActions.constructive.foregroundColor))
|
||||
} else {
|
||||
@@ -272,8 +286,8 @@ private func groupReferenceRevealOptions(strings: PresentationStrings, theme: Pr
|
||||
return options
|
||||
}
|
||||
|
||||
private func leftRevealOptions(strings: PresentationStrings, theme: PresentationTheme, isUnread: Bool, isEditing: Bool, isPinned: Bool, isSavedMessages: Bool, groupId: PeerGroupId, peer: Peer, filterData: ChatListItemFilterData?) -> [ItemListRevealOption] {
|
||||
if case .group = groupId {
|
||||
private func leftRevealOptions(strings: PresentationStrings, theme: PresentationTheme, isUnread: Bool, isEditing: Bool, isPinned: Bool, isSavedMessages: Bool, groupId: EngineChatList.Group, peer: EnginePeer, filterData: ChatListItemFilterData?) -> [ItemListRevealOption] {
|
||||
if case .archive = groupId {
|
||||
return []
|
||||
}
|
||||
var options: [ItemListRevealOption] = []
|
||||
@@ -332,8 +346,8 @@ private let playIconImage = UIImage(bundleImageName: "Chat List/MiniThumbnailPla
|
||||
|
||||
private final class ChatListMediaPreviewNode: ASDisplayNode {
|
||||
private let context: AccountContext
|
||||
private let message: Message
|
||||
private let media: Media
|
||||
private let message: EngineMessage
|
||||
private let media: EngineMedia
|
||||
|
||||
private let imageNode: TransformImageNode
|
||||
private let playIcon: ASImageNode
|
||||
@@ -341,7 +355,7 @@ private final class ChatListMediaPreviewNode: ASDisplayNode {
|
||||
private var requestedImage: Bool = false
|
||||
private var disposable: Disposable?
|
||||
|
||||
init(context: AccountContext, message: Message, media: Media) {
|
||||
init(context: AccountContext, message: EngineMessage, media: EngineMedia) {
|
||||
self.context = context
|
||||
self.message = message
|
||||
self.media = media
|
||||
@@ -366,17 +380,17 @@ private final class ChatListMediaPreviewNode: ASDisplayNode {
|
||||
}
|
||||
|
||||
var dimensions = CGSize(width: 100.0, height: 100.0)
|
||||
if let image = self.media as? TelegramMediaImage {
|
||||
if case let .image(image) = self.media {
|
||||
self.playIcon.isHidden = true
|
||||
if let largest = largestImageRepresentation(image.representations) {
|
||||
dimensions = largest.dimensions.cgSize
|
||||
if !self.requestedImage {
|
||||
self.requestedImage = true
|
||||
let signal = mediaGridMessagePhoto(account: self.context.account, photoReference: .message(message: MessageReference(self.message), media: image), fullRepresentationSize: CGSize(width: 36.0, height: 36.0), synchronousLoad: synchronousLoads)
|
||||
let signal = mediaGridMessagePhoto(account: self.context.account, photoReference: .message(message: MessageReference(self.message._asMessage()), media: image), fullRepresentationSize: CGSize(width: 36.0, height: 36.0), synchronousLoad: synchronousLoads)
|
||||
self.imageNode.setSignal(signal, attemptSynchronously: synchronousLoads)
|
||||
}
|
||||
}
|
||||
} else if let file = self.media as? TelegramMediaFile {
|
||||
} else if case let .file(file) = self.media {
|
||||
if file.isAnimated {
|
||||
self.playIcon.isHidden = true
|
||||
} else {
|
||||
@@ -386,7 +400,7 @@ private final class ChatListMediaPreviewNode: ASDisplayNode {
|
||||
dimensions = mediaDimensions.cgSize
|
||||
if !self.requestedImage {
|
||||
self.requestedImage = true
|
||||
let signal = mediaGridMessageVideo(postbox: self.context.account.postbox, videoReference: .message(message: MessageReference(self.message), media: file), synchronousLoad: synchronousLoads, autoFetchFullSizeThumbnail: true, useMiniThumbnailIfAvailable: true)
|
||||
let signal = mediaGridMessageVideo(postbox: self.context.account.postbox, videoReference: .message(message: MessageReference(self.message._asMessage()), media: file), synchronousLoad: synchronousLoads, autoFetchFullSizeThumbnail: true, useMiniThumbnailIfAvailable: true)
|
||||
self.imageNode.setSignal(signal, attemptSynchronously: synchronousLoads)
|
||||
}
|
||||
}
|
||||
@@ -426,8 +440,8 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
let mutedIconNode: ASImageNode
|
||||
|
||||
private var currentTextLeftCutout: CGFloat = 0.0
|
||||
private var currentMediaPreviewSpecs: [(message: Message, media: Media, size: CGSize)] = []
|
||||
private var mediaPreviewNodes: [MediaId: ChatListMediaPreviewNode] = [:]
|
||||
private var currentMediaPreviewSpecs: [(message: EngineMessage, media: EngineMedia, size: CGSize)] = []
|
||||
private var mediaPreviewNodes: [EngineMedia.Id: ChatListMediaPreviewNode] = [:]
|
||||
|
||||
var selectableControlNode: ItemListSelectableControlNode?
|
||||
var reorderControlNode: ItemListEditableReorderControlNode?
|
||||
@@ -477,11 +491,11 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
return nil
|
||||
}
|
||||
switch item.content {
|
||||
case let .groupReference(_, _, _, unreadState, _):
|
||||
case let .groupReference(_, _, _, unreadCount, _):
|
||||
var result = item.presentationData.strings.ChatList_ArchivedChatsTitle
|
||||
let allCount = unreadState.count(countingCategory: .chats, mutedCategory: .all)
|
||||
let allCount = unreadCount
|
||||
if allCount > 0 {
|
||||
result += "\n\(item.presentationData.strings.VoiceOver_Chat_UnreadMessages(allCount))"
|
||||
result += "\n\(item.presentationData.strings.VoiceOver_Chat_UnreadMessages(Int32(allCount)))"
|
||||
}
|
||||
return result
|
||||
case let .peer(_, peer, combinedReadState, _, _, _, _, _, _, _, _, _):
|
||||
@@ -519,7 +533,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
result += item.presentationData.strings.VoiceOver_ChatList_OutgoingMessage
|
||||
}
|
||||
let (_, initialHideAuthor, messageText) = chatListItemStrings(strings: item.presentationData.strings, nameDisplayOrder: item.presentationData.nameDisplayOrder, dateTimeFormat: item.presentationData.dateTimeFormat, messages: messages, chatPeer: peer, accountPeerId: item.context.account.peerId, isPeerGroup: false)
|
||||
if message.flags.contains(.Incoming), !initialHideAuthor, let author = message.author, author is TelegramUser {
|
||||
if message.flags.contains(.Incoming), !initialHideAuthor, let author = message.author, case .user = author {
|
||||
result += "\n\(item.presentationData.strings.VoiceOver_ChatList_MessageFrom(author.displayTitle(strings: item.presentationData.strings, displayOrder: item.presentationData.nameDisplayOrder)).string)"
|
||||
}
|
||||
result += "\n\(messageText)"
|
||||
@@ -553,7 +567,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
result += item.presentationData.strings.VoiceOver_ChatList_OutgoingMessage
|
||||
}
|
||||
let (_, initialHideAuthor, messageText) = chatListItemStrings(strings: item.presentationData.strings, nameDisplayOrder: item.presentationData.nameDisplayOrder, dateTimeFormat: item.presentationData.dateTimeFormat, messages: messages, chatPeer: peer, accountPeerId: item.context.account.peerId, isPeerGroup: false)
|
||||
if message.flags.contains(.Incoming), !initialHideAuthor, let author = message.author, author is TelegramUser {
|
||||
if message.flags.contains(.Incoming), !initialHideAuthor, let author = message.author, case .user = author {
|
||||
result += "\n\(item.presentationData.strings.VoiceOver_ChatList_MessageFrom(author.displayTitle(strings: item.presentationData.strings, displayOrder: item.presentationData.nameDisplayOrder)).string)"
|
||||
}
|
||||
if !message.flags.contains(.Incoming), let combinedReadState = combinedReadState, combinedReadState.isOutgoingMessageIndexRead(message.index) {
|
||||
@@ -662,14 +676,14 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
let previousItem = self.item
|
||||
self.item = item
|
||||
|
||||
var peer: Peer?
|
||||
var peer: EnginePeer?
|
||||
var displayAsMessage = false
|
||||
var enablePreview = true
|
||||
switch item.content {
|
||||
case let .peer(messages, peerValue, _, _, _, _, _, _, _, _, displayAsMessageValue, _):
|
||||
displayAsMessage = displayAsMessageValue
|
||||
if displayAsMessage, let author = messages.last?.author as? TelegramUser {
|
||||
peer = author
|
||||
if displayAsMessage, case let .user(author) = messages.last?.author {
|
||||
peer = .user(author)
|
||||
} else {
|
||||
peer = peerValue.chatMainPeer
|
||||
}
|
||||
@@ -681,7 +695,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
UIView.transition(with: self.avatarNode.view, duration: 0.3, options: [.transitionCrossDissolve], animations: {
|
||||
}, completion: nil)
|
||||
}
|
||||
self.avatarNode.setPeer(context: item.context, theme: item.presentationData.theme, peer: peer.flatMap(EnginePeer.init), overrideImage: .archivedChatsIcon(hiddenByDefault: hiddenByDefault), emptyColor: item.presentationData.theme.list.mediaPlaceholderColor, synchronousLoad: synchronousLoads)
|
||||
self.avatarNode.setPeer(context: item.context, theme: item.presentationData.theme, peer: peer, overrideImage: .archivedChatsIcon(hiddenByDefault: hiddenByDefault), emptyColor: item.presentationData.theme.list.mediaPlaceholderColor, synchronousLoad: synchronousLoads)
|
||||
}
|
||||
|
||||
if let peer = peer {
|
||||
@@ -693,7 +707,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
} else if peer.isDeleted {
|
||||
overrideImage = .deletedIcon
|
||||
}
|
||||
self.avatarNode.setPeer(context: item.context, theme: item.presentationData.theme, peer: EnginePeer(peer), overrideImage: overrideImage, emptyColor: item.presentationData.theme.list.mediaPlaceholderColor, synchronousLoad: synchronousLoads, displayDimensions: CGSize(width: 60.0, height: 60.0))
|
||||
self.avatarNode.setPeer(context: item.context, theme: item.presentationData.theme, peer: peer, overrideImage: overrideImage, emptyColor: item.presentationData.theme.list.mediaPlaceholderColor, synchronousLoad: synchronousLoads, displayDimensions: CGSize(width: 60.0, height: 60.0))
|
||||
}
|
||||
|
||||
self.contextContainer.isGestureEnabled = enablePreview && !item.editing
|
||||
@@ -804,19 +818,19 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
let badgeFont = Font.with(size: floor(item.presentationData.fontSize.itemListBaseFontSize * 14.0 / 17.0), design: .regular, weight: .regular, traits: [.monospacedNumbers])
|
||||
|
||||
let account = item.context.account
|
||||
var messages: [Message]
|
||||
var messages: [EngineMessage]
|
||||
enum ContentPeer {
|
||||
case chat(RenderedPeer)
|
||||
case group([ChatListGroupReferencePeer])
|
||||
case chat(EngineRenderedPeer)
|
||||
case group([EngineChatList.GroupItem.Item])
|
||||
}
|
||||
let contentPeer: ContentPeer
|
||||
let combinedReadState: CombinedPeerReadState?
|
||||
let combinedReadState: EnginePeerReadCounters?
|
||||
let unreadCount: (count: Int32, unread: Bool, muted: Bool, mutedCount: Int32?)
|
||||
let isRemovedFromTotalUnreadCount: Bool
|
||||
let peerPresence: PeerPresence?
|
||||
let embeddedState: StoredPeerChatInterfaceState?
|
||||
let summaryInfo: ChatListMessageTagSummaryInfo
|
||||
let inputActivities: [(Peer, PeerInputActivity)]?
|
||||
let peerPresence: EnginePeer.Presence?
|
||||
let draftState: ChatListItemContent.DraftState?
|
||||
let hasUnseenMentions: Bool
|
||||
let inputActivities: [(EnginePeer, PeerInputActivity)]?
|
||||
let isPeerGroup: Bool
|
||||
let promoInfo: ChatListNodeEntryPromoInfo?
|
||||
let displayAsMessage: Bool
|
||||
@@ -825,7 +839,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
var groupHiddenByDefault = false
|
||||
|
||||
switch item.content {
|
||||
case let .peer(messagesValue, peerValue, combinedReadStateValue, isRemovedFromTotalUnreadCountValue, peerPresenceValue, summaryInfoValue, embeddedStateValue, inputActivitiesValue, promoInfoValue, ignoreUnreadBadge, displayAsMessageValue, _):
|
||||
case let .peer(messagesValue, peerValue, combinedReadStateValue, isRemovedFromTotalUnreadCountValue, peerPresenceValue, hasUnseenMentionsValue, draftStateValue, inputActivitiesValue, promoInfoValue, ignoreUnreadBadge, displayAsMessageValue, _):
|
||||
messages = messagesValue
|
||||
contentPeer = .chat(peerValue)
|
||||
combinedReadState = combinedReadStateValue
|
||||
@@ -839,15 +853,15 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
} else {
|
||||
isRemovedFromTotalUnreadCount = isRemovedFromTotalUnreadCountValue
|
||||
}
|
||||
peerPresence = (peerPresenceValue as? TelegramUserPresence).flatMap { presence -> TelegramUserPresence in
|
||||
TelegramUserPresence(status: presence.status, lastActivity: 0)
|
||||
peerPresence = peerPresenceValue.flatMap { presence -> EnginePeer.Presence in
|
||||
return EnginePeer.Presence(status: presence.status, lastActivity: 0)
|
||||
}
|
||||
embeddedState = embeddedStateValue
|
||||
summaryInfo = summaryInfoValue
|
||||
draftState = draftStateValue
|
||||
hasUnseenMentions = hasUnseenMentionsValue
|
||||
|
||||
switch peerValue.peer {
|
||||
case _ as TelegramUser, _ as TelegramSecretChat:
|
||||
if let peerPresence = peerPresence as? TelegramUserPresence, case .present = peerPresence.status {
|
||||
case .user, .secretChat:
|
||||
if let peerPresence = peerPresence, case .present = peerPresence.status {
|
||||
inputActivities = inputActivitiesValue
|
||||
} else {
|
||||
inputActivities = nil
|
||||
@@ -860,7 +874,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
promoInfo = promoInfoValue
|
||||
displayAsMessage = displayAsMessageValue
|
||||
hasFailedMessages = messagesValue.last?.flags.contains(.Failed) ?? false // hasFailedMessagesValue
|
||||
case let .groupReference(_, peers, messageValue, unreadState, hiddenByDefault):
|
||||
case let .groupReference(_, peers, messageValue, unreadCountValue, hiddenByDefault):
|
||||
if let _ = messageValue, !peers.isEmpty {
|
||||
contentPeer = .chat(peers[0].peer)
|
||||
} else {
|
||||
@@ -873,13 +887,12 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
}
|
||||
combinedReadState = nil
|
||||
isRemovedFromTotalUnreadCount = false
|
||||
embeddedState = nil
|
||||
summaryInfo = ChatListMessageTagSummaryInfo()
|
||||
draftState = nil
|
||||
hasUnseenMentions = false
|
||||
inputActivities = nil
|
||||
isPeerGroup = true
|
||||
groupHiddenByDefault = hiddenByDefault
|
||||
let allCount = unreadState.count(countingCategory: .chats, mutedCategory: .all)
|
||||
unreadCount = (allCount, allCount != 0, true, nil)
|
||||
unreadCount = (Int32(unreadCountValue), unreadCountValue != 0, true, nil)
|
||||
peerPresence = nil
|
||||
promoInfo = nil
|
||||
displayAsMessage = false
|
||||
@@ -949,8 +962,8 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
let leftInset: CGFloat = params.leftInset + avatarLeftInset
|
||||
|
||||
enum ContentData {
|
||||
case chat(itemPeer: RenderedPeer, peer: Peer?, hideAuthor: Bool, messageText: String)
|
||||
case group(peers: [ChatListGroupReferencePeer])
|
||||
case chat(itemPeer: EngineRenderedPeer, peer: EnginePeer?, hideAuthor: Bool, messageText: String)
|
||||
case group(peers: [EngineChatList.GroupItem.Item])
|
||||
}
|
||||
|
||||
let contentData: ContentData
|
||||
@@ -977,11 +990,11 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
|
||||
var inlineAuthorPrefix: String?
|
||||
if case .groupReference = item.content {
|
||||
if let author = messages.last?.author as? TelegramUser {
|
||||
if case let .user(author) = messages.last?.author {
|
||||
if author.id == item.context.account.peerId {
|
||||
inlineAuthorPrefix = item.presentationData.strings.DialogList_You
|
||||
} else if messages.last?.id.peerId.namespace != Namespaces.Peer.CloudUser && messages.last?.id.peerId.namespace != Namespaces.Peer.SecretChat {
|
||||
inlineAuthorPrefix = author.compactDisplayTitle
|
||||
inlineAuthorPrefix = EnginePeer.user(author).compactDisplayTitle
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -993,22 +1006,27 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
let contentImageSize = CGSize(width: contentImageSide, height: contentImageSide)
|
||||
let contentImageSpacing: CGFloat = 2.0
|
||||
let contentImageTrailingSpace: CGFloat = 5.0
|
||||
var contentImageSpecs: [(message: Message, media: Media, size: CGSize)] = []
|
||||
var contentImageSpecs: [(message: EngineMessage, media: EngineMedia, size: CGSize)] = []
|
||||
|
||||
switch contentData {
|
||||
case let .chat(itemPeer, _, _, text):
|
||||
var isUser = false
|
||||
if case .user = itemPeer.chatMainPeer {
|
||||
isUser = true
|
||||
}
|
||||
|
||||
var peerText: String?
|
||||
if case .groupReference = item.content {
|
||||
if let messagePeer = itemPeer.chatMainPeer {
|
||||
peerText = messagePeer.displayTitle(strings: item.presentationData.strings, displayOrder: item.presentationData.nameDisplayOrder)
|
||||
}
|
||||
} else if let message = messages.last, let author = message.author as? TelegramUser, let peer = itemPeer.chatMainPeer, !(peer is TelegramUser) {
|
||||
if let peer = peer as? TelegramChannel, case .broadcast = peer.info {
|
||||
} else if let message = messages.last, case let .user(author) = message.author, let peer = itemPeer.chatMainPeer, !isUser {
|
||||
if case let .channel(peer) = peer, case .broadcast = peer.info {
|
||||
} else if !displayAsMessage {
|
||||
if let forwardInfo = message.forwardInfo, forwardInfo.flags.contains(.isImported), let authorSignature = forwardInfo.authorSignature {
|
||||
peerText = authorSignature
|
||||
} else {
|
||||
peerText = author.id == account.peerId ? item.presentationData.strings.DialogList_You : author.displayTitle(strings: item.presentationData.strings, displayOrder: item.presentationData.nameDisplayOrder)
|
||||
peerText = author.id == account.peerId ? item.presentationData.strings.DialogList_You : EnginePeer(author).displayTitle(strings: item.presentationData.strings, displayOrder: item.presentationData.nameDisplayOrder)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1022,13 +1040,11 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
chatListText = (text, messageText)
|
||||
}
|
||||
|
||||
if inlineAuthorPrefix == nil, let embeddedState = embeddedState, embeddedState.overrideChatTimestamp != nil, let opaqueState = _internal_decodeStoredChatInterfaceState(state: embeddedState) {
|
||||
let interfaceState = ChatInterfaceState.parse(opaqueState)
|
||||
|
||||
if inlineAuthorPrefix == nil, let draftState = draftState {
|
||||
hasDraft = true
|
||||
authorAttributedString = NSAttributedString(string: item.presentationData.strings.DialogList_Draft, font: textFont, textColor: theme.messageDraftTextColor)
|
||||
|
||||
let draftText: String = interfaceState.composeInputState.inputText.string
|
||||
let draftText: String = draftState.text
|
||||
|
||||
attributedText = NSAttributedString(string: foldLineBreaks(draftText.replacingOccurrences(of: "\n\n", with: " ")), font: textFont, textColor: theme.messageTextColor)
|
||||
} else if let message = messages.last {
|
||||
@@ -1081,7 +1097,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
}
|
||||
|
||||
var displayMediaPreviews = true
|
||||
if message.containsSecretMedia {
|
||||
if message._asMessage().containsSecretMedia {
|
||||
displayMediaPreviews = false
|
||||
} else if let _ = message.peers[message.id.peerId] as? TelegramSecretChat {
|
||||
displayMediaPreviews = false
|
||||
@@ -1096,34 +1112,28 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
inner: for media in message.media {
|
||||
if let image = media as? TelegramMediaImage {
|
||||
if let _ = largestImageRepresentation(image.representations) {
|
||||
//let imageSize = largest.dimensions.cgSize
|
||||
//let fitSize = imageSize.aspectFilled(contentImageFillSize)
|
||||
let fitSize = contentImageSize
|
||||
contentImageSpecs.append((message, image, fitSize))
|
||||
contentImageSpecs.append((message, .image(image), fitSize))
|
||||
}
|
||||
break inner
|
||||
} else if let file = media as? TelegramMediaFile {
|
||||
if file.isVideo, !file.isInstantVideo, let _ = file.dimensions {
|
||||
//let imageSize = dimensions.cgSize
|
||||
//let fitSize = imageSize.aspectFilled(contentImageFillSize)
|
||||
let fitSize = contentImageSize
|
||||
contentImageSpecs.append((message, file, fitSize))
|
||||
contentImageSpecs.append((message, .file(file), fitSize))
|
||||
}
|
||||
break inner
|
||||
} else if let webpage = media as? TelegramMediaWebpage, case let .Loaded(content) = webpage.content {
|
||||
let imageTypes = ["photo", "video", "embed", "gif", "document", "telegram_album"]
|
||||
if let image = content.image, let type = content.type, imageTypes.contains(type) {
|
||||
if let _ = largestImageRepresentation(image.representations) {
|
||||
//let imageSize = largest.dimensions.cgSize
|
||||
let fitSize = contentImageSize
|
||||
contentImageSpecs.append((message, image, fitSize))
|
||||
contentImageSpecs.append((message, .image(image), fitSize))
|
||||
}
|
||||
break inner
|
||||
} else if let file = content.file {
|
||||
if file.isVideo, !file.isInstantVideo, let _ = file.dimensions {
|
||||
//let imageSize = dimensions.cgSize
|
||||
let fitSize = contentImageSize
|
||||
contentImageSpecs.append((message, file, fitSize))
|
||||
contentImageSpecs.append((message, .file(file), fitSize))
|
||||
}
|
||||
break inner
|
||||
}
|
||||
@@ -1176,15 +1186,15 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
|
||||
switch contentData {
|
||||
case let .chat(itemPeer, _, _, _):
|
||||
if let message = messages.last, let author = message.author as? TelegramUser, displayAsMessage {
|
||||
titleAttributedString = NSAttributedString(string: author.id == account.peerId ? item.presentationData.strings.DialogList_You : author.displayTitle(strings: item.presentationData.strings, displayOrder: item.presentationData.nameDisplayOrder), font: titleFont, textColor: theme.titleColor)
|
||||
if let message = messages.last, case let .user(author) = message.author, displayAsMessage {
|
||||
titleAttributedString = NSAttributedString(string: author.id == account.peerId ? item.presentationData.strings.DialogList_You : EnginePeer.user(author).displayTitle(strings: item.presentationData.strings, displayOrder: item.presentationData.nameDisplayOrder), font: titleFont, textColor: theme.titleColor)
|
||||
} else if isPeerGroup {
|
||||
titleAttributedString = NSAttributedString(string: item.presentationData.strings.ChatList_ArchivedChatsTitle, font: titleFont, textColor: theme.titleColor)
|
||||
} else if itemPeer.chatMainPeer?.id == item.context.account.peerId {
|
||||
titleAttributedString = NSAttributedString(string: item.presentationData.strings.DialogList_SavedMessages, font: titleFont, textColor: theme.titleColor)
|
||||
} else if let id = itemPeer.chatMainPeer?.id, id.isReplies {
|
||||
titleAttributedString = NSAttributedString(string: item.presentationData.strings.DialogList_Replies, font: titleFont, textColor: theme.titleColor)
|
||||
} else if let displayTitle = itemPeer.chatMainPeer?.displayTitle(strings: item.presentationData.strings, displayOrder: item.presentationData.nameDisplayOrder) {
|
||||
} else if let displayTitle = itemPeer.chatMainPeer?.displayTitle(strings: item.presentationData.strings, displayOrder: item.presentationData.nameDisplayOrder) {
|
||||
titleAttributedString = NSAttributedString(string: displayTitle, font: titleFont, textColor: item.index.messageIndex.id.peerId.namespace == Namespaces.Peer.SecretChat ? theme.secretTitleColor : theme.titleColor)
|
||||
}
|
||||
case .group:
|
||||
@@ -1221,7 +1231,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
}
|
||||
|
||||
if !isPeerGroup, let message = messages.last, message.author?.id == account.peerId && !hasDraft {
|
||||
if message.flags.isSending && !message.isSentOrAcknowledged {
|
||||
if message.flags.isSending && !message._asMessage().isSentOrAcknowledged {
|
||||
statusState = .clock(PresentationResourcesChatList.clockFrameImage(item.presentationData.theme), PresentationResourcesChatList.clockMinImage(item.presentationData.theme))
|
||||
} else if message.id.peerId != account.peerId {
|
||||
if hasFailedMessages {
|
||||
@@ -1263,13 +1273,10 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let tagSummaryCount = summaryInfo.tagSummaryCount ?? 0
|
||||
let actionsSummaryCount = summaryInfo.actionsSummaryCount ?? 0
|
||||
let totalMentionCount = tagSummaryCount - actionsSummaryCount
|
||||
|
||||
if !isPeerGroup {
|
||||
if totalMentionCount > 0 {
|
||||
if Namespaces.PeerGroup.archive == item.peerGroupId {
|
||||
if hasUnseenMentions {
|
||||
if case .archive = item.peerGroupId {
|
||||
currentMentionBadgeImage = PresentationResourcesChatList.badgeBackgroundInactiveMention(item.presentationData.theme, diameter: badgeDiameter)
|
||||
} else {
|
||||
currentMentionBadgeImage = PresentationResourcesChatList.badgeBackgroundMention(item.presentationData.theme, diameter: badgeDiameter)
|
||||
@@ -1414,20 +1421,20 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
switch item.content {
|
||||
case let .peer(_, renderedPeer, _, _, presence, _ ,_ ,_, _, _, displayAsMessage, _):
|
||||
if !displayAsMessage {
|
||||
if let peer = renderedPeer.chatMainPeer as? TelegramUser, let presence = presence as? TelegramUserPresence, !isServicePeer(peer) && !peer.flags.contains(.isSupport) && peer.id != item.context.account.peerId {
|
||||
let updatedPresence = TelegramUserPresence(status: presence.status, lastActivity: 0)
|
||||
let relativeStatus = relativeUserPresenceStatus(EnginePeer.Presence(updatedPresence), relativeTo: timestamp)
|
||||
if case let .user(peer) = renderedPeer.chatMainPeer, let presence = presence, !isServicePeer(peer) && !peer.flags.contains(.isSupport) && peer.id != item.context.account.peerId {
|
||||
let updatedPresence = EnginePeer.Presence(status: presence.status, lastActivity: 0)
|
||||
let relativeStatus = relativeUserPresenceStatus(updatedPresence, relativeTo: timestamp)
|
||||
if case .online = relativeStatus {
|
||||
online = true
|
||||
}
|
||||
animateOnline = true
|
||||
} else if let channel = renderedPeer.peer as? TelegramChannel {
|
||||
} else if case let .channel(channel) = renderedPeer.peer {
|
||||
onlineIsVoiceChat = true
|
||||
if channel.flags.contains(.hasActiveVoiceChat) && item.interaction.searchTextHighightState == nil {
|
||||
online = true
|
||||
}
|
||||
animateOnline = true
|
||||
} else if let group = renderedPeer.peer as? TelegramGroup {
|
||||
} else if case let .legacyGroup(group) = renderedPeer.peer {
|
||||
onlineIsVoiceChat = true
|
||||
if group.flags.contains(.hasActiveVoiceChat) && item.interaction.searchTextHighightState == nil {
|
||||
online = true
|
||||
@@ -1780,7 +1787,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
inputActivitiesApply?()
|
||||
|
||||
var mediaPreviewOffset = textNodeFrame.origin.offsetBy(dx: 1.0, dy: floor((measureLayout.size.height - contentImageSize.height) / 2.0))
|
||||
var validMediaIds: [MediaId] = []
|
||||
var validMediaIds: [EngineMedia.Id] = []
|
||||
for (message, media, mediaSize) in contentImageSpecs {
|
||||
guard let mediaId = media.id else {
|
||||
continue
|
||||
@@ -1803,7 +1810,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
previewNodeTransition.updateFrame(node: previewNode, frame: CGRect(origin: mediaPreviewOffset, size: mediaSize))
|
||||
mediaPreviewOffset.x += mediaSize.width + contentImageSpacing
|
||||
}
|
||||
var removeMediaIds: [MediaId] = []
|
||||
var removeMediaIds: [EngineMedia.Id] = []
|
||||
for (mediaId, itemNode) in strongSelf.mediaPreviewNodes {
|
||||
if !validMediaIds.contains(mediaId) {
|
||||
removeMediaIds.append(mediaId)
|
||||
@@ -1864,8 +1871,8 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
let topNegativeInset: CGFloat = 0.0
|
||||
strongSelf.highlightedBackgroundNode.frame = CGRect(origin: CGPoint(x: 0.0, y: layoutOffset - separatorHeight - topNegativeInset), size: CGSize(width: layout.contentSize.width, height: layout.contentSize.height + separatorHeight + topNegativeInset))
|
||||
|
||||
if let peerPresence = peerPresence as? TelegramUserPresence {
|
||||
strongSelf.peerPresenceManager?.reset(presence: TelegramUserPresence(status: peerPresence.status, lastActivity: 0), isOnline: online)
|
||||
if let peerPresence = peerPresence {
|
||||
strongSelf.peerPresenceManager?.reset(presence: EnginePeer.Presence(status: peerPresence.status, lastActivity: 0), isOnline: online)
|
||||
}
|
||||
|
||||
strongSelf.updateLayout(size: layout.contentSize, leftInset: params.leftInset, rightInset: params.rightInset)
|
||||
@@ -2057,7 +2064,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
case RevealOptionKey.pin.rawValue:
|
||||
switch item.content {
|
||||
case .peer:
|
||||
let itemId: PinnedItemId = .peer(item.index.messageIndex.id.peerId)
|
||||
let itemId: EngineChatList.PinnedItem.Id = .peer(item.index.messageIndex.id.peerId)
|
||||
item.interaction.setItemPinned(itemId, true)
|
||||
case .groupReference:
|
||||
break
|
||||
@@ -2065,7 +2072,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
case RevealOptionKey.unpin.rawValue:
|
||||
switch item.content {
|
||||
case .peer:
|
||||
let itemId: PinnedItemId = .peer(item.index.messageIndex.id.peerId)
|
||||
let itemId: EngineChatList.PinnedItem.Id = .peer(item.index.messageIndex.id.peerId)
|
||||
item.interaction.setItemPinned(itemId, false)
|
||||
case .groupReference:
|
||||
break
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
import TelegramCore
|
||||
import TelegramPresentationData
|
||||
import TelegramUIPreferences
|
||||
@@ -14,7 +13,7 @@ private enum MessageGroupType {
|
||||
case generic
|
||||
}
|
||||
|
||||
private func singleMessageType(message: Message) -> MessageGroupType {
|
||||
private func singleMessageType(message: EngineMessage) -> MessageGroupType {
|
||||
for media in message.media {
|
||||
if let _ = media as? TelegramMediaImage {
|
||||
return .photos
|
||||
@@ -31,7 +30,7 @@ private func singleMessageType(message: Message) -> MessageGroupType {
|
||||
return .generic
|
||||
}
|
||||
|
||||
private func messageGroupType(messages: [Message]) -> MessageGroupType {
|
||||
private func messageGroupType(messages: [EngineMessage]) -> MessageGroupType {
|
||||
if messages.isEmpty {
|
||||
return .generic
|
||||
}
|
||||
@@ -45,8 +44,8 @@ private func messageGroupType(messages: [Message]) -> MessageGroupType {
|
||||
return currentType
|
||||
}
|
||||
|
||||
public func chatListItemStrings(strings: PresentationStrings, nameDisplayOrder: PresentationPersonNameOrder, dateTimeFormat: PresentationDateTimeFormat, messages: [Message], chatPeer: RenderedPeer, accountPeerId: PeerId, enableMediaEmoji: Bool = true, isPeerGroup: Bool = false) -> (peer: Peer?, hideAuthor: Bool, messageText: String) {
|
||||
let peer: Peer?
|
||||
public func chatListItemStrings(strings: PresentationStrings, nameDisplayOrder: PresentationPersonNameOrder, dateTimeFormat: PresentationDateTimeFormat, messages: [EngineMessage], chatPeer: EngineRenderedPeer, accountPeerId: EnginePeer.Id, enableMediaEmoji: Bool = true, isPeerGroup: Bool = false) -> (peer: EnginePeer?, hideAuthor: Bool, messageText: String) {
|
||||
let peer: EnginePeer?
|
||||
|
||||
let message = messages.last
|
||||
|
||||
@@ -290,7 +289,7 @@ public func chatListItemStrings(strings: PresentationStrings, nameDisplayOrder:
|
||||
peer = chatPeer.chatMainPeer
|
||||
messageText = ""
|
||||
if chatPeer.peerId.namespace == Namespaces.Peer.SecretChat {
|
||||
if let secretChat = chatPeer.peers[chatPeer.peerId] as? TelegramSecretChat {
|
||||
if case let .secretChat(secretChat) = chatPeer.peers[chatPeer.peerId] {
|
||||
switch secretChat.embeddedState {
|
||||
case .active:
|
||||
switch secretChat.role {
|
||||
|
||||
@@ -4,7 +4,6 @@ import Display
|
||||
import AsyncDisplayKit
|
||||
import SwiftSignalKit
|
||||
import TelegramCore
|
||||
import Postbox
|
||||
import TelegramPresentationData
|
||||
import TelegramUIPreferences
|
||||
import AccountContext
|
||||
@@ -48,34 +47,34 @@ final class ChatListHighlightedLocation {
|
||||
|
||||
public final class ChatListNodeInteraction {
|
||||
public enum PeerEntry {
|
||||
case peerId(PeerId)
|
||||
case peer(Peer)
|
||||
case peerId(EnginePeer.Id)
|
||||
case peer(EnginePeer)
|
||||
}
|
||||
|
||||
let activateSearch: () -> Void
|
||||
let peerSelected: (Peer, Peer?, ChatListNodeEntryPromoInfo?) -> Void
|
||||
let disabledPeerSelected: (Peer) -> Void
|
||||
let togglePeerSelected: (Peer) -> Void
|
||||
let peerSelected: (EnginePeer, EnginePeer?, ChatListNodeEntryPromoInfo?) -> Void
|
||||
let disabledPeerSelected: (EnginePeer) -> Void
|
||||
let togglePeerSelected: (EnginePeer) -> Void
|
||||
let togglePeersSelection: ([PeerEntry], Bool) -> Void
|
||||
let additionalCategorySelected: (Int) -> Void
|
||||
let messageSelected: (Peer, Message, ChatListNodeEntryPromoInfo?) -> Void
|
||||
let groupSelected: (PeerGroupId) -> Void
|
||||
let messageSelected: (EnginePeer, EngineMessage, ChatListNodeEntryPromoInfo?) -> Void
|
||||
let groupSelected: (EngineChatList.Group) -> Void
|
||||
let addContact: (String) -> Void
|
||||
let setPeerIdWithRevealedOptions: (PeerId?, PeerId?) -> Void
|
||||
let setItemPinned: (PinnedItemId, Bool) -> Void
|
||||
let setPeerMuted: (PeerId, Bool) -> Void
|
||||
let deletePeer: (PeerId, Bool) -> Void
|
||||
let updatePeerGrouping: (PeerId, Bool) -> Void
|
||||
let togglePeerMarkedUnread: (PeerId, Bool) -> Void
|
||||
let setPeerIdWithRevealedOptions: (EnginePeer.Id?, EnginePeer.Id?) -> Void
|
||||
let setItemPinned: (EngineChatList.PinnedItem.Id, Bool) -> Void
|
||||
let setPeerMuted: (EnginePeer.Id, Bool) -> Void
|
||||
let deletePeer: (EnginePeer.Id, Bool) -> Void
|
||||
let updatePeerGrouping: (EnginePeer.Id, Bool) -> Void
|
||||
let togglePeerMarkedUnread: (EnginePeer.Id, Bool) -> Void
|
||||
let toggleArchivedFolderHiddenByDefault: () -> Void
|
||||
let hidePsa: (PeerId) -> Void
|
||||
let hidePsa: (EnginePeer.Id) -> Void
|
||||
let activateChatPreview: (ChatListItem, ASDisplayNode, ContextGesture?) -> Void
|
||||
let present: (ViewController) -> Void
|
||||
|
||||
public var searchTextHighightState: String?
|
||||
var highlightedChatLocation: ChatListHighlightedLocation?
|
||||
|
||||
public init(activateSearch: @escaping () -> Void, peerSelected: @escaping (Peer, Peer?, ChatListNodeEntryPromoInfo?) -> Void, disabledPeerSelected: @escaping (Peer) -> Void, togglePeerSelected: @escaping (Peer) -> Void, togglePeersSelection: @escaping ([PeerEntry], Bool) -> Void, additionalCategorySelected: @escaping (Int) -> Void, messageSelected: @escaping (Peer, Message, ChatListNodeEntryPromoInfo?) -> Void, groupSelected: @escaping (PeerGroupId) -> Void, addContact: @escaping (String) -> Void, setPeerIdWithRevealedOptions: @escaping (PeerId?, PeerId?) -> Void, setItemPinned: @escaping (PinnedItemId, Bool) -> Void, setPeerMuted: @escaping (PeerId, Bool) -> Void, deletePeer: @escaping (PeerId, Bool) -> Void, updatePeerGrouping: @escaping (PeerId, Bool) -> Void, togglePeerMarkedUnread: @escaping (PeerId, Bool) -> Void, toggleArchivedFolderHiddenByDefault: @escaping () -> Void, hidePsa: @escaping (PeerId) -> Void, activateChatPreview: @escaping (ChatListItem, ASDisplayNode, ContextGesture?) -> Void, present: @escaping (ViewController) -> Void) {
|
||||
public init(activateSearch: @escaping () -> Void, peerSelected: @escaping (EnginePeer, EnginePeer?, ChatListNodeEntryPromoInfo?) -> Void, disabledPeerSelected: @escaping (EnginePeer) -> Void, togglePeerSelected: @escaping (EnginePeer) -> Void, togglePeersSelection: @escaping ([PeerEntry], Bool) -> Void, additionalCategorySelected: @escaping (Int) -> Void, messageSelected: @escaping (EnginePeer, EngineMessage, ChatListNodeEntryPromoInfo?) -> Void, groupSelected: @escaping (EngineChatList.Group) -> Void, addContact: @escaping (String) -> Void, setPeerIdWithRevealedOptions: @escaping (EnginePeer.Id?, EnginePeer.Id?) -> Void, setItemPinned: @escaping (EngineChatList.PinnedItem.Id, Bool) -> Void, setPeerMuted: @escaping (EnginePeer.Id, Bool) -> Void, deletePeer: @escaping (EnginePeer.Id, Bool) -> Void, updatePeerGrouping: @escaping (EnginePeer.Id, Bool) -> Void, togglePeerMarkedUnread: @escaping (EnginePeer.Id, Bool) -> Void, toggleArchivedFolderHiddenByDefault: @escaping () -> Void, hidePsa: @escaping (EnginePeer.Id) -> Void, activateChatPreview: @escaping (ChatListItem, ASDisplayNode, ContextGesture?) -> Void, present: @escaping (ViewController) -> Void) {
|
||||
self.activateSearch = activateSearch
|
||||
self.peerSelected = peerSelected
|
||||
self.disabledPeerSelected = disabledPeerSelected
|
||||
@@ -99,19 +98,19 @@ public final class ChatListNodeInteraction {
|
||||
}
|
||||
|
||||
public final class ChatListNodePeerInputActivities {
|
||||
public let activities: [PeerId: [(Peer, PeerInputActivity)]]
|
||||
public let activities: [EnginePeer.Id: [(EnginePeer, PeerInputActivity)]]
|
||||
|
||||
public init(activities: [PeerId: [(Peer, PeerInputActivity)]]) {
|
||||
public init(activities: [EnginePeer.Id: [(EnginePeer, PeerInputActivity)]]) {
|
||||
self.activities = activities
|
||||
}
|
||||
}
|
||||
|
||||
private func areFoundPeerArraysEqual(_ lhs: [(Peer, Peer?)], _ rhs: [(Peer, Peer?)]) -> Bool {
|
||||
private func areFoundPeerArraysEqual(_ lhs: [(EnginePeer, EnginePeer?)], _ rhs: [(EnginePeer, EnginePeer?)]) -> Bool {
|
||||
if lhs.count != rhs.count {
|
||||
return false
|
||||
}
|
||||
for i in 0 ..< lhs.count {
|
||||
if !arePeersEqual(lhs[i].0, rhs[i].0) || !arePeersEqual(lhs[i].1, rhs[i].1) {
|
||||
if lhs[i].0 != rhs[i].0 || lhs[i].1 != rhs[i].1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -121,18 +120,18 @@ private func areFoundPeerArraysEqual(_ lhs: [(Peer, Peer?)], _ rhs: [(Peer, Peer
|
||||
public struct ChatListNodeState: Equatable {
|
||||
public var presentationData: ChatListPresentationData
|
||||
public var editing: Bool
|
||||
public var peerIdWithRevealedOptions: PeerId?
|
||||
public var selectedPeerIds: Set<PeerId>
|
||||
public var peerIdWithRevealedOptions: EnginePeer.Id?
|
||||
public var selectedPeerIds: Set<EnginePeer.Id>
|
||||
public var peerInputActivities: ChatListNodePeerInputActivities?
|
||||
public var pendingRemovalPeerIds: Set<PeerId>
|
||||
public var pendingClearHistoryPeerIds: Set<PeerId>
|
||||
public var pendingRemovalPeerIds: Set<EnginePeer.Id>
|
||||
public var pendingClearHistoryPeerIds: Set<EnginePeer.Id>
|
||||
public var archiveShouldBeTemporaryRevealed: Bool
|
||||
public var selectedAdditionalCategoryIds: Set<Int>
|
||||
public var hiddenPsaPeerId: PeerId?
|
||||
public var foundPeers: [(Peer, Peer?)]
|
||||
public var selectedPeerMap: [PeerId: Peer]
|
||||
public var hiddenPsaPeerId: EnginePeer.Id?
|
||||
public var foundPeers: [(EnginePeer, EnginePeer?)]
|
||||
public var selectedPeerMap: [EnginePeer.Id: EnginePeer]
|
||||
|
||||
public init(presentationData: ChatListPresentationData, editing: Bool, peerIdWithRevealedOptions: PeerId?, selectedPeerIds: Set<PeerId>, foundPeers: [(Peer, Peer?)], selectedPeerMap: [PeerId: Peer], selectedAdditionalCategoryIds: Set<Int>, peerInputActivities: ChatListNodePeerInputActivities?, pendingRemovalPeerIds: Set<PeerId>, pendingClearHistoryPeerIds: Set<PeerId>, archiveShouldBeTemporaryRevealed: Bool, hiddenPsaPeerId: PeerId?) {
|
||||
public init(presentationData: ChatListPresentationData, editing: Bool, peerIdWithRevealedOptions: EnginePeer.Id?, selectedPeerIds: Set<EnginePeer.Id>, foundPeers: [(EnginePeer, EnginePeer?)], selectedPeerMap: [EnginePeer.Id: EnginePeer], selectedAdditionalCategoryIds: Set<Int>, peerInputActivities: ChatListNodePeerInputActivities?, pendingRemovalPeerIds: Set<EnginePeer.Id>, pendingClearHistoryPeerIds: Set<EnginePeer.Id>, archiveShouldBeTemporaryRevealed: Bool, hiddenPsaPeerId: EnginePeer.Id?) {
|
||||
self.presentationData = presentationData
|
||||
self.editing = editing
|
||||
self.peerIdWithRevealedOptions = peerIdWithRevealedOptions
|
||||
@@ -163,7 +162,7 @@ public struct ChatListNodeState: Equatable {
|
||||
if areFoundPeerArraysEqual(lhs.foundPeers, rhs.foundPeers) {
|
||||
return false
|
||||
}
|
||||
if arePeerDictionariesEqual(lhs.selectedPeerMap, rhs.selectedPeerMap) {
|
||||
if lhs.selectedPeerMap != rhs.selectedPeerMap {
|
||||
return false
|
||||
}
|
||||
if lhs.selectedAdditionalCategoryIds != rhs.selectedAdditionalCategoryIds {
|
||||
@@ -188,7 +187,7 @@ public struct ChatListNodeState: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
private func mappedInsertEntries(context: AccountContext, nodeInteraction: ChatListNodeInteraction, peerGroupId: PeerGroupId, filterData: ChatListItemFilterData?, mode: ChatListNodeMode, entries: [ChatListNodeViewTransitionInsertEntry]) -> [ListViewInsertItem] {
|
||||
private func mappedInsertEntries(context: AccountContext, nodeInteraction: ChatListNodeInteraction, peerGroupId: EngineChatList.Group, filterData: ChatListItemFilterData?, mode: ChatListNodeMode, entries: [ChatListNodeViewTransitionInsertEntry]) -> [ListViewInsertItem] {
|
||||
return entries.map { entry -> ListViewInsertItem in
|
||||
switch entry.entry {
|
||||
case .HeaderEntry:
|
||||
@@ -211,20 +210,47 @@ private func mappedInsertEntries(context: AccountContext, nodeInteraction: ChatL
|
||||
nodeInteraction.additionalCategorySelected(id)
|
||||
}
|
||||
), directionHint: entry.directionHint)
|
||||
case let .PeerEntry(index, presentationData, messages, combinedReadState, isRemovedFromTotalUnreadCount, embeddedState, peer, presence, summaryInfo, editing, hasActiveRevealControls, selected, inputActivities, promoInfo, hasFailedMessages, isContact):
|
||||
case let .PeerEntry(index, presentationData, messages, combinedReadState, isRemovedFromTotalUnreadCount, draftState, peer, presence, hasUnseenMentions, editing, hasActiveRevealControls, selected, inputActivities, promoInfo, hasFailedMessages, isContact):
|
||||
switch mode {
|
||||
case .chatList:
|
||||
return ListViewInsertItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListItem(presentationData: presentationData, context: context, peerGroupId: peerGroupId, filterData: filterData, index: index, content: .peer(messages: messages, peer: peer, combinedReadState: combinedReadState, isRemovedFromTotalUnreadCount: isRemovedFromTotalUnreadCount, presence: presence, summaryInfo: summaryInfo, embeddedState: embeddedState, inputActivities: inputActivities, promoInfo: promoInfo, ignoreUnreadBadge: false, displayAsMessage: false, hasFailedMessages: hasFailedMessages), editing: editing, hasActiveRevealControls: hasActiveRevealControls, selected: selected, header: nil, enableContextActions: true, hiddenOffset: false, interaction: nodeInteraction), directionHint: entry.directionHint)
|
||||
return ListViewInsertItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListItem(
|
||||
presentationData: presentationData,
|
||||
context: context,
|
||||
peerGroupId: peerGroupId,
|
||||
filterData: filterData,
|
||||
index: index,
|
||||
content: .peer(
|
||||
messages: messages,
|
||||
peer: peer,
|
||||
combinedReadState: combinedReadState,
|
||||
isRemovedFromTotalUnreadCount: isRemovedFromTotalUnreadCount,
|
||||
presence: presence,
|
||||
hasUnseenMentions: hasUnseenMentions,
|
||||
draftState: draftState,
|
||||
inputActivities: inputActivities,
|
||||
promoInfo: promoInfo,
|
||||
ignoreUnreadBadge: false,
|
||||
displayAsMessage: false,
|
||||
hasFailedMessages: hasFailedMessages
|
||||
),
|
||||
editing: editing,
|
||||
hasActiveRevealControls: hasActiveRevealControls,
|
||||
selected: selected,
|
||||
header: nil,
|
||||
enableContextActions: true,
|
||||
hiddenOffset: false,
|
||||
interaction: nodeInteraction
|
||||
), directionHint: entry.directionHint)
|
||||
case let .peers(filter, isSelecting, _, filters):
|
||||
let itemPeer = peer.chatMainPeer
|
||||
var chatPeer: Peer?
|
||||
var chatPeer: EnginePeer?
|
||||
if let peer = peer.peers[peer.peerId] {
|
||||
chatPeer = peer
|
||||
}
|
||||
var enabled = true
|
||||
if filter.contains(.onlyWriteable) {
|
||||
if let peer = peer.peers[peer.peerId] {
|
||||
if !canSendMessagesToPeer(peer) {
|
||||
if !canSendMessagesToPeer(peer._asPeer()) {
|
||||
enabled = false
|
||||
}
|
||||
} else {
|
||||
@@ -233,7 +259,10 @@ private func mappedInsertEntries(context: AccountContext, nodeInteraction: ChatL
|
||||
}
|
||||
if filter.contains(.onlyPrivateChats) {
|
||||
if let peer = peer.peers[peer.peerId] {
|
||||
if !(peer is TelegramUser || peer is TelegramSecretChat) {
|
||||
switch peer {
|
||||
case .user, .secretChat:
|
||||
break
|
||||
default:
|
||||
enabled = false
|
||||
}
|
||||
} else {
|
||||
@@ -242,8 +271,8 @@ private func mappedInsertEntries(context: AccountContext, nodeInteraction: ChatL
|
||||
}
|
||||
if filter.contains(.onlyGroups) {
|
||||
if let peer = peer.peers[peer.peerId] {
|
||||
if let _ = peer as? TelegramGroup {
|
||||
} else if let peer = peer as? TelegramChannel, case .group = peer.info {
|
||||
if case .legacyGroup = peer {
|
||||
} else if case let .channel(peer) = peer, case .group = peer.info {
|
||||
} else {
|
||||
enabled = false
|
||||
}
|
||||
@@ -254,7 +283,7 @@ private func mappedInsertEntries(context: AccountContext, nodeInteraction: ChatL
|
||||
if filter.contains(.onlyManageable) {
|
||||
if let peer = peer.peers[peer.peerId] {
|
||||
var canManage = false
|
||||
if let peer = peer as? TelegramGroup {
|
||||
if case let .legacyGroup(peer) = peer {
|
||||
switch peer.role {
|
||||
case .creator, .admin:
|
||||
canManage = true
|
||||
@@ -264,7 +293,7 @@ private func mappedInsertEntries(context: AccountContext, nodeInteraction: ChatL
|
||||
}
|
||||
|
||||
if canManage {
|
||||
} else if let peer = peer as? TelegramChannel, case .group = peer.info, peer.hasPermission(.inviteMembers) {
|
||||
} else if case let .channel(peer) = peer, case .group = peer.info, peer.hasPermission(.inviteMembers) {
|
||||
} else {
|
||||
enabled = false
|
||||
}
|
||||
@@ -274,7 +303,7 @@ private func mappedInsertEntries(context: AccountContext, nodeInteraction: ChatL
|
||||
}
|
||||
if filter.contains(.excludeChannels) {
|
||||
if let peer = peer.peers[peer.peerId] {
|
||||
if let peer = peer as? TelegramChannel, case .broadcast = peer.info {
|
||||
if case let .channel(peer) = peer, case .broadcast = peer.info {
|
||||
enabled = false
|
||||
}
|
||||
}
|
||||
@@ -299,57 +328,115 @@ private func mappedInsertEntries(context: AccountContext, nodeInteraction: ChatL
|
||||
|
||||
var status: ContactsPeerItemStatus = .none
|
||||
if isSelecting, let itemPeer = itemPeer {
|
||||
let tagSummaryCount = summaryInfo.tagSummaryCount ?? 0
|
||||
let actionsSummaryCount = summaryInfo.actionsSummaryCount ?? 0
|
||||
let totalMentionCount = tagSummaryCount - actionsSummaryCount
|
||||
if let (string, multiline) = statusStringForPeerType(accountPeerId: context.account.peerId, strings: presentationData.strings, peer: itemPeer, isMuted: isRemovedFromTotalUnreadCount, isUnread: combinedReadState?.isUnread ?? false, isContact: isContact, hasUnseenMentions: totalMentionCount > 0, chatListFilters: filters) {
|
||||
if let (string, multiline) = statusStringForPeerType(accountPeerId: context.account.peerId, strings: presentationData.strings, peer: itemPeer, isMuted: isRemovedFromTotalUnreadCount, isUnread: combinedReadState?.isUnread ?? false, isContact: isContact, hasUnseenMentions: hasUnseenMentions, chatListFilters: filters) {
|
||||
status = .custom(string: string, multiline: multiline)
|
||||
} else {
|
||||
status = .none
|
||||
}
|
||||
}
|
||||
|
||||
return ListViewInsertItem(index: entry.index, previousIndex: entry.previousIndex, item: ContactsPeerItem(presentationData: ItemListPresentationData(theme: presentationData.theme, fontSize: presentationData.fontSize, strings: presentationData.strings), sortOrder: presentationData.nameSortOrder, displayOrder: presentationData.nameDisplayOrder, context: context, peerMode: .generalSearch, peer: .peer(peer: itemPeer, chatPeer: chatPeer), status: status, enabled: enabled, selection: editing ? .selectable(selected: selected) : .none, editing: ContactsPeerItemEditing(editable: false, editing: false, revealed: false), index: nil, header: header, action: { _ in
|
||||
if let chatPeer = chatPeer {
|
||||
if editing {
|
||||
nodeInteraction.togglePeerSelected(chatPeer)
|
||||
} else {
|
||||
nodeInteraction.peerSelected(chatPeer, nil, nil)
|
||||
return ListViewInsertItem(index: entry.index, previousIndex: entry.previousIndex, item: ContactsPeerItem(
|
||||
presentationData: ItemListPresentationData(theme: presentationData.theme, fontSize: presentationData.fontSize, strings: presentationData.strings),
|
||||
sortOrder: presentationData.nameSortOrder,
|
||||
displayOrder: presentationData.nameDisplayOrder,
|
||||
context: context,
|
||||
peerMode: .generalSearch,
|
||||
peer: .peer(peer: itemPeer, chatPeer: chatPeer),
|
||||
status: status,
|
||||
enabled: enabled,
|
||||
selection: editing ? .selectable(selected: selected) : .none,
|
||||
editing: ContactsPeerItemEditing(editable: false, editing: false, revealed: false),
|
||||
index: nil,
|
||||
header: header,
|
||||
action: { _ in
|
||||
if let chatPeer = chatPeer {
|
||||
if editing {
|
||||
nodeInteraction.togglePeerSelected(chatPeer)
|
||||
} else {
|
||||
nodeInteraction.peerSelected(chatPeer, nil, nil)
|
||||
}
|
||||
}
|
||||
}, disabledAction: { _ in
|
||||
if let chatPeer = chatPeer {
|
||||
nodeInteraction.disabledPeerSelected(chatPeer)
|
||||
}
|
||||
}
|
||||
}, disabledAction: { _ in
|
||||
if let chatPeer = chatPeer {
|
||||
nodeInteraction.disabledPeerSelected(chatPeer)
|
||||
}
|
||||
}), directionHint: entry.directionHint)
|
||||
), directionHint: entry.directionHint)
|
||||
}
|
||||
case let .HoleEntry(_, theme):
|
||||
return ListViewInsertItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListHoleItem(theme: theme), directionHint: entry.directionHint)
|
||||
case let .GroupReferenceEntry(index, presentationData, groupId, peers, message, editing, unreadState, revealed, hiddenByDefault):
|
||||
return ListViewInsertItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListItem(presentationData: presentationData, context: context, peerGroupId: peerGroupId, filterData: filterData, index: index, content: .groupReference(groupId: groupId, peers: peers, message: message, unreadState: unreadState, hiddenByDefault: hiddenByDefault), editing: editing, hasActiveRevealControls: false, selected: false, header: nil, enableContextActions: true, hiddenOffset: hiddenByDefault && !revealed, interaction: nodeInteraction), directionHint: entry.directionHint)
|
||||
case let .GroupReferenceEntry(index, presentationData, groupId, peers, message, editing, unreadCount, revealed, hiddenByDefault):
|
||||
return ListViewInsertItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListItem(
|
||||
presentationData: presentationData,
|
||||
context: context,
|
||||
peerGroupId: peerGroupId,
|
||||
filterData: filterData,
|
||||
index: index,
|
||||
content: .groupReference(
|
||||
groupId: groupId,
|
||||
peers: peers,
|
||||
message: message,
|
||||
unreadCount: unreadCount,
|
||||
hiddenByDefault: hiddenByDefault
|
||||
),
|
||||
editing: editing,
|
||||
hasActiveRevealControls: false,
|
||||
selected: false,
|
||||
header: nil,
|
||||
enableContextActions: true,
|
||||
hiddenOffset: hiddenByDefault && !revealed,
|
||||
interaction: nodeInteraction
|
||||
), directionHint: entry.directionHint)
|
||||
case let .ArchiveIntro(presentationData):
|
||||
return ListViewInsertItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListArchiveInfoItem(theme: presentationData.theme, strings: presentationData.strings), directionHint: entry.directionHint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func mappedUpdateEntries(context: AccountContext, nodeInteraction: ChatListNodeInteraction, peerGroupId: PeerGroupId, filterData: ChatListItemFilterData?, mode: ChatListNodeMode, entries: [ChatListNodeViewTransitionUpdateEntry]) -> [ListViewUpdateItem] {
|
||||
private func mappedUpdateEntries(context: AccountContext, nodeInteraction: ChatListNodeInteraction, peerGroupId: EngineChatList.Group, filterData: ChatListItemFilterData?, mode: ChatListNodeMode, entries: [ChatListNodeViewTransitionUpdateEntry]) -> [ListViewUpdateItem] {
|
||||
return entries.map { entry -> ListViewUpdateItem in
|
||||
switch entry.entry {
|
||||
case let .PeerEntry(index, presentationData, messages, combinedReadState, isRemovedFromTotalUnreadCount, embeddedState, peer, presence, summaryInfo, editing, hasActiveRevealControls, selected, inputActivities, promoInfo, hasFailedMessages, isContact):
|
||||
case let .PeerEntry(index, presentationData, messages, combinedReadState, isRemovedFromTotalUnreadCount, draftState, peer, presence, hasUnseenMentions, editing, hasActiveRevealControls, selected, inputActivities, promoInfo, hasFailedMessages, isContact):
|
||||
switch mode {
|
||||
case .chatList:
|
||||
return ListViewUpdateItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListItem(presentationData: presentationData, context: context, peerGroupId: peerGroupId, filterData: filterData, index: index, content: .peer(messages: messages, peer: peer, combinedReadState: combinedReadState, isRemovedFromTotalUnreadCount: isRemovedFromTotalUnreadCount, presence: presence, summaryInfo: summaryInfo, embeddedState: embeddedState, inputActivities: inputActivities, promoInfo: promoInfo, ignoreUnreadBadge: false, displayAsMessage: false, hasFailedMessages: hasFailedMessages), editing: editing, hasActiveRevealControls: hasActiveRevealControls, selected: selected, header: nil, enableContextActions: true, hiddenOffset: false, interaction: nodeInteraction), directionHint: entry.directionHint)
|
||||
return ListViewUpdateItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListItem(
|
||||
presentationData: presentationData,
|
||||
context: context,
|
||||
peerGroupId: peerGroupId,
|
||||
filterData: filterData,
|
||||
index: index,
|
||||
content: .peer(
|
||||
messages: messages,
|
||||
peer: peer,
|
||||
combinedReadState: combinedReadState,
|
||||
isRemovedFromTotalUnreadCount: isRemovedFromTotalUnreadCount,
|
||||
presence: presence,
|
||||
hasUnseenMentions: hasUnseenMentions,
|
||||
draftState: draftState,
|
||||
inputActivities: inputActivities,
|
||||
promoInfo: promoInfo,
|
||||
ignoreUnreadBadge: false,
|
||||
displayAsMessage: false,
|
||||
hasFailedMessages: hasFailedMessages
|
||||
),
|
||||
editing: editing,
|
||||
hasActiveRevealControls: hasActiveRevealControls,
|
||||
selected: selected,
|
||||
header: nil,
|
||||
enableContextActions: true,
|
||||
hiddenOffset: false,
|
||||
interaction: nodeInteraction
|
||||
), directionHint: entry.directionHint)
|
||||
case let .peers(filter, isSelecting, _, filters):
|
||||
let itemPeer = peer.chatMainPeer
|
||||
var chatPeer: Peer?
|
||||
var chatPeer: EnginePeer?
|
||||
if let peer = peer.peers[peer.peerId] {
|
||||
chatPeer = peer
|
||||
}
|
||||
var enabled = true
|
||||
if filter.contains(.onlyWriteable) {
|
||||
if let peer = peer.peers[peer.peerId] {
|
||||
if !canSendMessagesToPeer(peer) {
|
||||
if !canSendMessagesToPeer(peer._asPeer()) {
|
||||
enabled = false
|
||||
}
|
||||
} else {
|
||||
@@ -357,7 +444,7 @@ private func mappedUpdateEntries(context: AccountContext, nodeInteraction: ChatL
|
||||
}
|
||||
}
|
||||
if filter.contains(.excludeChannels) {
|
||||
if let peer = peer.chatMainPeer as? TelegramChannel, case .broadcast = peer.info {
|
||||
if case let .channel(peer) = peer.chatMainPeer, case .broadcast = peer.info {
|
||||
enabled = false
|
||||
}
|
||||
}
|
||||
@@ -380,34 +467,65 @@ private func mappedUpdateEntries(context: AccountContext, nodeInteraction: ChatL
|
||||
|
||||
var status: ContactsPeerItemStatus = .none
|
||||
if isSelecting, let itemPeer = itemPeer {
|
||||
let tagSummaryCount = summaryInfo.tagSummaryCount ?? 0
|
||||
let actionsSummaryCount = summaryInfo.actionsSummaryCount ?? 0
|
||||
let totalMentionCount = tagSummaryCount - actionsSummaryCount
|
||||
if let (string, multiline) = statusStringForPeerType(accountPeerId: context.account.peerId, strings: presentationData.strings, peer: itemPeer, isMuted: isRemovedFromTotalUnreadCount, isUnread: combinedReadState?.isUnread ?? false, isContact: isContact, hasUnseenMentions: totalMentionCount > 0, chatListFilters: filters) {
|
||||
if let (string, multiline) = statusStringForPeerType(accountPeerId: context.account.peerId, strings: presentationData.strings, peer: itemPeer, isMuted: isRemovedFromTotalUnreadCount, isUnread: combinedReadState?.isUnread ?? false, isContact: isContact, hasUnseenMentions: hasUnseenMentions, chatListFilters: filters) {
|
||||
status = .custom(string: string, multiline: multiline)
|
||||
} else {
|
||||
status = .none
|
||||
}
|
||||
}
|
||||
|
||||
return ListViewUpdateItem(index: entry.index, previousIndex: entry.previousIndex, item: ContactsPeerItem(presentationData: ItemListPresentationData(theme: presentationData.theme, fontSize: presentationData.fontSize, strings: presentationData.strings), sortOrder: presentationData.nameSortOrder, displayOrder: presentationData.nameDisplayOrder, context: context, peerMode: .generalSearch, peer: .peer(peer: itemPeer, chatPeer: chatPeer), status: status, enabled: enabled, selection: editing ? .selectable(selected: selected) : .none, editing: ContactsPeerItemEditing(editable: false, editing: false, revealed: false), index: nil, header: header, action: { _ in
|
||||
if let chatPeer = chatPeer {
|
||||
if editing {
|
||||
nodeInteraction.togglePeerSelected(chatPeer)
|
||||
} else {
|
||||
nodeInteraction.peerSelected(chatPeer, nil, nil)
|
||||
return ListViewUpdateItem(index: entry.index, previousIndex: entry.previousIndex, item: ContactsPeerItem(
|
||||
presentationData: ItemListPresentationData(theme: presentationData.theme, fontSize: presentationData.fontSize, strings: presentationData.strings),
|
||||
sortOrder: presentationData.nameSortOrder,
|
||||
displayOrder: presentationData.nameDisplayOrder,
|
||||
context: context,
|
||||
peerMode: .generalSearch,
|
||||
peer: .peer(peer: itemPeer, chatPeer: chatPeer),
|
||||
status: status,
|
||||
enabled: enabled,
|
||||
selection: editing ? .selectable(selected: selected) : .none,
|
||||
editing: ContactsPeerItemEditing(editable: false, editing: false, revealed: false),
|
||||
index: nil,
|
||||
header: header,
|
||||
action: { _ in
|
||||
if let chatPeer = chatPeer {
|
||||
if editing {
|
||||
nodeInteraction.togglePeerSelected(chatPeer)
|
||||
} else {
|
||||
nodeInteraction.peerSelected(chatPeer, nil, nil)
|
||||
}
|
||||
}
|
||||
}, disabledAction: { _ in
|
||||
if let chatPeer = chatPeer {
|
||||
nodeInteraction.disabledPeerSelected(chatPeer)
|
||||
}
|
||||
}
|
||||
}, disabledAction: { _ in
|
||||
if let chatPeer = chatPeer {
|
||||
nodeInteraction.disabledPeerSelected(chatPeer)
|
||||
}
|
||||
}), directionHint: entry.directionHint)
|
||||
), directionHint: entry.directionHint)
|
||||
}
|
||||
case let .HoleEntry(_, theme):
|
||||
return ListViewUpdateItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListHoleItem(theme: theme), directionHint: entry.directionHint)
|
||||
case let .GroupReferenceEntry(index, presentationData, groupId, peers, message, editing, unreadState, revealed, hiddenByDefault):
|
||||
return ListViewUpdateItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListItem(presentationData: presentationData, context: context, peerGroupId: peerGroupId, filterData: filterData, index: index, content: .groupReference(groupId: groupId, peers: peers, message: message, unreadState: unreadState, hiddenByDefault: hiddenByDefault), editing: editing, hasActiveRevealControls: false, selected: false, header: nil, enableContextActions: true, hiddenOffset: hiddenByDefault && !revealed, interaction: nodeInteraction), directionHint: entry.directionHint)
|
||||
case let .GroupReferenceEntry(index, presentationData, groupId, peers, message, editing, unreadCount, revealed, hiddenByDefault):
|
||||
return ListViewUpdateItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListItem(
|
||||
presentationData: presentationData,
|
||||
context: context,
|
||||
peerGroupId: peerGroupId,
|
||||
filterData: filterData,
|
||||
index: index,
|
||||
content: .groupReference(
|
||||
groupId: groupId,
|
||||
peers: peers,
|
||||
message: message,
|
||||
unreadCount: unreadCount,
|
||||
hiddenByDefault: hiddenByDefault
|
||||
),
|
||||
editing: editing,
|
||||
hasActiveRevealControls: false,
|
||||
selected: false,
|
||||
header: nil,
|
||||
enableContextActions: true,
|
||||
hiddenOffset: hiddenByDefault && !revealed,
|
||||
interaction: nodeInteraction
|
||||
), directionHint: entry.directionHint)
|
||||
case let .ArchiveIntro(presentationData):
|
||||
return ListViewUpdateItem(index: entry.index, previousIndex: entry.previousIndex, item: ChatListArchiveInfoItem(theme: presentationData.theme, strings: presentationData.strings), directionHint: entry.directionHint)
|
||||
case .HeaderEntry:
|
||||
@@ -434,7 +552,7 @@ private func mappedUpdateEntries(context: AccountContext, nodeInteraction: ChatL
|
||||
}
|
||||
}
|
||||
|
||||
private func mappedChatListNodeViewListTransition(context: AccountContext, nodeInteraction: ChatListNodeInteraction, peerGroupId: PeerGroupId, filterData: ChatListItemFilterData?, mode: ChatListNodeMode, transition: ChatListNodeViewTransition) -> ChatListNodeListViewTransition {
|
||||
private func mappedChatListNodeViewListTransition(context: AccountContext, nodeInteraction: ChatListNodeInteraction, peerGroupId: EngineChatList.Group, filterData: ChatListItemFilterData?, mode: ChatListNodeMode, transition: ChatListNodeViewTransition) -> ChatListNodeListViewTransition {
|
||||
return ChatListNodeListViewTransition(chatListView: transition.chatListView, deleteItems: transition.deleteItems, insertItems: mappedInsertEntries(context: context, nodeInteraction: nodeInteraction, peerGroupId: peerGroupId, filterData: filterData, mode: mode, entries: transition.insertEntries), updateItems: mappedUpdateEntries(context: context, nodeInteraction: nodeInteraction, peerGroupId: peerGroupId, filterData: filterData, mode: mode, entries: transition.updateEntries), options: transition.options, scrollToItem: transition.scrollToItem, stationaryItemRange: transition.stationaryItemRange, adjustScrollToFirstItem: transition.adjustScrollToFirstItem, animateCrossfade: transition.animateCrossfade)
|
||||
}
|
||||
|
||||
@@ -449,7 +567,7 @@ private final class ChatListOpaqueTransactionState {
|
||||
public enum ChatListSelectionOption {
|
||||
case previous(unread: Bool)
|
||||
case next(unread: Bool)
|
||||
case peerId(PeerId)
|
||||
case peerId(EnginePeer.Id)
|
||||
case index(Int)
|
||||
}
|
||||
|
||||
@@ -473,7 +591,7 @@ public enum ChatListNodeEmptyState: Equatable {
|
||||
public final class ChatListNode: ListView {
|
||||
private let fillPreloadItems: Bool
|
||||
private let context: AccountContext
|
||||
private let groupId: PeerGroupId
|
||||
private let groupId: EngineChatList.Group
|
||||
private let mode: ChatListNodeMode
|
||||
|
||||
private let _ready = ValuePromise<Bool>()
|
||||
@@ -488,18 +606,18 @@ public final class ChatListNode: ListView {
|
||||
return _contentsReady.get()
|
||||
}
|
||||
|
||||
public var peerSelected: ((Peer, Bool, Bool, ChatListNodeEntryPromoInfo?) -> Void)?
|
||||
public var disabledPeerSelected: ((Peer) -> Void)?
|
||||
public var peerSelected: ((EnginePeer, Bool, Bool, ChatListNodeEntryPromoInfo?) -> Void)?
|
||||
public var disabledPeerSelected: ((EnginePeer) -> Void)?
|
||||
public var additionalCategorySelected: ((Int) -> Void)?
|
||||
public var groupSelected: ((PeerGroupId) -> Void)?
|
||||
public var groupSelected: ((EngineChatList.Group) -> Void)?
|
||||
public var addContact: ((String) -> Void)?
|
||||
public var activateSearch: (() -> Void)?
|
||||
public var deletePeerChat: ((PeerId, Bool) -> Void)?
|
||||
public var updatePeerGrouping: ((PeerId, Bool) -> Void)?
|
||||
public var deletePeerChat: ((EnginePeer.Id, Bool) -> Void)?
|
||||
public var updatePeerGrouping: ((EnginePeer.Id, Bool) -> Void)?
|
||||
public var presentAlert: ((String) -> Void)?
|
||||
public var present: ((ViewController) -> Void)?
|
||||
public var toggleArchivedFolderHiddenByDefault: (() -> Void)?
|
||||
public var hidePsa: ((PeerId) -> Void)?
|
||||
public var hidePsa: ((EnginePeer.Id) -> Void)?
|
||||
public var activateChatPreview: ((ChatListItem, ASDisplayNode, ContextGesture?) -> Void)?
|
||||
|
||||
private var theme: PresentationTheme
|
||||
@@ -569,10 +687,10 @@ public final class ChatListNode: ListView {
|
||||
var isEmptyUpdated: ((ChatListNodeEmptyState, Bool, ContainedViewLayoutTransition) -> Void)?
|
||||
private var currentIsEmptyState: ChatListNodeEmptyState?
|
||||
|
||||
public var addedVisibleChatsWithPeerIds: (([PeerId]) -> Void)?
|
||||
public var addedVisibleChatsWithPeerIds: (([EnginePeer.Id]) -> Void)?
|
||||
|
||||
private let currentRemovingPeerId = Atomic<PeerId?>(value: nil)
|
||||
public func setCurrentRemovingPeerId(_ peerId: PeerId?) {
|
||||
private let currentRemovingPeerId = Atomic<EnginePeer.Id?>(value: nil)
|
||||
public func setCurrentRemovingPeerId(_ peerId: EnginePeer.Id?) {
|
||||
let _ = self.currentRemovingPeerId.swap(peerId)
|
||||
}
|
||||
|
||||
@@ -585,7 +703,7 @@ public final class ChatListNode: ListView {
|
||||
|
||||
var isSelectionGestureEnabled = true
|
||||
|
||||
public init(context: AccountContext, groupId: PeerGroupId, chatListFilter: ChatListFilter? = nil, previewing: Bool, fillPreloadItems: Bool, mode: ChatListNodeMode, theme: PresentationTheme, fontSize: PresentationFontSize, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, nameSortOrder: PresentationPersonNameOrder, nameDisplayOrder: PresentationPersonNameOrder, disableAnimations: Bool) {
|
||||
public init(context: AccountContext, groupId: EngineChatList.Group, chatListFilter: ChatListFilter? = nil, previewing: Bool, fillPreloadItems: Bool, mode: ChatListNodeMode, theme: PresentationTheme, fontSize: PresentationFontSize, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, nameSortOrder: PresentationPersonNameOrder, nameDisplayOrder: PresentationPersonNameOrder, disableAnimations: Bool) {
|
||||
self.context = context
|
||||
self.groupId = groupId
|
||||
self.chatListFilter = chatListFilter
|
||||
@@ -712,7 +830,7 @@ public final class ChatListNode: ListView {
|
||||
if let chatListFilter = chatListFilter {
|
||||
location = .filter(chatListFilter.id)
|
||||
} else {
|
||||
location = .group(groupId)
|
||||
location = .group(groupId._asGroup())
|
||||
}
|
||||
let _ = (context.engine.peers.toggleItemPinned(location: location, itemId: itemId)
|
||||
|> deliverOnMainQueue).start(next: { result in
|
||||
@@ -785,7 +903,7 @@ public final class ChatListNode: ListView {
|
||||
let chatListViewUpdate = self.chatListLocation.get()
|
||||
|> distinctUntilChanged
|
||||
|> mapToSignal { location -> Signal<(ChatListNodeViewUpdate, ChatListFilter?), NoError> in
|
||||
return chatListViewForLocation(groupId: groupId, location: location, account: context.account)
|
||||
return chatListViewForLocation(groupId: groupId._asGroup(), location: location, account: context.account)
|
||||
|> map { update in
|
||||
return (update, location.filter)
|
||||
}
|
||||
@@ -796,26 +914,29 @@ public final class ChatListNode: ListView {
|
||||
let previousHideArchivedFolderByDefault = Atomic<Bool?>(value: nil)
|
||||
let currentRemovingPeerId = self.currentRemovingPeerId
|
||||
|
||||
let savedMessagesPeer: Signal<Peer?, NoError>
|
||||
let savedMessagesPeer: Signal<EnginePeer?, NoError>
|
||||
if case let .peers(filter, _, _, _) = mode, filter.contains(.onlyWriteable) {
|
||||
savedMessagesPeer = context.account.postbox.loadedPeerWithId(context.account.peerId)
|
||||
|> map(Optional.init)
|
||||
|> map { peer in
|
||||
return peer.flatMap(EnginePeer.init)
|
||||
}
|
||||
} else {
|
||||
savedMessagesPeer = .single(nil)
|
||||
}
|
||||
|
||||
let hideArchivedFolderByDefault = context.account.postbox.preferencesView(keys: [ApplicationSpecificPreferencesKeys.chatArchiveSettings])
|
||||
|> map { view -> Bool in
|
||||
let settings: ChatArchiveSettings = view.values[ApplicationSpecificPreferencesKeys.chatArchiveSettings] as? ChatArchiveSettings ?? .default
|
||||
let settings: ChatArchiveSettings = view.values[ApplicationSpecificPreferencesKeys.chatArchiveSettings]?.get(ChatArchiveSettings.self) ?? .default
|
||||
return settings.isHiddenByDefault
|
||||
}
|
||||
|> distinctUntilChanged
|
||||
|
||||
let displayArchiveIntro: Signal<Bool, NoError>
|
||||
if Namespaces.PeerGroup.archive == groupId {
|
||||
if case .archive = groupId {
|
||||
displayArchiveIntro = context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.archiveIntroDismissedKey())
|
||||
|> map { entry -> Bool in
|
||||
if let value = entry.value as? ApplicationSpecificVariantNotice {
|
||||
if let value = entry.value?.get(ApplicationSpecificVariantNotice.self) {
|
||||
return !value.value
|
||||
} else {
|
||||
return true
|
||||
@@ -835,7 +956,7 @@ public final class ChatListNode: ListView {
|
||||
displayArchiveIntro = .single(false)
|
||||
}
|
||||
|
||||
let currentPeerId: PeerId = context.account.peerId
|
||||
let currentPeerId: EnginePeer.Id = context.account.peerId
|
||||
|
||||
let chatListNodeViewTransition = combineLatest(queue: viewProcessingQueue, hideArchivedFolderByDefault, displayArchiveIntro, savedMessagesPeer, chatListViewUpdate, self.statePromise.get())
|
||||
|> mapToQueue { (hideArchivedFolderByDefault, displayArchiveIntro, savedMessagesPeer, updateAndFilter, state) -> Signal<ChatListNodeListViewTransition, NoError> in
|
||||
@@ -843,7 +964,7 @@ public final class ChatListNode: ListView {
|
||||
|
||||
let previousHideArchivedFolderByDefaultValue = previousHideArchivedFolderByDefault.swap(hideArchivedFolderByDefault)
|
||||
|
||||
let (rawEntries, isLoading) = chatListNodeEntriesForView(update.view, state: state, savedMessagesPeer: savedMessagesPeer, foundPeers: state.foundPeers, hideArchivedFolderByDefault: hideArchivedFolderByDefault, displayArchiveIntro: displayArchiveIntro, mode: mode)
|
||||
let (rawEntries, isLoading) = chatListNodeEntriesForView(EngineChatList(update.view), state: state, savedMessagesPeer: savedMessagesPeer, foundPeers: state.foundPeers, hideArchivedFolderByDefault: hideArchivedFolderByDefault, displayArchiveIntro: displayArchiveIntro, mode: mode)
|
||||
let entries = rawEntries.filter { entry in
|
||||
switch entry {
|
||||
case let .PeerEntry(_, _, _, _, _, _, peer, _, _, _, _, _, _, _, _, _):
|
||||
@@ -858,7 +979,7 @@ public final class ChatListNode: ListView {
|
||||
|
||||
if filter.contains(.onlyGroups) {
|
||||
var isGroup: Bool = false
|
||||
if let peer = peer.chatMainPeer as? TelegramChannel, case .group = peer.info {
|
||||
if case let .channel(peer) = peer.chatMainPeer, case .group = peer.info {
|
||||
isGroup = true
|
||||
} else if peer.peerId.namespace == Namespaces.Peer.CloudGroup {
|
||||
isGroup = true
|
||||
@@ -869,7 +990,7 @@ public final class ChatListNode: ListView {
|
||||
}
|
||||
|
||||
if filter.contains(.onlyChannels) {
|
||||
if let peer = peer.chatMainPeer as? TelegramChannel, case .broadcast = peer.info {
|
||||
if case let .channel(peer) = peer.chatMainPeer, case .broadcast = peer.info {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
@@ -877,13 +998,13 @@ public final class ChatListNode: ListView {
|
||||
}
|
||||
|
||||
if filter.contains(.excludeChannels) {
|
||||
if let peer = peer.chatMainPeer as? TelegramChannel, case .broadcast = peer.info {
|
||||
if case let .channel(peer) = peer.chatMainPeer, case .broadcast = peer.info {
|
||||
}
|
||||
}
|
||||
|
||||
if filter.contains(.onlyWriteable) && filter.contains(.excludeDisabled) {
|
||||
if let peer = peer.peers[peer.peerId] {
|
||||
if !canSendMessagesToPeer(peer) {
|
||||
if !canSendMessagesToPeer(peer._asPeer()) {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
@@ -950,8 +1071,8 @@ public final class ChatListNode: ListView {
|
||||
if previousState.editing != state.editing {
|
||||
disableAnimations = false
|
||||
} else {
|
||||
var previousPinnedChats: [PeerId] = []
|
||||
var updatedPinnedChats: [PeerId] = []
|
||||
var previousPinnedChats: [EnginePeer.Id] = []
|
||||
var updatedPinnedChats: [EnginePeer.Id] = []
|
||||
|
||||
var didIncludeRemovingPeerId = false
|
||||
var didIncludeHiddenByDefaultArchive = false
|
||||
@@ -1095,18 +1216,18 @@ public final class ChatListNode: ListView {
|
||||
self.setChatListLocation(initialLocation)
|
||||
|
||||
let postbox = context.account.postbox
|
||||
let previousPeerCache = Atomic<[PeerId: Peer]>(value: [:])
|
||||
let previousPeerCache = Atomic<[EnginePeer.Id: EnginePeer]>(value: [:])
|
||||
let previousActivities = Atomic<ChatListNodePeerInputActivities?>(value: nil)
|
||||
self.activityStatusesDisposable = (context.account.allPeerInputActivities()
|
||||
|> mapToSignal { activitiesByPeerId -> Signal<[PeerId: [(Peer, PeerInputActivity)]], NoError> in
|
||||
|> mapToSignal { activitiesByPeerId -> Signal<[EnginePeer.Id: [(EnginePeer, PeerInputActivity)]], NoError> in
|
||||
var foundAllPeers = true
|
||||
var cachedResult: [PeerId: [(Peer, PeerInputActivity)]] = [:]
|
||||
var cachedResult: [EnginePeer.Id: [(EnginePeer, PeerInputActivity)]] = [:]
|
||||
previousPeerCache.with { dict -> Void in
|
||||
for (chatPeerId, activities) in activitiesByPeerId {
|
||||
guard case .global = chatPeerId.category else {
|
||||
continue
|
||||
}
|
||||
var cachedChatResult: [(Peer, PeerInputActivity)] = []
|
||||
var cachedChatResult: [(EnginePeer, PeerInputActivity)] = []
|
||||
for (peerId, activity) in activities {
|
||||
if let peer = dict[peerId] {
|
||||
cachedChatResult.append((peer, activity))
|
||||
@@ -1121,19 +1242,19 @@ public final class ChatListNode: ListView {
|
||||
if foundAllPeers {
|
||||
return .single(cachedResult)
|
||||
} else {
|
||||
return postbox.transaction { transaction -> [PeerId: [(Peer, PeerInputActivity)]] in
|
||||
var result: [PeerId: [(Peer, PeerInputActivity)]] = [:]
|
||||
var peerCache: [PeerId: Peer] = [:]
|
||||
return postbox.transaction { transaction -> [EnginePeer.Id: [(EnginePeer, PeerInputActivity)]] in
|
||||
var result: [EnginePeer.Id: [(EnginePeer, PeerInputActivity)]] = [:]
|
||||
var peerCache: [EnginePeer.Id: EnginePeer] = [:]
|
||||
for (chatPeerId, activities) in activitiesByPeerId {
|
||||
guard case .global = chatPeerId.category else {
|
||||
continue
|
||||
}
|
||||
var chatResult: [(Peer, PeerInputActivity)] = []
|
||||
var chatResult: [(EnginePeer, PeerInputActivity)] = []
|
||||
|
||||
for (peerId, activity) in activities {
|
||||
if let peer = transaction.getPeer(peerId) {
|
||||
chatResult.append((peer, activity))
|
||||
peerCache[peerId] = peer
|
||||
chatResult.append((EnginePeer(peer), activity))
|
||||
peerCache[peerId] = EnginePeer(peer)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1147,7 +1268,7 @@ public final class ChatListNode: ListView {
|
||||
|> map { activities -> ChatListNodePeerInputActivities? in
|
||||
return previousActivities.modify { current in
|
||||
var updated = false
|
||||
let currentList: [PeerId: [(Peer, PeerInputActivity)]] = current?.activities ?? [:]
|
||||
let currentList: [EnginePeer.Id: [(EnginePeer, PeerInputActivity)]] = current?.activities ?? [:]
|
||||
if currentList.count != activities.count {
|
||||
updated = true
|
||||
} else {
|
||||
@@ -1158,7 +1279,7 @@ public final class ChatListNode: ListView {
|
||||
break outer
|
||||
} else {
|
||||
for i in 0 ..< currentValue.count {
|
||||
if !arePeersEqual(currentValue[i].0, value[i].0) {
|
||||
if currentValue[i].0 != value[i].0 {
|
||||
updated = true
|
||||
break outer
|
||||
}
|
||||
@@ -1201,7 +1322,7 @@ public final class ChatListNode: ListView {
|
||||
let fromEntry = filteredEntries[filteredEntries.count - 1 - fromIndex]
|
||||
let toEntry = filteredEntries[filteredEntries.count - 1 - toIndex]
|
||||
|
||||
var referenceId: PinnedItemId?
|
||||
var referenceId: EngineChatList.PinnedItem.Id?
|
||||
var beforeAll = false
|
||||
switch toEntry {
|
||||
case let .PeerEntry(index, _, _, _, _, _, _, _, _, _, _, _, _, promoInfo, _, _):
|
||||
@@ -1219,7 +1340,7 @@ public final class ChatListNode: ListView {
|
||||
if let chatListFilter = chatListFilter {
|
||||
location = .filter(chatListFilter.id)
|
||||
} else {
|
||||
location = .group(groupId)
|
||||
location = .group(groupId._asGroup())
|
||||
}
|
||||
|
||||
let engine = strongSelf.context.engine
|
||||
@@ -1227,7 +1348,7 @@ public final class ChatListNode: ListView {
|
||||
|> mapToSignal { itemIds -> Signal<Bool, NoError> in
|
||||
var itemIds = itemIds
|
||||
|
||||
var itemId: PinnedItemId?
|
||||
var itemId: EngineChatList.PinnedItem.Id?
|
||||
switch fromEntry {
|
||||
case let .PeerEntry(index, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _):
|
||||
itemId = .peer(index.messageIndex.id.peerId)
|
||||
@@ -1312,7 +1433,7 @@ public final class ChatListNode: ListView {
|
||||
}
|
||||
|
||||
self.scrollToTopOptionPromise.set(combineLatest(
|
||||
renderedTotalUnreadCount(accountManager: self.context.sharedContext.accountManager, postbox: self.context.account.postbox) |> deliverOnMainQueue,
|
||||
renderedTotalUnreadCount(accountManager: self.context.sharedContext.accountManager, engine: self.context.engine) |> deliverOnMainQueue,
|
||||
self.scrolledAtTop.get()
|
||||
) |> map { badge, scrolledAtTop -> ChatListGlobalScrollOption in
|
||||
if scrolledAtTop {
|
||||
@@ -1595,7 +1716,7 @@ public final class ChatListNode: ListView {
|
||||
isEmptyState = .notEmpty(containsChats: containsChats)
|
||||
}
|
||||
|
||||
var insertedPeerIds: [PeerId] = []
|
||||
var insertedPeerIds: [EnginePeer.Id] = []
|
||||
for item in transition.insertItems {
|
||||
if let item = item.item as? ChatListItem {
|
||||
switch item.content {
|
||||
@@ -1754,25 +1875,25 @@ public final class ChatListNode: ListView {
|
||||
self.chatListLocation.set(location)
|
||||
}
|
||||
|
||||
private func relativeUnreadChatListIndex(position: ChatListRelativePosition) -> Signal<ChatListIndex?, NoError> {
|
||||
private func relativeUnreadChatListIndex(position: EngineChatList.RelativePosition) -> Signal<EngineChatList.Item.Index?, NoError> {
|
||||
let groupId = self.groupId
|
||||
let postbox = self.context.account.postbox
|
||||
return self.context.sharedContext.accountManager.transaction { transaction -> Signal<ChatListIndex?, NoError> in
|
||||
return self.context.sharedContext.accountManager.transaction { transaction -> Signal<EngineChatList.Item.Index?, NoError> in
|
||||
var filter = true
|
||||
if let inAppNotificationSettings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.inAppNotificationSettings) as? InAppNotificationSettings {
|
||||
if let inAppNotificationSettings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.inAppNotificationSettings)?.get(InAppNotificationSettings.self) {
|
||||
switch inAppNotificationSettings.totalUnreadCountDisplayStyle {
|
||||
case .filtered:
|
||||
filter = true
|
||||
}
|
||||
}
|
||||
return postbox.transaction { transaction -> ChatListIndex? in
|
||||
return transaction.getRelativeUnreadChatListIndex(filtered: filter, position: position, groupId: groupId)
|
||||
return postbox.transaction { transaction -> EngineChatList.Item.Index? in
|
||||
return transaction.getRelativeUnreadChatListIndex(filtered: filter, position: position._asPosition(), groupId: groupId._asGroup())
|
||||
}
|
||||
}
|
||||
|> switchToLatest
|
||||
}
|
||||
|
||||
public func scrollToEarliestUnread(earlierThan: ChatListIndex?) {
|
||||
public func scrollToEarliestUnread(earlierThan: EngineChatList.Item.Index?) {
|
||||
let _ = (relativeUnreadChatListIndex(position: .earlier(than: earlierThan)) |> deliverOnMainQueue).start(next: { [weak self] index in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
@@ -1804,9 +1925,9 @@ public final class ChatListNode: ListView {
|
||||
}
|
||||
|
||||
let entryCount = chatListView.filteredEntries.count
|
||||
var current: (ChatListIndex, Peer, Int)? = nil
|
||||
var previous: (ChatListIndex, Peer)? = nil
|
||||
var next: (ChatListIndex, Peer)? = nil
|
||||
var current: (EngineChatList.Item.Index, EnginePeer, Int)? = nil
|
||||
var previous: (EngineChatList.Item.Index, EnginePeer)? = nil
|
||||
var next: (EngineChatList.Item.Index, EnginePeer)? = nil
|
||||
|
||||
outer: for i in range.firstIndex ..< range.lastIndex {
|
||||
if i < 0 || i >= entryCount {
|
||||
@@ -1826,7 +1947,7 @@ public final class ChatListNode: ListView {
|
||||
|
||||
switch option {
|
||||
case .previous(unread: true), .next(unread: true):
|
||||
let position: ChatListRelativePosition
|
||||
let position: EngineChatList.RelativePosition
|
||||
if let current = current {
|
||||
if case .previous = option {
|
||||
position = .earlier(than: current.0)
|
||||
@@ -1838,11 +1959,11 @@ public final class ChatListNode: ListView {
|
||||
}
|
||||
let postbox = self.context.account.postbox
|
||||
let _ = (relativeUnreadChatListIndex(position: position)
|
||||
|> mapToSignal { index -> Signal<(ChatListIndex, Peer)?, NoError> in
|
||||
|> mapToSignal { index -> Signal<(EngineChatList.Item.Index, EnginePeer)?, NoError> in
|
||||
if let index = index {
|
||||
return postbox.transaction { transaction -> (ChatListIndex, Peer)? in
|
||||
return transaction.getPeer(index.messageIndex.id.peerId).flatMap { peer -> (ChatListIndex, Peer)? in
|
||||
(index, peer)
|
||||
return postbox.transaction { transaction -> (EngineChatList.Item.Index, EnginePeer)? in
|
||||
return transaction.getPeer(index.messageIndex.id.peerId).flatMap { peer -> (EngineChatList.Item.Index, EnginePeer)? in
|
||||
(index, EnginePeer(peer))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -1858,7 +1979,7 @@ public final class ChatListNode: ListView {
|
||||
strongSelf.peerSelected?(peer, false, false, nil)
|
||||
})
|
||||
case .previous(unread: false), .next(unread: false):
|
||||
var target: (ChatListIndex, Peer)? = nil
|
||||
var target: (EngineChatList.Item.Index, EnginePeer)? = nil
|
||||
if let current = current, entryCount > 1 {
|
||||
if current.2 > 0, case let .PeerEntry(index, _, _, _, _, _, peer, _, _, _, _, _, _, _, _, _) = chatListView.filteredEntries[current.2 - 1] {
|
||||
next = (index, peer.peer!)
|
||||
@@ -1882,8 +2003,8 @@ public final class ChatListNode: ListView {
|
||||
self.peerSelected?(target.1, false, false, nil)
|
||||
}
|
||||
case let .peerId(peerId):
|
||||
let _ = (self.context.account.postbox.transaction { transaction -> Peer? in
|
||||
return transaction.getPeer(peerId)
|
||||
let _ = (self.context.account.postbox.transaction { transaction -> EnginePeer? in
|
||||
return transaction.getPeer(peerId).flatMap(EnginePeer.init)
|
||||
}
|
||||
|> deliverOnMainQueue).start(next: { [weak self] peer in
|
||||
guard let strongSelf = self, let peer = peer else {
|
||||
@@ -1901,14 +2022,14 @@ public final class ChatListNode: ListView {
|
||||
guard let self = self else {
|
||||
return
|
||||
}
|
||||
let _ = (chatListViewForLocation(groupId: self.groupId, location: .initial(count: 10, filter: filter), account: self.context.account)
|
||||
let _ = (chatListViewForLocation(groupId: self.groupId._asGroup(), location: .initial(count: 10, filter: filter), account: self.context.account)
|
||||
|> take(1)
|
||||
|> deliverOnMainQueue).start(next: { update in
|
||||
let entries = update.view.entries
|
||||
if entries.count > index, case let .MessageEntry(index, _, _, _, _, renderedPeer, _, _, _, _) = entries[10 - index - 1] {
|
||||
let location: ChatListNodeLocation = .scroll(index: index, sourceIndex: .absoluteLowerBound, scrollPosition: .center(.top), animated: true, filter: filter)
|
||||
self.setChatListLocation(location)
|
||||
self.peerSelected?(renderedPeer.peer!, false, false, nil)
|
||||
self.peerSelected?(EnginePeer(renderedPeer.peer!), false, false, nil)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -1936,7 +2057,7 @@ public final class ChatListNode: ListView {
|
||||
}
|
||||
}
|
||||
|
||||
private func currentlyVisibleLatestChatListIndex() -> ChatListIndex? {
|
||||
private func currentlyVisibleLatestChatListIndex() -> EngineChatList.Item.Index? {
|
||||
guard let chatListView = (self.opaqueTransactionState as? ChatListOpaqueTransactionState)?.chatListView else {
|
||||
return nil
|
||||
}
|
||||
@@ -1958,8 +2079,8 @@ public final class ChatListNode: ListView {
|
||||
return nil
|
||||
}
|
||||
|
||||
private func peerAtPoint(_ point: CGPoint) -> Peer? {
|
||||
var resultPeer: Peer?
|
||||
private func peerAtPoint(_ point: CGPoint) -> EnginePeer? {
|
||||
var resultPeer: EnginePeer?
|
||||
self.forEachVisibleItemNode { itemNode in
|
||||
if resultPeer == nil, let itemNode = itemNode as? ListViewItemNode, itemNode.frame.contains(point) {
|
||||
if let itemNode = itemNode as? ChatListItemNode, let item = itemNode.item {
|
||||
@@ -1975,7 +2096,7 @@ public final class ChatListNode: ListView {
|
||||
return resultPeer
|
||||
}
|
||||
|
||||
private var selectionPanState: (selecting: Bool, initialPeerId: PeerId, toggledPeerIds: [[PeerId]])?
|
||||
private var selectionPanState: (selecting: Bool, initialPeerId: EnginePeer.Id, toggledPeerIds: [[EnginePeer.Id]])?
|
||||
private var selectionScrollActivationTimer: SwiftSignalKit.Timer?
|
||||
private var selectionScrollDisplayLink: ConstantDisplayLinkAnimator?
|
||||
private var selectionScrollDelta: CGFloat?
|
||||
@@ -2024,7 +2145,7 @@ public final class ChatListNode: ListView {
|
||||
self.selectionPanState = (state.selecting, state.initialPeerId, [])
|
||||
}
|
||||
} else if state.toggledPeerIds.last?.first != peer.id {
|
||||
var updatedToggledPeerIds: [[PeerId]] = []
|
||||
var updatedToggledPeerIds: [[EnginePeer.Id]] = []
|
||||
var previouslyToggled = false
|
||||
for i in (0 ..< state.toggledPeerIds.count) {
|
||||
if let peerId = state.toggledPeerIds[i].first {
|
||||
@@ -2100,7 +2221,7 @@ public final class ChatListNode: ListView {
|
||||
}
|
||||
}
|
||||
|
||||
private func statusStringForPeerType(accountPeerId: PeerId, strings: PresentationStrings, peer: Peer, isMuted: Bool, isUnread: Bool, isContact: Bool, hasUnseenMentions: Bool, chatListFilters: [ChatListFilter]?) -> (String, Bool)? {
|
||||
private func statusStringForPeerType(accountPeerId: EnginePeer.Id, strings: PresentationStrings, peer: EnginePeer, isMuted: Bool, isUnread: Bool, isContact: Bool, hasUnseenMentions: Bool, chatListFilters: [ChatListFilter]?) -> (String, Bool)? {
|
||||
if accountPeerId == peer.id {
|
||||
return nil
|
||||
}
|
||||
@@ -2109,7 +2230,7 @@ private func statusStringForPeerType(accountPeerId: PeerId, strings: Presentatio
|
||||
var result = ""
|
||||
for filter in chatListFilters {
|
||||
let predicate = chatListFilterPredicate(filter: filter.data)
|
||||
if predicate.includes(peer: peer, groupId: .root, isRemovedFromTotalUnreadCount: isMuted, isUnread: isUnread, isContact: isContact, messageTagSummaryResult: hasUnseenMentions) {
|
||||
if predicate.includes(peer: peer._asPeer(), groupId: .root, isRemovedFromTotalUnreadCount: isMuted, isUnread: isUnread, isContact: isContact, messageTagSummaryResult: hasUnseenMentions) {
|
||||
if !result.isEmpty {
|
||||
result.append(", ")
|
||||
}
|
||||
@@ -2126,7 +2247,7 @@ private func statusStringForPeerType(accountPeerId: PeerId, strings: Presentatio
|
||||
|
||||
if peer.id.isReplies {
|
||||
return nil
|
||||
} else if let user = peer as? TelegramUser {
|
||||
} else if case let .user(user) = peer {
|
||||
if user.botInfo != nil || user.flags.contains(.isSupport) {
|
||||
return (strings.ChatList_PeerTypeBot, false)
|
||||
} else if isContact {
|
||||
@@ -2134,15 +2255,15 @@ private func statusStringForPeerType(accountPeerId: PeerId, strings: Presentatio
|
||||
} else {
|
||||
return (strings.ChatList_PeerTypeNonContact, false)
|
||||
}
|
||||
} else if peer is TelegramSecretChat {
|
||||
} else if case .secretChat = peer {
|
||||
if isContact {
|
||||
return (strings.ChatList_PeerTypeContact, false)
|
||||
} else {
|
||||
return (strings.ChatList_PeerTypeNonContact, false)
|
||||
}
|
||||
} else if peer is TelegramGroup {
|
||||
} else if case .legacyGroup = peer {
|
||||
return (strings.ChatList_PeerTypeGroup, false)
|
||||
} else if let channel = peer as? TelegramChannel {
|
||||
} else if case let .channel(channel) = peer {
|
||||
if case .group = channel.info {
|
||||
return (strings.ChatList_PeerTypeGroup, false)
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import Postbox
|
||||
import TelegramCore
|
||||
import TelegramPresentationData
|
||||
import MergeLists
|
||||
@@ -10,13 +9,13 @@ enum ChatListNodeEntryId: Hashable {
|
||||
case Header
|
||||
case Hole(Int64)
|
||||
case PeerId(Int64)
|
||||
case GroupId(PeerGroupId)
|
||||
case GroupId(EngineChatList.Group)
|
||||
case ArchiveIntro
|
||||
case additionalCategory(Int)
|
||||
}
|
||||
|
||||
enum ChatListNodeEntrySortIndex: Comparable {
|
||||
case index(ChatListIndex)
|
||||
case index(EngineChatList.Item.Index)
|
||||
case additionalCategory(Int)
|
||||
|
||||
static func <(lhs: ChatListNodeEntrySortIndex, rhs: ChatListNodeEntrySortIndex) -> Bool {
|
||||
@@ -46,24 +45,24 @@ public enum ChatListNodeEntryPromoInfo: Equatable {
|
||||
|
||||
enum ChatListNodeEntry: Comparable, Identifiable {
|
||||
case HeaderEntry
|
||||
case PeerEntry(index: ChatListIndex, presentationData: ChatListPresentationData, messages: [Message], readState: CombinedPeerReadState?, isRemovedFromTotalUnreadCount: Bool, embeddedInterfaceState: StoredPeerChatInterfaceState?, peer: RenderedPeer, presence: PeerPresence?, summaryInfo: ChatListMessageTagSummaryInfo, editing: Bool, hasActiveRevealControls: Bool, selected: Bool, inputActivities: [(Peer, PeerInputActivity)]?, promoInfo: ChatListNodeEntryPromoInfo?, hasFailedMessages: Bool, isContact: Bool)
|
||||
case HoleEntry(ChatListHole, theme: PresentationTheme)
|
||||
case GroupReferenceEntry(index: ChatListIndex, presentationData: ChatListPresentationData, groupId: PeerGroupId, peers: [ChatListGroupReferencePeer], message: Message?, editing: Bool, unreadState: PeerGroupUnreadCountersCombinedSummary, revealed: Bool, hiddenByDefault: Bool)
|
||||
case PeerEntry(index: EngineChatList.Item.Index, presentationData: ChatListPresentationData, messages: [EngineMessage], readState: EnginePeerReadCounters?, isRemovedFromTotalUnreadCount: Bool, draftState: ChatListItemContent.DraftState?, peer: EngineRenderedPeer, presence: EnginePeer.Presence?, hasUnseenMentions: Bool, editing: Bool, hasActiveRevealControls: Bool, selected: Bool, inputActivities: [(EnginePeer, PeerInputActivity)]?, promoInfo: ChatListNodeEntryPromoInfo?, hasFailedMessages: Bool, isContact: Bool)
|
||||
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)
|
||||
case ArchiveIntro(presentationData: ChatListPresentationData)
|
||||
case AdditionalCategory(index: Int, id: Int, title: String, image: UIImage?, appearance: ChatListNodeAdditionalCategory.Appearance, selected: Bool, presentationData: ChatListPresentationData)
|
||||
|
||||
var sortIndex: ChatListNodeEntrySortIndex {
|
||||
switch self {
|
||||
case .HeaderEntry:
|
||||
return .index(ChatListIndex.absoluteUpperBound)
|
||||
return .index(EngineChatList.Item.Index.absoluteUpperBound)
|
||||
case let .PeerEntry(index, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _):
|
||||
return .index(index)
|
||||
case let .HoleEntry(hole, _):
|
||||
return .index(ChatListIndex(pinningIndex: nil, messageIndex: hole.index))
|
||||
case let .HoleEntry(holeIndex, _):
|
||||
return .index(EngineChatList.Item.Index(pinningIndex: nil, messageIndex: holeIndex))
|
||||
case let .GroupReferenceEntry(index, _, _, _, _, _, _, _, _):
|
||||
return .index(index)
|
||||
case .ArchiveIntro:
|
||||
return .index(ChatListIndex.absoluteUpperBound.successor)
|
||||
return .index(EngineChatList.Item.Index.absoluteUpperBound.successor)
|
||||
case let .AdditionalCategory(index, _, _, _, _, _, _):
|
||||
return .additionalCategory(index)
|
||||
}
|
||||
@@ -75,8 +74,8 @@ enum ChatListNodeEntry: Comparable, Identifiable {
|
||||
return .Header
|
||||
case let .PeerEntry(index, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _):
|
||||
return .PeerId(index.messageIndex.id.peerId.toInt64())
|
||||
case let .HoleEntry(hole, _):
|
||||
return .Hole(Int64(hole.index.id.id))
|
||||
case let .HoleEntry(holeIndex, _):
|
||||
return .Hole(Int64(holeIndex.id.id))
|
||||
case let .GroupReferenceEntry(_, _, groupId, _, _, _, _, _, _):
|
||||
return .GroupId(groupId)
|
||||
case .ArchiveIntro:
|
||||
@@ -137,7 +136,7 @@ enum ChatListNodeEntry: Comparable, Identifiable {
|
||||
return false
|
||||
}
|
||||
if let lhsPeerPresence = lhsPresence, let rhsPeerPresence = rhsPresence {
|
||||
if !lhsPeerPresence.isEqual(to: rhsPeerPresence) {
|
||||
if lhsPeerPresence != rhsPeerPresence {
|
||||
return false
|
||||
}
|
||||
} else if (lhsPresence != nil) != (rhsPresence != nil) {
|
||||
@@ -170,7 +169,7 @@ enum ChatListNodeEntry: Comparable, Identifiable {
|
||||
return false
|
||||
}
|
||||
for i in 0 ..< lhsInputActivities.count {
|
||||
if !arePeersEqual(lhsInputActivities[i].0, rhsInputActivities[i].0) {
|
||||
if lhsInputActivities[i].0 != rhsInputActivities[i].0 {
|
||||
return false
|
||||
}
|
||||
if lhsInputActivities[i].1 != rhsInputActivities[i].1 {
|
||||
@@ -273,115 +272,149 @@ enum ChatListNodeEntry: Comparable, Identifiable {
|
||||
}
|
||||
}
|
||||
|
||||
private func offsetPinnedIndex(_ index: ChatListIndex, offset: UInt16) -> ChatListIndex {
|
||||
private func offsetPinnedIndex(_ index: EngineChatList.Item.Index, offset: UInt16) -> EngineChatList.Item.Index {
|
||||
if let pinningIndex = index.pinningIndex {
|
||||
return ChatListIndex(pinningIndex: pinningIndex + offset, messageIndex: index.messageIndex)
|
||||
return EngineChatList.Item.Index(pinningIndex: pinningIndex + offset, messageIndex: index.messageIndex)
|
||||
} else {
|
||||
return index
|
||||
}
|
||||
}
|
||||
|
||||
func chatListNodeEntriesForView(_ view: ChatListView, state: ChatListNodeState, savedMessagesPeer: Peer?, foundPeers: [(Peer, Peer?)], hideArchivedFolderByDefault: Bool, displayArchiveIntro: Bool, mode: ChatListNodeMode) -> (entries: [ChatListNodeEntry], loading: Bool) {
|
||||
func chatListNodeEntriesForView(_ view: EngineChatList, state: ChatListNodeState, savedMessagesPeer: EnginePeer?, foundPeers: [(EnginePeer, EnginePeer?)], hideArchivedFolderByDefault: Bool, displayArchiveIntro: Bool, mode: ChatListNodeMode) -> (entries: [ChatListNodeEntry], loading: Bool) {
|
||||
var result: [ChatListNodeEntry] = []
|
||||
|
||||
var pinnedIndexOffset: UInt16 = 0
|
||||
|
||||
if view.laterIndex == nil, case .chatList = mode {
|
||||
if !view.hasLater, case .chatList = mode {
|
||||
var groupEntryCount = 0
|
||||
for _ in view.groupEntries {
|
||||
for _ in view.groupItems {
|
||||
groupEntryCount += 1
|
||||
}
|
||||
pinnedIndexOffset += UInt16(groupEntryCount)
|
||||
}
|
||||
|
||||
let filteredAdditionalItemEntries = view.additionalItemEntries.filter { item -> Bool in
|
||||
return item.info.peerId != state.hiddenPsaPeerId
|
||||
let filteredAdditionalItemEntries = view.additionalItems.filter { item -> Bool in
|
||||
return item.item.renderedPeer.peerId != state.hiddenPsaPeerId
|
||||
}
|
||||
|
||||
var foundPeerIds = Set<PeerId>()
|
||||
var foundPeerIds = Set<EnginePeer.Id>()
|
||||
for peer in foundPeers {
|
||||
foundPeerIds.insert(peer.0.id)
|
||||
}
|
||||
|
||||
if view.laterIndex == nil && savedMessagesPeer == nil {
|
||||
if !view.hasLater && savedMessagesPeer == nil {
|
||||
pinnedIndexOffset += UInt16(filteredAdditionalItemEntries.count)
|
||||
}
|
||||
var filterAfterHole = false
|
||||
loop: for entry in view.entries {
|
||||
switch entry {
|
||||
case let .MessageEntry(index, messages, combinedReadState, isRemovedFromTotalUnreadCount, embeddedState, peer, peerPresence, summaryInfo, hasFailed, isContact):
|
||||
if let savedMessagesPeer = savedMessagesPeer, savedMessagesPeer.id == index.messageIndex.id.peerId || foundPeerIds.contains(index.messageIndex.id.peerId) {
|
||||
continue loop
|
||||
}
|
||||
if state.pendingRemovalPeerIds.contains(index.messageIndex.id.peerId) {
|
||||
continue loop
|
||||
}
|
||||
var updatedMessages = messages
|
||||
var updatedCombinedReadState = combinedReadState
|
||||
if state.pendingClearHistoryPeerIds.contains(index.messageIndex.id.peerId) {
|
||||
updatedMessages = []
|
||||
updatedCombinedReadState = nil
|
||||
}
|
||||
result.append(.PeerEntry(index: offsetPinnedIndex(index, offset: pinnedIndexOffset), presentationData: state.presentationData, messages: updatedMessages, readState: updatedCombinedReadState, isRemovedFromTotalUnreadCount: isRemovedFromTotalUnreadCount, embeddedInterfaceState: embeddedState, peer: peer, presence: peerPresence, summaryInfo: summaryInfo, editing: state.editing, hasActiveRevealControls: index.messageIndex.id.peerId == state.peerIdWithRevealedOptions, selected: state.selectedPeerIds.contains(index.messageIndex.id.peerId), inputActivities: state.peerInputActivities?.activities[index.messageIndex.id.peerId], promoInfo: nil, hasFailedMessages: hasFailed, isContact: isContact))
|
||||
case let .HoleEntry(hole):
|
||||
if hole.index.timestamp == Int32.max - 1 {
|
||||
//return ([.HeaderEntry], true)
|
||||
}
|
||||
filterAfterHole = true
|
||||
result.append(.HoleEntry(hole, theme: state.presentationData.theme))
|
||||
loop: for entry in view.items {
|
||||
//case let .MessageEntry(index, messages, combinedReadState, isRemovedFromTotalUnreadCount, embeddedState, peer, peerPresence, summaryInfo, hasFailed, isContact):
|
||||
if let savedMessagesPeer = savedMessagesPeer, savedMessagesPeer.id == entry.index.messageIndex.id.peerId || foundPeerIds.contains(entry.index.messageIndex.id.peerId) {
|
||||
continue loop
|
||||
}
|
||||
if state.pendingRemovalPeerIds.contains(entry.index.messageIndex.id.peerId) {
|
||||
continue loop
|
||||
}
|
||||
var updatedMessages = entry.messages
|
||||
var updatedCombinedReadState = entry.readCounters
|
||||
if state.pendingClearHistoryPeerIds.contains(entry.index.messageIndex.id.peerId) {
|
||||
updatedMessages = []
|
||||
updatedCombinedReadState = nil
|
||||
}
|
||||
|
||||
var draftState: ChatListItemContent.DraftState?
|
||||
if let draftText = entry.draftText {
|
||||
draftState = ChatListItemContent.DraftState(text: draftText)
|
||||
}
|
||||
|
||||
result.append(.PeerEntry(index: offsetPinnedIndex(entry.index, offset: pinnedIndexOffset), presentationData: state.presentationData, messages: updatedMessages, readState: updatedCombinedReadState, isRemovedFromTotalUnreadCount: entry.isMuted, draftState: draftState, peer: entry.renderedPeer, presence: entry.presence, hasUnseenMentions: entry.hasUnseenMentions, editing: state.editing, hasActiveRevealControls: entry.index.messageIndex.id.peerId == state.peerIdWithRevealedOptions, selected: state.selectedPeerIds.contains(entry.index.messageIndex.id.peerId), inputActivities: state.peerInputActivities?.activities[entry.index.messageIndex.id.peerId], promoInfo: nil, hasFailedMessages: entry.hasFailed, isContact: entry.isContact))
|
||||
}
|
||||
if view.laterIndex == nil {
|
||||
if !view.hasLater {
|
||||
var pinningIndex: UInt16 = UInt16(pinnedIndexOffset == 0 ? 0 : (pinnedIndexOffset - 1))
|
||||
|
||||
if let savedMessagesPeer = savedMessagesPeer {
|
||||
if !foundPeers.isEmpty {
|
||||
var foundPinningIndex: UInt16 = UInt16(foundPeers.count)
|
||||
for peer in foundPeers.reversed() {
|
||||
var peers: [PeerId: Peer] = [peer.0.id: peer.0]
|
||||
var peers: [EnginePeer.Id: EnginePeer] = [peer.0.id: peer.0]
|
||||
if let chatPeer = peer.1 {
|
||||
peers[chatPeer.id] = chatPeer
|
||||
}
|
||||
|
||||
let messageIndex = MessageIndex(id: MessageId(peerId: peer.0.id, namespace: 0, id: 0), timestamp: 1)
|
||||
result.append(.PeerEntry(index: ChatListIndex(pinningIndex: foundPinningIndex, messageIndex: messageIndex), presentationData: state.presentationData, messages: [], readState: nil, isRemovedFromTotalUnreadCount: false, embeddedInterfaceState: nil, peer: RenderedPeer(peerId: peer.0.id, peers: SimpleDictionary(peers)), presence: nil, summaryInfo: ChatListMessageTagSummaryInfo(), editing: state.editing, hasActiveRevealControls: false, selected: state.selectedPeerIds.contains(peer.0.id), inputActivities: nil, promoInfo: nil, hasFailedMessages: false, isContact: false))
|
||||
let messageIndex = EngineMessage.Index(id: EngineMessage.Id(peerId: peer.0.id, namespace: 0, id: 0), timestamp: 1)
|
||||
result.append(.PeerEntry(
|
||||
index: EngineChatList.Item.Index(pinningIndex: foundPinningIndex, messageIndex: messageIndex),
|
||||
presentationData: state.presentationData,
|
||||
messages: [],
|
||||
readState: nil,
|
||||
isRemovedFromTotalUnreadCount: false,
|
||||
draftState: nil,
|
||||
peer: EngineRenderedPeer(peerId: peer.0.id, peers: peers),
|
||||
presence: nil,
|
||||
hasUnseenMentions: false,
|
||||
editing: state.editing,
|
||||
hasActiveRevealControls: false,
|
||||
selected: state.selectedPeerIds.contains(peer.0.id),
|
||||
inputActivities: nil,
|
||||
promoInfo: nil,
|
||||
hasFailedMessages: false,
|
||||
isContact: false
|
||||
))
|
||||
if foundPinningIndex != 0 {
|
||||
foundPinningIndex -= 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.append(.PeerEntry(index: ChatListIndex.absoluteUpperBound.predecessor, presentationData: state.presentationData, messages: [], readState: nil, isRemovedFromTotalUnreadCount: false, embeddedInterfaceState: nil, peer: RenderedPeer(peerId: savedMessagesPeer.id, peers: SimpleDictionary([savedMessagesPeer.id: savedMessagesPeer])), presence: nil, summaryInfo: ChatListMessageTagSummaryInfo(), editing: state.editing, hasActiveRevealControls: false, selected: state.selectedPeerIds.contains(savedMessagesPeer.id), inputActivities: nil, promoInfo: nil, hasFailedMessages: false, isContact: false))
|
||||
result.append(.PeerEntry(index: EngineChatList.Item.Index.absoluteUpperBound.predecessor, presentationData: state.presentationData, messages: [], readState: nil, isRemovedFromTotalUnreadCount: false, draftState: nil, peer: EngineRenderedPeer(peerId: savedMessagesPeer.id, peers: [savedMessagesPeer.id: savedMessagesPeer]), presence: nil, hasUnseenMentions: false, editing: state.editing, hasActiveRevealControls: false, selected: state.selectedPeerIds.contains(savedMessagesPeer.id), inputActivities: nil, promoInfo: nil, hasFailedMessages: false, isContact: false))
|
||||
} else {
|
||||
if !filteredAdditionalItemEntries.isEmpty {
|
||||
for item in filteredAdditionalItemEntries.reversed() {
|
||||
guard let info = item.info as? PromoChatListItem else {
|
||||
continue
|
||||
}
|
||||
let promoInfo: ChatListNodeEntryPromoInfo
|
||||
switch info.kind {
|
||||
switch item.promoInfo.content {
|
||||
case .proxy:
|
||||
promoInfo = .proxy
|
||||
case let .psa(type, message):
|
||||
promoInfo = .psa(type: type, message: message)
|
||||
}
|
||||
switch item.entry {
|
||||
case let .MessageEntry(index, messages, combinedReadState, isRemovedFromTotalUnreadCount, embeddedState, peer, peerPresence, summaryInfo, hasFailed, isContact):
|
||||
result.append(.PeerEntry(index: ChatListIndex(pinningIndex: pinningIndex, messageIndex: index.messageIndex), presentationData: state.presentationData, messages: messages, readState: combinedReadState, isRemovedFromTotalUnreadCount: isRemovedFromTotalUnreadCount, embeddedInterfaceState: embeddedState, peer: peer, presence: peerPresence, summaryInfo: summaryInfo, editing: state.editing, hasActiveRevealControls: index.messageIndex.id.peerId == state.peerIdWithRevealedOptions, selected: state.selectedPeerIds.contains(index.messageIndex.id.peerId), inputActivities: state.peerInputActivities?.activities[index.messageIndex.id.peerId], promoInfo: promoInfo, hasFailedMessages: hasFailed, isContact: isContact))
|
||||
if pinningIndex != 0 {
|
||||
pinningIndex -= 1
|
||||
}
|
||||
default:
|
||||
break
|
||||
let draftState = item.item.draftText.flatMap(ChatListItemContent.DraftState.init(text:))
|
||||
result.append(.PeerEntry(
|
||||
index: EngineChatList.Item.Index(pinningIndex: pinningIndex, messageIndex: item.item.index.messageIndex),
|
||||
presentationData: state.presentationData,
|
||||
messages: item.item.messages,
|
||||
readState: item.item.readCounters,
|
||||
isRemovedFromTotalUnreadCount: item.item.isMuted,
|
||||
draftState: draftState,
|
||||
peer: item.item.renderedPeer,
|
||||
presence: item.item.presence,
|
||||
hasUnseenMentions: item.item.hasUnseenMentions,
|
||||
editing: state.editing,
|
||||
hasActiveRevealControls: item.item.index.messageIndex.id.peerId == state.peerIdWithRevealedOptions,
|
||||
selected: state.selectedPeerIds.contains(item.item.index.messageIndex.id.peerId),
|
||||
inputActivities: state.peerInputActivities?.activities[item.item.index.messageIndex.id.peerId],
|
||||
promoInfo: promoInfo,
|
||||
hasFailedMessages: item.item.hasFailed,
|
||||
isContact: item.item.isContact
|
||||
))
|
||||
if pinningIndex != 0 {
|
||||
pinningIndex -= 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if view.laterIndex == nil, case .chatList = mode {
|
||||
for groupReference in view.groupEntries {
|
||||
let messageIndex = MessageIndex(id: MessageId(peerId: PeerId(0), namespace: 0, id: 0), timestamp: 1)
|
||||
result.append(.GroupReferenceEntry(index: ChatListIndex(pinningIndex: pinningIndex, messageIndex: messageIndex), presentationData: state.presentationData, groupId: groupReference.groupId, peers: groupReference.renderedPeers, message: groupReference.message, editing: state.editing, unreadState: groupReference.unreadState, revealed: state.archiveShouldBeTemporaryRevealed, hiddenByDefault: hideArchivedFolderByDefault))
|
||||
if !view.hasLater, case .chatList = mode {
|
||||
for groupReference in view.groupItems {
|
||||
let messageIndex = EngineMessage.Index(id: EngineMessage.Id(peerId: EnginePeer.Id(0), namespace: 0, id: 0), timestamp: 1)
|
||||
result.append(.GroupReferenceEntry(
|
||||
index: EngineChatList.Item.Index(pinningIndex: pinningIndex, messageIndex: messageIndex),
|
||||
presentationData: state.presentationData,
|
||||
groupId: groupReference.id,
|
||||
peers: groupReference.items,
|
||||
message: groupReference.topMessage,
|
||||
editing: state.editing,
|
||||
unreadCount: groupReference.unreadCount,
|
||||
revealed: state.archiveShouldBeTemporaryRevealed,
|
||||
hiddenByDefault: hideArchivedFolderByDefault
|
||||
))
|
||||
if pinningIndex != 0 {
|
||||
pinningIndex -= 1
|
||||
}
|
||||
@@ -394,7 +427,7 @@ func chatListNodeEntriesForView(_ view: ChatListView, state: ChatListNodeState,
|
||||
result.append(.HeaderEntry)
|
||||
}
|
||||
|
||||
if view.laterIndex == nil, case let .peers(_, _, additionalCategories,
|
||||
if !view.hasLater, case let .peers(_, _, additionalCategories,
|
||||
_) = mode {
|
||||
var index = 0
|
||||
for category in additionalCategories.reversed(){
|
||||
@@ -403,35 +436,11 @@ func chatListNodeEntriesForView(_ view: ChatListView, state: ChatListNodeState,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var isLoading: Bool = false
|
||||
|
||||
if filterAfterHole {
|
||||
var seenHole = false
|
||||
for i in (0 ..< result.count).reversed() {
|
||||
if seenHole {
|
||||
result.remove(at: i)
|
||||
} else {
|
||||
switch result[i] {
|
||||
case .HeaderEntry:
|
||||
break
|
||||
case .ArchiveIntro, .AdditionalCategory, .GroupReferenceEntry:
|
||||
break
|
||||
case .PeerEntry:
|
||||
break
|
||||
case .HoleEntry:
|
||||
isLoading = true
|
||||
seenHole = true
|
||||
result.remove(at: i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if result.count >= 1, case .HoleEntry = result[result.count - 1] {
|
||||
return ([.HeaderEntry], true)
|
||||
} else if result.count == 1, case .HoleEntry = result[0] {
|
||||
return ([.HeaderEntry], true)
|
||||
}
|
||||
return (result, isLoading)
|
||||
return (result, view.isLoading)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import AsyncDisplayKit
|
||||
import Postbox
|
||||
import TelegramCore
|
||||
import Display
|
||||
import SwiftSignalKit
|
||||
@@ -20,7 +19,7 @@ final class ChatListInputActivitiesNode: ASDisplayNode {
|
||||
self.addSubnode(self.activityNode)
|
||||
}
|
||||
|
||||
func asyncLayout() -> (CGSize, ChatListPresentationData, UIColor, PeerId, [(Peer, PeerInputActivity)]) -> (CGSize, () -> Void) {
|
||||
func asyncLayout() -> (CGSize, ChatListPresentationData, UIColor, EnginePeer.Id, [(EnginePeer, PeerInputActivity)]) -> (CGSize, () -> Void) {
|
||||
return { [weak self] boundingSize, presentationData, color, peerId, activities in
|
||||
let strings = presentationData.strings
|
||||
|
||||
|
||||
Reference in New Issue
Block a user