mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-22 20:18:44 +00:00
Support groups in contact list
This commit is contained in:
@@ -44,7 +44,7 @@ final class ComposeControllerNode: ASDisplayNode {
|
||||
ContactListAdditionalOption(title: self.presentationData.strings.Compose_NewChannel, icon: .generic(UIImage(bundleImageName: "Contact List/CreateChannelActionIcon")!), action: {
|
||||
openCreateNewChannelImpl?()
|
||||
})
|
||||
])), displayPermissionPlaceholder: false)
|
||||
], includeChatList: false)), displayPermissionPlaceholder: false)
|
||||
|
||||
super.init()
|
||||
|
||||
|
||||
@@ -501,7 +501,7 @@ private func contactListNodeEntries(accountPeer: Peer?, peers: [ContactListPeer]
|
||||
for i in 0 ..< options.count {
|
||||
entries.append(.option(i, options[i], commonHeader, theme, strings))
|
||||
}
|
||||
case let .natural(options):
|
||||
case let .natural(options, _):
|
||||
let sortedPeers = peers.sorted(by: { lhs, rhs in
|
||||
let result = lhs.indexName.isLessThan(other: rhs.indexName, ordering: sortOrder)
|
||||
if result == .orderedSame {
|
||||
@@ -698,7 +698,7 @@ public struct ContactListAdditionalOption: Equatable {
|
||||
|
||||
enum ContactListPresentation {
|
||||
case orderedByPresence(options: [ContactListAdditionalOption])
|
||||
case natural(options: [ContactListAdditionalOption])
|
||||
case natural(options: [ContactListAdditionalOption], includeChatList: Bool)
|
||||
case search(signal: Signal<String, NoError>, searchChatList: Bool, searchDeviceContacts: Bool, searchGroups: Bool)
|
||||
|
||||
var sortOrder: ContactsSortOrder? {
|
||||
@@ -937,8 +937,10 @@ final class ContactListNode: ASDisplayNode {
|
||||
transition = presentation
|
||||
|> mapToSignal { presentation in
|
||||
var generateSections = false
|
||||
if case .natural = presentation {
|
||||
var includeChatList = false
|
||||
if case let .natural(natural) = presentation {
|
||||
generateSections = true
|
||||
includeChatList = natural.includeChatList
|
||||
}
|
||||
|
||||
if case let .search(query, searchChatList, searchDeviceContacts, searchGroups) = presentation {
|
||||
@@ -1122,10 +1124,45 @@ final class ContactListNode: ASDisplayNode {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return (combineLatest(self.contactPeersViewPromise.get(), selectionStateSignal, themeAndStringsPromise.get(), contactsAuthorization.get(), contactsWarningSuppressed.get())
|
||||
|> mapToQueue { view, selectionState, themeAndStrings, authorizationStatus, warningSuppressed -> Signal<ContactsListNodeTransition, NoError> in
|
||||
let chatListSignal: Signal<[(Peer, Int32)], NoError>
|
||||
if includeChatList {
|
||||
chatListSignal = self.context.account.viewTracker.tailChatListView(groupId: .root, count: 100)
|
||||
|> take(1)
|
||||
|> mapToSignal { view, _ -> Signal<[(Peer, Int32)], NoError> in
|
||||
return context.account.postbox.transaction { transaction -> [(Peer, Int32)] in
|
||||
var peers: [(Peer, Int32)] = []
|
||||
for entry in view.entries {
|
||||
switch entry {
|
||||
case let .MessageEntry(messageEntry):
|
||||
if let peer = messageEntry.5.peer {
|
||||
if peer is TelegramGroup {
|
||||
peers.append((peer, 0))
|
||||
} else if let channel = peer as? TelegramChannel, case .group = channel.info {
|
||||
var memberCount: Int32 = 0
|
||||
if let cachedData = transaction.getPeerCachedData(peerId: peer.id) as? CachedChannelData {
|
||||
memberCount = cachedData.participantsSummary.memberCount ?? 0
|
||||
}
|
||||
peers.append((peer, memberCount))
|
||||
}
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
return peers
|
||||
}
|
||||
}
|
||||
} else {
|
||||
chatListSignal = .single([])
|
||||
}
|
||||
|
||||
return (combineLatest(self.contactPeersViewPromise.get(), chatListSignal, selectionStateSignal, themeAndStringsPromise.get(), contactsAuthorization.get(), contactsWarningSuppressed.get())
|
||||
|> mapToQueue { view, chatListPeers, selectionState, themeAndStrings, authorizationStatus, warningSuppressed -> Signal<ContactsListNodeTransition, NoError> in
|
||||
let signal = deferred { () -> Signal<ContactsListNodeTransition, NoError> in
|
||||
var peers = view.peers.map({ ContactListPeer.peer(peer: $0, isGlobal: false, participantCount: nil) })
|
||||
for (peer, memberCount) in chatListPeers {
|
||||
peers.append(.peer(peer: peer, isGlobal: false, participantCount: memberCount))
|
||||
}
|
||||
var existingPeerIds = Set<PeerId>()
|
||||
var disabledPeerIds = Set<PeerId>()
|
||||
for filter in filters {
|
||||
|
||||
@@ -49,8 +49,10 @@ final class ContactMultiselectionControllerNode: ASDisplayNode {
|
||||
self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
|
||||
let placeholder: String
|
||||
var includeChatList = false
|
||||
switch mode {
|
||||
case let .peerSelection(_, searchGroups):
|
||||
includeChatList = searchGroups
|
||||
if searchGroups {
|
||||
placeholder = self.presentationData.strings.Contacts_SearchUsersAndGroupsLabel
|
||||
} else {
|
||||
@@ -60,7 +62,7 @@ final class ContactMultiselectionControllerNode: ASDisplayNode {
|
||||
placeholder = self.presentationData.strings.Compose_TokenListPlaceholder
|
||||
}
|
||||
|
||||
self.contactListNode = ContactListNode(context: context, presentation: .single(.natural(options: options)), filters: filters, selectionState: ContactListNodeGroupSelectionState())
|
||||
self.contactListNode = ContactListNode(context: context, presentation: .single(.natural(options: options, includeChatList: includeChatList)), filters: filters, selectionState: ContactListNodeGroupSelectionState())
|
||||
self.tokenListNode = EditableTokenListNode(theme: EditableTokenListNodeTheme(backgroundColor: self.presentationData.theme.rootController.navigationBar.backgroundColor, separatorColor: self.presentationData.theme.rootController.navigationBar.separatorColor, placeholderTextColor: self.presentationData.theme.list.itemPlaceholderTextColor, primaryTextColor: self.presentationData.theme.list.itemPrimaryTextColor, selectedTextColor: self.presentationData.theme.list.itemAccentColor, keyboardColor: self.presentationData.theme.chatList.searchBarKeyboardColor), placeholder: placeholder)
|
||||
|
||||
super.init()
|
||||
|
||||
@@ -39,7 +39,7 @@ final class ContactSelectionControllerNode: ASDisplayNode {
|
||||
self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
self.displayDeviceContacts = displayDeviceContacts
|
||||
|
||||
self.contactListNode = ContactListNode(context: context, presentation: .single(.natural(options: options)))
|
||||
self.contactListNode = ContactListNode(context: context, presentation: .single(.natural(options: options, includeChatList: false)))
|
||||
|
||||
self.dimNode = ASDisplayNode()
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ final class ContactsControllerNode: ASDisplayNode {
|
||||
case .presence:
|
||||
return .orderedByPresence(options: options)
|
||||
case .natural:
|
||||
return .natural(options: options)
|
||||
return .natural(options: options, includeChatList: false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -326,7 +326,7 @@ final class PeerSelectionControllerNode: ASDisplayNode {
|
||||
self.recursivelyEnsureDisplaySynchronously(true)
|
||||
contactListNode.enableUpdates = true
|
||||
} else {
|
||||
let contactListNode = ContactListNode(context: context, presentation: .single(.natural(options: [])))
|
||||
let contactListNode = ContactListNode(context: context, presentation: .single(.natural(options: [], includeChatList: false)))
|
||||
self.contactListNode = contactListNode
|
||||
contactListNode.enableUpdates = true
|
||||
contactListNode.activateSearch = { [weak self] in
|
||||
|
||||
Reference in New Issue
Block a user