@@ -98,7 +98,7 @@ private enum ContactListNodeEntry: Comparable, Identifiable {
9898 case permissionInfo( PresentationTheme , String , String , Bool )
9999 case permissionEnable( PresentationTheme , String )
100100 case option( Int , ContactListAdditionalOption , ListViewItemHeader ? , PresentationTheme , PresentationStrings )
101- case peer( Int , ContactListPeer , EnginePeer . Presence ? , ListViewItemHeader ? , ContactsPeerItemSelection , PresentationTheme , PresentationStrings , PresentationDateTimeFormat , PresentationPersonNameOrder , PresentationPersonNameOrder , Bool , Bool , Bool , StoryData ? , Bool )
101+ case peer( Int , ContactListPeer , EnginePeer . Presence ? , ListViewItemHeader ? , ContactsPeerItemSelection , PresentationTheme , PresentationStrings , PresentationDateTimeFormat , PresentationPersonNameOrder , PresentationPersonNameOrder , Bool , Bool , Bool , StoryData ? , Bool , String ? )
102102
103103 var stableId : ContactListNodeEntryId {
104104 switch self {
@@ -112,7 +112,7 @@ private enum ContactListNodeEntry: Comparable, Identifiable {
112112 return . permission( action: true )
113113 case let . option( index, _, _, _, _) :
114114 return . option( index: index)
115- case let . peer( _, peer, _, _, _, _, _, _, _, _, _, _, _, storyData, _) :
115+ case let . peer( _, peer, _, _, _, _, _, _, _, _, _, _, _, storyData, _, _ ) :
116116 switch peer {
117117 case let . peer( peer, _, _) :
118118 return . peerId( peerId: peer. id. toInt64 ( ) , section: storyData != nil ? . stories : . contacts)
@@ -152,7 +152,7 @@ private enum ContactListNodeEntry: Comparable, Identifiable {
152152 style = . generic
153153 }
154154 return ContactListActionItem ( presentationData: ItemListPresentationData ( presentationData) , title: option. title, subtitle: option. subtitle, icon: option. icon, style: style, clearHighlightAutomatically: option. clearHighlightAutomatically, header: header, action: option. action)
155- case let . peer( _, peer, presence, header, selection, _, strings, dateTimeFormat, nameSortOrder, nameDisplayOrder, displayCallIcons, hasMoreButton, enabled, storyData, requiresPremiumForMessaging) :
155+ case let . peer( _, peer, presence, header, selection, _, strings, dateTimeFormat, nameSortOrder, nameDisplayOrder, displayCallIcons, hasMoreButton, enabled, storyData, requiresPremiumForMessaging, customSubtitle ) :
156156 var status : ContactsPeerItemStatus
157157 let itemPeer : ContactsPeerItemPeer
158158 var isContextActionEnabled = false
@@ -221,8 +221,11 @@ private enum ContactListNodeEntry: Comparable, Identifiable {
221221 } ) ]
222222 }
223223
224+
224225 var storyStats : ( total: Int , unseen: Int , hasUnseenCloseFriends: Bool ) ?
225- if let storyData = storyData {
226+ if let customSubtitle {
227+ status = . custom( string: NSAttributedString ( string: customSubtitle) , multiline: false , isActive: false , icon: nil )
228+ } else if let storyData {
226229 storyStats = ( storyData. count, storyData. unseenCount, storyData. hasUnseenCloseFriends)
227230
228231 let text : String
@@ -276,9 +279,9 @@ private enum ContactListNodeEntry: Comparable, Identifiable {
276279 } else {
277280 return false
278281 }
279- case let . peer( lhsIndex, lhsPeer, lhsPresence, lhsHeader, lhsSelection, lhsTheme, lhsStrings, lhsTimeFormat, lhsSortOrder, lhsDisplayOrder, lhsDisplayCallIcons, lhsHasMoreButton, lhsEnabled, lhsStoryData, lhsRequiresPremiumForMessaging) :
282+ case let . peer( lhsIndex, lhsPeer, lhsPresence, lhsHeader, lhsSelection, lhsTheme, lhsStrings, lhsTimeFormat, lhsSortOrder, lhsDisplayOrder, lhsDisplayCallIcons, lhsHasMoreButton, lhsEnabled, lhsStoryData, lhsRequiresPremiumForMessaging, lhsCustomSubtitle ) :
280283 switch rhs {
281- case let . peer( rhsIndex, rhsPeer, rhsPresence, rhsHeader, rhsSelection, rhsTheme, rhsStrings, rhsTimeFormat, rhsSortOrder, rhsDisplayOrder, rhsDisplayCallIcons, rhsHasMoreButton, rhsEnabled, rhsStoryData, rhsRequiresPremiumForMessaging) :
284+ case let . peer( rhsIndex, rhsPeer, rhsPresence, rhsHeader, rhsSelection, rhsTheme, rhsStrings, rhsTimeFormat, rhsSortOrder, rhsDisplayOrder, rhsDisplayCallIcons, rhsHasMoreButton, rhsEnabled, rhsStoryData, rhsRequiresPremiumForMessaging, rhsCustomSubtitle ) :
282285 if lhsIndex != rhsIndex {
283286 return false
284287 }
@@ -328,6 +331,9 @@ private enum ContactListNodeEntry: Comparable, Identifiable {
328331 if lhsRequiresPremiumForMessaging != rhsRequiresPremiumForMessaging {
329332 return false
330333 }
334+ if lhsCustomSubtitle != rhsCustomSubtitle {
335+ return false
336+ }
331337 return true
332338 default :
333339 return false
@@ -369,11 +375,11 @@ private enum ContactListNodeEntry: Comparable, Identifiable {
369375 case . peer:
370376 return true
371377 }
372- case let . peer( lhsIndex, _, _, _, _, _, _, _, _, _, _, _, _, lhsStoryData, _) :
378+ case let . peer( lhsIndex, _, _, _, _, _, _, _, _, _, _, _, _, lhsStoryData, _, _ ) :
373379 switch rhs {
374380 case . search, . sort, . permissionInfo, . permissionEnable, . option:
375381 return false
376- case let . peer( rhsIndex, _, _, _, _, _, _, _, _, _, _, _, _, rhsStoryData, _) :
382+ case let . peer( rhsIndex, _, _, _, _, _, _, _, _, _, _, _, _, rhsStoryData, _, _ ) :
377383 if ( lhsStoryData == nil ) != ( rhsStoryData == nil ) {
378384 if lhsStoryData != nil {
379385 return true
@@ -567,15 +573,24 @@ private func contactListNodeEntries(accountPeer: EnginePeer?, peers: [ContactLis
567573 }
568574
569575 let presence = presences [ peer. id]
570- entries. append ( . peer( index, . peer( peer: peer. _asPeer ( ) , isGlobal: false , participantCount: nil ) , presence, header, selection, theme, strings, dateTimeFormat, sortOrder, displayOrder, false , false , true , nil , false ) )
576+ entries. append ( . peer( index, . peer( peer: peer. _asPeer ( ) , isGlobal: false , participantCount: nil ) , presence, header, selection, theme, strings, dateTimeFormat, sortOrder, displayOrder, false , false , true , nil , false , nil ) )
571577
572578 index += 1
573579 }
574580 }
575- case let . custom( sections) :
581+ case let . custom( showSelf , sections) :
576582 if !topPeers. isEmpty {
577583 var index : Int = 0
578- var sectionId : Int = 1
584+
585+ if showSelf, let accountPeer {
586+ if let peer = topPeers. first ( where: { $0. id == accountPeer. id } ) {
587+ let header = ChatListSearchItemHeader ( type: . text( strings. Premium_Gift_ContactSelection_ThisIsYou. uppercased ( ) , AnyHashable ( 10 ) ) , theme: theme, strings: strings)
588+ entries. append ( . peer( index, . peer( peer: peer. _asPeer ( ) , isGlobal: false , participantCount: nil ) , nil , header, . none, theme, strings, dateTimeFormat, sortOrder, displayOrder, false , false , true , nil , false , strings. Premium_Gift_ContactSelection_BuySelf) )
589+ existingPeerIds. insert ( . peer( peer. id) )
590+ }
591+ }
592+
593+ var sectionId : Int = 2
579594 for (title, peerIds, hasActions) in sections {
580595 var allSelected = true
581596 if let selectedPeerIndices = selectionState? . selectedPeerIndices, !selectedPeerIndices. isEmpty {
@@ -624,7 +639,7 @@ private func contactListNodeEntries(accountPeer: EnginePeer?, peers: [ContactLis
624639 }
625640
626641 let presence = presences [ peer. id]
627- entries. append ( . peer( index, . peer( peer: peer. _asPeer ( ) , isGlobal: false , participantCount: nil ) , presence, header, selection, theme, strings, dateTimeFormat, sortOrder, displayOrder, false , hasActions, true , nil , false ) )
642+ entries. append ( . peer( index, . peer( peer: peer. _asPeer ( ) , isGlobal: false , participantCount: nil ) , presence, header, selection, theme, strings, dateTimeFormat, sortOrder, displayOrder, false , hasActions, true , nil , false , nil ) )
628643
629644 index += 1
630645 }
@@ -675,7 +690,7 @@ private func contactListNodeEntries(accountPeer: EnginePeer?, peers: [ContactLis
675690 let presence = presences [ peer. id]
676691 entries. append ( . peer( index, . peer( peer: peer. _asPeer ( ) , isGlobal: false , participantCount: nil ) , presence, header, selection, theme, strings, dateTimeFormat, sortOrder, displayOrder, false , false , true , peersWithStories [ peer. id] . flatMap {
677692 ContactListNodeEntry . StoryData ( count: $0. totalCount, unseenCount: $0. unseenCount, hasUnseenCloseFriends: $0. hasUnseenCloseFriends)
678- } , false ) )
693+ } , false , nil ) )
679694
680695 index += 1
681696 }
@@ -726,7 +741,7 @@ private func contactListNodeEntries(accountPeer: EnginePeer?, peers: [ContactLis
726741 }
727742 }
728743
729- entries. append ( . peer( index, peer, presence, nil , selection, theme, strings, dateTimeFormat, sortOrder, displayOrder, displayCallIcons, false , enabled, storyData, false ) )
744+ entries. append ( . peer( index, peer, presence, nil , selection, theme, strings, dateTimeFormat, sortOrder, displayOrder, displayCallIcons, false , enabled, storyData, false , nil ) )
730745 index += 1
731746 }
732747 }
@@ -779,7 +794,7 @@ private func contactListNodeEntries(accountPeer: EnginePeer?, peers: [ContactLis
779794 }
780795 }
781796
782- entries. append ( . peer( index, peer, presence, header, selection, theme, strings, dateTimeFormat, sortOrder, displayOrder, displayCallIcons, false , enabled, storyData, requiresPremiumForMessaging) )
797+ entries. append ( . peer( index, peer, presence, header, selection, theme, strings, dateTimeFormat, sortOrder, displayOrder, displayCallIcons, false , enabled, storyData, requiresPremiumForMessaging, nil ) )
783798 index += 1
784799 }
785800 return entries
@@ -803,7 +818,7 @@ private func preparedContactListNodeTransition(context: AccountContext, presenta
803818 case . search:
804819 //indexSections.apend(CollectionIndexNode.searchIndex)
805820 break
806- case let . peer( _, _, _, header, _, _, _, _, _, _, _, _, _, _, _) :
821+ case let . peer( _, _, _, header, _, _, _, _, _, _, _, _, _, _, _, _ ) :
807822 if let header = header as? ContactListNameIndexHeader {
808823 if !existingSections. contains ( header. letter) {
809824 existingSections. insert ( header. letter)
@@ -872,7 +887,7 @@ public enum ContactListPresentation {
872887 public enum TopPeers {
873888 case none
874889 case recent
875- case custom( [ ( title: String , peerIds: [ EnginePeer . Id ] , hasActions: Bool ) ] )
890+ case custom( showSelf : Bool , sections : [ ( title: String , peerIds: [ EnginePeer . Id ] , hasActions: Bool ) ] )
876891 }
877892
878893 case orderedByPresence( options: [ ContactListAdditionalOption ] )
@@ -1284,7 +1299,7 @@ public final class ContactListNode: ASDisplayNode {
12841299 strongSelf. listNode. transaction ( deleteIndices: [ ] , insertIndicesAndItems: [ ] , updateIndicesAndItems: [ ] , options: [ . PreferSynchronousDrawing, . PreferSynchronousResourceLoading] , scrollToItem: ListViewScrollToItem ( index: index, position: . top( - navigationBarSearchContentHeight) , animated: false , curve: . Default( duration: nil ) , directionHint: . Down) , additionalScrollDistance: 0.0 , updateSizeAndInsets: updateSizeAndInsets, stationaryItemRange: nil , updateOpaqueState: nil , completion: { _ in } )
12851300 break loop
12861301 }
1287- case let . peer( _, _, _, header, _, _, _, _, _, _, _, _, _, _, _) :
1302+ case let . peer( _, _, _, header, _, _, _, _, _, _, _, _, _, _, _, _ ) :
12881303 if let header = header as? ContactListNameIndexHeader {
12891304 if let scalar = UnicodeScalar ( header. letter) {
12901305 let title = " \( Character ( scalar) ) "
@@ -1718,8 +1733,11 @@ public final class ContactListNode: ASDisplayNode {
17181733 return . single( [ ] )
17191734 }
17201735 }
1721- case let . custom( sections) :
1736+ case let . custom( showSelf , sections) :
17221737 var peerIds : [ EnginePeer . Id ] = [ ]
1738+ if showSelf {
1739+ peerIds. append ( context. account. peerId)
1740+ }
17231741 for (_, sectionPeers, _) in sections {
17241742 peerIds. append ( contentsOf: sectionPeers)
17251743 }
0 commit comments