@@ -70,6 +70,7 @@ public final class PeerInfoGiftsPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr
7070 private let profileGifts : ProfileGiftsContext
7171 private let canManage : Bool
7272 private let canGift : Bool
73+ private var peer : EnginePeer ?
7374 private let initialGiftCollectionId : Int64 ?
7475
7576 private var resultsAreEmpty = false
@@ -130,6 +131,8 @@ public final class PeerInfoGiftsPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr
130131 return self . giftsListView. profileGifts
131132 }
132133
134+ public var openShareLink : ( ( String ) -> Void ) ?
135+
133136 private let collectionsMaxCount : Int
134137
135138 public init ( context: AccountContext , peerId: PeerId , chatControllerInteraction: ChatControllerInteraction , profileGiftsCollections: ProfileGiftsCollectionsContext , profileGifts: ProfileGiftsContext , canManage: Bool , canGift: Bool , initialGiftCollectionId: Int64 ? ) {
@@ -193,6 +196,15 @@ public final class PeerInfoGiftsPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr
193196 if let initialGiftCollectionId {
194197 self . setCurrentCollection ( collection: . collection( Int32 ( initialGiftCollectionId) ) )
195198 }
199+
200+ let _ = ( context. engine. data. subscribe ( TelegramEngine . EngineData. Item. Peer. Peer ( id: peerId) )
201+ |> deliverOnMainQueue) . start ( next: { [ weak self] peer in
202+ guard let self else {
203+ return
204+ }
205+ self . peer = peer
206+ self . updateScrolling ( transition: . immediate)
207+ } )
196208 }
197209
198210 deinit {
@@ -485,68 +497,78 @@ public final class PeerInfoGiftsPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr
485497 return
486498 }
487499
488- var items : [ ContextMenuItem ] = [ ]
500+ var canEditCollections = false
501+ if self . peerId == self . context. account. peerId || self . canManage {
502+ canEditCollections = true
503+ }
489504
490- items. append ( . action( ContextMenuActionItem ( text: params. presentationData. strings. PeerInfo_Gifts_AddGifts, icon: { theme in
491- return generateTintedImage ( image: UIImage ( bundleImageName: " Peer Info/Gifts/AddGift " ) , color: theme. actionSheet. primaryTextColor)
492- } , action: { [ weak self] _, f in
493- guard let self else {
494- return
495- }
496- f ( . default)
497-
498- self . setCurrentCollection ( collection: . collection( id) )
499- self . addGiftsToCollection ( id: id)
500- } ) ) )
505+ var items : [ ContextMenuItem ] = [ ]
501506
502- items. append ( . action( ContextMenuActionItem ( text: params. presentationData. strings. PeerInfo_Gifts_RenameCollection, icon: { theme in
503- return generateTintedImage ( image: UIImage ( bundleImageName: " Chat/Context Menu/Edit " ) , color: theme. actionSheet. primaryTextColor)
504- } , action: { [ weak self] _, f in
505- guard let self else {
506- return
507- }
508- f ( . default)
507+ if canEditCollections {
508+ items. append ( . action( ContextMenuActionItem ( text: params. presentationData. strings. PeerInfo_Gifts_AddGifts, icon: { theme in
509+ return generateTintedImage ( image: UIImage ( bundleImageName: " Peer Info/Gifts/AddGift " ) , color: theme. actionSheet. primaryTextColor)
510+ } , action: { [ weak self] _, f in
511+ guard let self else {
512+ return
513+ }
514+ f ( . default)
515+
516+ self . setCurrentCollection ( collection: . collection( id) )
517+ self . addGiftsToCollection ( id: id)
518+ } ) ) )
509519
510- Queue . mainQueue ( ) . after ( 0.15 ) {
511- self . renameCollection ( id: id)
512- }
513- } ) ) )
520+ items. append ( . action( ContextMenuActionItem ( text: params. presentationData. strings. PeerInfo_Gifts_RenameCollection, icon: { theme in
521+ return generateTintedImage ( image: UIImage ( bundleImageName: " Chat/Context Menu/Edit " ) , color: theme. actionSheet. primaryTextColor)
522+ } , action: { [ weak self] _, f in
523+ guard let self else {
524+ return
525+ }
526+ f ( . default)
527+
528+ Queue . mainQueue ( ) . after ( 0.15 ) {
529+ self . renameCollection ( id: id)
530+ }
531+ } ) ) )
532+ }
514533
515-
516- // items.append(.action(ContextMenuActionItem(text: params.presentationData.strings.PeerInfo_Gifts_ShareCollection, icon: { theme in
517- // return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Forward"), color: theme.actionSheet.primaryTextColor)
518- // }, action: { [weak self] _, f in
519- // guard let self else {
520- // return
521- // }
522- // f(.default)
523- //
524- // let _ = self
525- // })))
526-
527- items. append ( . action( ContextMenuActionItem ( text: params. presentationData. strings. PeerInfo_Gifts_Reorder, icon: { theme in
528- return generateTintedImage ( image: UIImage ( bundleImageName: " Chat/Context Menu/ReorderItems " ) , color: theme. actionSheet. primaryTextColor)
529- } , action: { [ weak self] c, f in
530- c? . dismiss ( completion: { [ weak self] in
534+ if let peer = self . peer, let addressName = peer. addressName, !addressName. isEmpty {
535+ items. append ( . action( ContextMenuActionItem ( text: params. presentationData. strings. PeerInfo_Gifts_ShareCollection, icon: { theme in
536+ return generateTintedImage ( image: UIImage ( bundleImageName: " Chat/Context Menu/Forward " ) , color: theme. actionSheet. primaryTextColor)
537+ } , action: { [ weak self] _, f in
531538 guard let self else {
532539 return
533540 }
534- self . beginReordering ( )
535- } )
536- } ) ) )
541+ f ( . default)
542+
543+ self . openShareLink ? ( " https://t.me/ \( addressName) /c/ \( id) " )
544+ } ) ) )
545+ }
537546
538- items. append ( . action( ContextMenuActionItem ( text: params. presentationData. strings. PeerInfo_Gifts_DeleteCollection, textColor: . destructive, icon: { theme in
539- return generateTintedImage ( image: UIImage ( bundleImageName: " Chat/Context Menu/Delete " ) , color: theme. contextMenu. destructiveColor)
540- } , action: { [ weak self] _, f in
541- guard let self else {
542- return
543- }
544- f ( . default)
547+ if canEditCollections {
548+ items. append ( . action( ContextMenuActionItem ( text: params. presentationData. strings. PeerInfo_Gifts_Reorder, icon: { theme in
549+ return generateTintedImage ( image: UIImage ( bundleImageName: " Chat/Context Menu/ReorderItems " ) , color: theme. actionSheet. primaryTextColor)
550+ } , action: { [ weak self] c, f in
551+ c? . dismiss ( completion: { [ weak self] in
552+ guard let self else {
553+ return
554+ }
555+ self . beginReordering ( )
556+ } )
557+ } ) ) )
545558
546- Queue . mainQueue ( ) . after ( 0.15 ) {
547- self . deleteCollection ( id: id)
548- }
549- } ) ) )
559+ items. append ( . action( ContextMenuActionItem ( text: params. presentationData. strings. PeerInfo_Gifts_DeleteCollection, textColor: . destructive, icon: { theme in
560+ return generateTintedImage ( image: UIImage ( bundleImageName: " Chat/Context Menu/Delete " ) , color: theme. contextMenu. destructiveColor)
561+ } , action: { [ weak self] _, f in
562+ guard let self else {
563+ return
564+ }
565+ f ( . default)
566+
567+ Queue . mainQueue ( ) . after ( 0.15 ) {
568+ self . deleteCollection ( id: id)
569+ }
570+ } ) ) )
571+ }
550572
551573 let contextController = ContextController (
552574 presentationData: params. presentationData,
@@ -568,6 +590,10 @@ public final class PeerInfoGiftsPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr
568590 if self . peerId == self . context. account. peerId || self . canManage {
569591 canEditCollections = true
570592 }
593+ var canShare = false
594+ if let peer = self . peer, let addressName = peer. addressName, !addressName. isEmpty {
595+ canShare = true
596+ }
571597
572598 let hasNonEmptyCollections = self . collections? . contains ( where: { $0. count > 0 } ) ?? false
573599 if let collections = self . collections, !collections. isEmpty && ( hasNonEmptyCollections || canEditCollections) {
@@ -607,7 +633,7 @@ public final class PeerInfoGiftsPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr
607633 )
608634 ) ) ,
609635 isReorderable: collections. count > 1 ,
610- contextAction: canEditCollections ? { [ weak self] sourceNode, gesture in
636+ contextAction: canEditCollections || canShare ? { [ weak self] sourceNode, gesture in
611637 guard let self else {
612638 return
613639 }
0 commit comments