Skip to content

Commit 80731fd

Browse files
authored
Merge pull request #37 from 1IxI1/folder-avatar-removal
Add folder avatar removal
2 parents 933e619 + 55ae022 commit 80731fd

5 files changed

Lines changed: 53 additions & 3 deletions

File tree

‎Telegram-Mac/packages-integration/bridges/SidebarUIIntegration.swift‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,10 @@ final class AppSidebarUIEnvironment: SidebarUIEnvironment {
170170
return InputTextDataRowItem(size, stableId: stableId, context: accountContext, state: state, viewType: .singleItem, placeholder: nil, inputPlaceholder: strings().chatListFilterNamePlaceholder, rightItem: rightItem, filter: { $0 }, updateState: updateState, limit: 12, hasEmoji: true, playAnimation: playAnimation)
171171
}
172172

173-
func makePeerRow(_ size: NSSize, peer: Peer, stableId: AnyHashable, viewType: GeneralViewType, action: @escaping () -> Void, contextMenuItems: @escaping () -> Signal<[ContextMenuItem], NoError>) -> TableRowItem {
174-
return ShortPeerRowItem(size, peer: peer, account: accountContext.account, context: accountContext, stableId: stableId, height: 44, photoSize: NSMakeSize(30, 30), inset: NSEdgeInsets(left: 20, right: 20), viewType: viewType, action: action, contextMenuItems: contextMenuItems)
173+
func makePeerRow(_ size: NSSize, peer: Peer, stableId: AnyHashable, viewType: GeneralViewType, action: @escaping () -> Void, remove: @escaping () -> Void, contextMenuItems: @escaping () -> Signal<[ContextMenuItem], NoError>) -> TableRowItem {
174+
let item = ShortPeerRowItem(size, peer: peer, account: accountContext.account, context: accountContext, stableId: stableId, height: 44, photoSize: NSMakeSize(30, 30), inset: NSEdgeInsets(left: 20, right: 20), viewType: viewType, action: action, contextMenuItems: contextMenuItems)
175+
item.avatarRemoveAction = remove
176+
return item
175177
}
176178

177179
func makeAnimatedHeader() -> SidebarAnimatedHeaderView {

‎packages/ShortPeerRow/Sources/ShortPeerRow/ShortPeerRowItem.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ open class ShortPeerRowItem: GeneralRowItem {
336336

337337
private let _menuPresentation: AppMenu.Presentation?
338338
public let badgeAction: ((NSView)->Void)?
339+
public var avatarRemoveAction: (() -> Void)?
339340

340341
public init(_ initialSize:NSSize, peer: Peer, account: Account, context: (any AccountContextProtocol)?, peerId: PeerId? = nil, stableId:AnyHashable? = nil, enabled: Bool = true, height:CGFloat = 50, photoSize:NSSize = NSMakeSize(36, 36), titleStyle:ControlStyle = ControlStyle(font: .medium(.title), foregroundColor: theme.colors.text, highlightColor: .white), titleAddition:String? = nil, leftImage:CGImage? = nil, statusStyle:ControlStyle = ControlStyle(font:.normal(.text), foregroundColor: theme.colors.grayText, highlightColor:.white), status:String? = nil, borderType:BorderType = [], drawCustomSeparator:Bool = true, isLookSavedMessage: Bool = false, deleteInset:CGFloat? = nil, drawLastSeparator:Bool = false, inset:NSEdgeInsets = NSEdgeInsets(left:10.0), drawSeparatorIgnoringInset: Bool = false, interactionType:ShortPeerItemInteractionType = .plain, generalType:GeneralInteractedType = .none, viewType: GeneralViewType = .legacy, action:@escaping ()->Void = {}, contextMenuItems:@escaping()->Signal<[ContextMenuItem], NoError> = { .single([]) }, inputActivity: PeerInputActivity? = nil, highlightOnHover: Bool = false, alwaysHighlight: Bool = false, badgeNode: ShortPeerBadgeNode? = nil, compactText: Bool = false, highlightVerified: Bool = false, customTheme: GeneralRowItem.Theme? = nil, drawPhotoOuter: Bool = false, disabledAction:(()->Void)? = nil, story: EngineStorySubscriptions.Item? = nil, openStory: @escaping(StoryInitialIndex?)->Void = { _ in }, menuOnAction: Bool = false, photoBadge: CGImage? = nil, customAction: CustomAction? = nil, makeAvatarRound: Bool = false, drawStarsPaid: StarsAmount? = nil, statusImage: CGImage? = nil, passLeftAction: Bool = false, rightActions: RightActions = .init(), monoforumPeer: Peer? = nil, fullSize: Bool = false, _menuPresentation: AppMenu.Presentation? = nil, badgeAction: ((NSView)->Void)? = nil) {
341342
self.peer = peer

‎packages/ShortPeerRow/Sources/ShortPeerRow/ShortPeerRowView.swift‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ open class ShortPeerRowView: TableRowView, Notifable, ViewDisplayDelegate {
3333
private var paidMessageBadgeCache: SendPaidMessageBadgeCache?
3434

3535
private var deleteControl:ImageButton?
36+
private var avatarRemoveControl: ImageButton?
3637
private var selectControl:SelectingControl?
3738
let container:Control = Control()
3839
private var switchView:SwitchView?
@@ -485,6 +486,12 @@ open class ShortPeerRowView: TableRowView, Notifable, ViewDisplayDelegate {
485486
container.needsDisplay = true
486487

487488
}
489+
490+
if let avatarRemoveControl {
491+
avatarRemoveControl.frame = image.frame
492+
avatarRemoveControl.layer?.mask?.frame = avatarRemoveControl.bounds
493+
avatarRemoveControl.updateState()
494+
}
488495

489496
var additional: CGFloat = 0
490497

@@ -843,6 +850,42 @@ open class ShortPeerRowView: TableRowView, Notifable, ViewDisplayDelegate {
843850
}
844851

845852
image.userInteractionEnabled = item.story != nil
853+
854+
if item.avatarRemoveAction != nil, item.enabled {
855+
let control: ImageButton
856+
if let avatarRemoveControl {
857+
control = avatarRemoveControl
858+
} else {
859+
control = ImageButton()
860+
control.autohighlight = false
861+
control.set(background: .clear, for: .Normal)
862+
control.set(background: NSColor.black.withAlphaComponent(0.6), for: .Hover)
863+
control.set(background: NSColor.black.withAlphaComponent(0.7), for: .Highlight)
864+
let mask = SimpleLayer()
865+
mask.contentsGravity = .resizeAspectFill
866+
control.layer?.mask = mask
867+
image.contentUpdated = { [weak mask] contents in
868+
mask?.contents = contents
869+
}
870+
control.set(handler: { [weak self] _ in
871+
guard let item = self?.item as? ShortPeerRowItem, item.enabled else {
872+
return
873+
}
874+
item.avatarRemoveAction?()
875+
}, for: .Click)
876+
container.addSubview(control)
877+
avatarRemoveControl = control
878+
}
879+
control.layer?.mask?.contents = image.avatar.imageContents
880+
let icon = TelegramThemeHooks.shared.image(.iconPipClose).precomposed(.white)
881+
control.set(image: icon, for: .Hover)
882+
control.set(image: icon, for: .Highlight)
883+
control.setAccessibilityLabel(strings().voiceOverCommonRemove)
884+
} else if let avatarRemoveControl {
885+
avatarRemoveControl.removeFromSuperview()
886+
self.avatarRemoveControl = nil
887+
image.contentUpdated = nil
888+
}
846889

847890
let transition: ContainedViewLayoutTransition = animated ? .animated(duration: 0.2, curve: .easeOut) : .immediate
848891
if let indicator = item.avatarStoryIndicator {

‎packages/SidebarUI/Sources/SidebarUI/ChatListFilterController.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,8 @@ private func chatListFilterEntries(state: State, includePeers: [Peer], excludePe
641641
entries.append(.custom(sectionId: sectionId, index: index, value: .none, identifier: _id_include(peer.id), equatable: InputDataEquatable(E(viewType: viewType, peer: SidebarPeerEquatable(peer))), comparable: nil, item: { initialSize, stableId in
642642
return arguments.environment.makePeerRow(initialSize, peer: peer, stableId: stableId, viewType: viewType, action: {
643643
arguments.openInfo(peer.id)
644+
}, remove: {
645+
arguments.removeIncluded(peer.id)
644646
}, contextMenuItems: {
645647
return .single([ContextMenuItem(strings().chatListFilterIncludeRemoveChat, handler: {
646648
arguments.removeIncluded(peer.id)
@@ -715,6 +717,8 @@ private func chatListFilterEntries(state: State, includePeers: [Peer], excludePe
715717
entries.append(.custom(sectionId: sectionId, index: index, value: .none, identifier: _id_exclude(peer.id), equatable: InputDataEquatable(E(viewType: viewType, peer: SidebarPeerEquatable(peer))), comparable: nil, item: { initialSize, stableId in
716718
return arguments.environment.makePeerRow(initialSize, peer: peer, stableId: stableId, viewType: viewType, action: {
717719
arguments.openInfo(peer.id)
720+
}, remove: {
721+
arguments.removeExcluded(peer.id)
718722
}, contextMenuItems: {
719723
return .single([ContextMenuItem.init(strings().chatListFilterExcludeRemoveChat, handler: {
720724
arguments.removeExcluded(peer.id)

‎packages/SidebarUI/Sources/SidebarUI/SidebarUIEnvironment.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public protocol SidebarUIEnvironment: AnyObject {
6363
func titleEntities(_ state: Updated_ChatTextInputState) -> [MessageTextEntity]
6464
func inputStatesEqual(_ lhs: Updated_ChatTextInputState, _ rhs: Updated_ChatTextInputState) -> Bool
6565
func makeNameRow(_ size: NSSize, stableId: AnyHashable, state: Updated_ChatTextInputState, rightItem: InputDataRightItem, updateState: @escaping (Updated_ChatTextInputState) -> Void, playAnimation: Bool) -> TableRowItem
66-
func makePeerRow(_ size: NSSize, peer: Peer, stableId: AnyHashable, viewType: GeneralViewType, action: @escaping () -> Void, contextMenuItems: @escaping () -> Signal<[ContextMenuItem], NoError>) -> TableRowItem
66+
func makePeerRow(_ size: NSSize, peer: Peer, stableId: AnyHashable, viewType: GeneralViewType, action: @escaping () -> Void, remove: @escaping () -> Void, contextMenuItems: @escaping () -> Signal<[ContextMenuItem], NoError>) -> TableRowItem
6767
func makeAnimatedHeader() -> SidebarAnimatedHeaderView
6868
func applyInlineStickers(to text: NSMutableAttributedString, entities: [MessageTextEntity], isPremium: Bool, animated: Bool)
6969
func image(_ image: SidebarImage) -> NSImage

0 commit comments

Comments
 (0)