Don't show delete action in shared media context menu when it's not available

This commit is contained in:
Ilya Laktyushin 2019-11-23 18:35:56 +04:00
parent 295e6917eb
commit f9f8788e65

View File

@ -139,32 +139,40 @@ public class PeerMediaCollectionController: TelegramBaseController {
} }
}, openPeerMention: { _ in }, openPeerMention: { _ in
}, openMessageContextMenu: { [weak self] message, _, _, _, _ in }, openMessageContextMenu: { [weak self] message, _, _, _, _ in
guard let strongSelf = self else {
return
}
let items = (chatAvailableMessageActionsImpl(postbox: strongSelf.context.account.postbox, accountPeerId: strongSelf.context.account.peerId, messageIds: [message.id])
|> deliverOnMainQueue).start(next: { actions in
var messageIds = Set<MessageId>() var messageIds = Set<MessageId>()
messageIds.insert(message.id) messageIds.insert(message.id)
if let strongSelf = self, strongSelf.isNodeLoaded { if let strongSelf = self, strongSelf.isNodeLoaded {
if let message = strongSelf.mediaCollectionDisplayNode.messageForGallery(message.id)?.message { if let message = strongSelf.mediaCollectionDisplayNode.messageForGallery(message.id)?.message {
let actionSheet = ActionSheetController(presentationTheme: strongSelf.presentationData.theme) let actionSheet = ActionSheetController(presentationTheme: strongSelf.presentationData.theme)
actionSheet.setItemGroups([ActionSheetItemGroup(items: [ var items: [ActionSheetButtonItem] = []
ActionSheetButtonItem(title: strongSelf.presentationData.strings.SharedMedia_ViewInChat, color: .accent, action: { [weak actionSheet] in
items.append(ActionSheetButtonItem(title: strongSelf.presentationData.strings.SharedMedia_ViewInChat, color: .accent, action: { [weak actionSheet] in
actionSheet?.dismissAnimated() actionSheet?.dismissAnimated()
if let strongSelf = self, let navigationController = strongSelf.navigationController as? NavigationController { if let strongSelf = self, let navigationController = strongSelf.navigationController as? NavigationController {
strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(strongSelf.peerId), subject: .message(message.id))) strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(strongSelf.peerId), subject: .message(message.id)))
} }
}), }))
ActionSheetButtonItem(title: strongSelf.presentationData.strings.Conversation_ContextMenuForward, color: .accent, action: { [weak actionSheet] in items.append(ActionSheetButtonItem(title: strongSelf.presentationData.strings.Conversation_ContextMenuForward, color: .accent, action: { [weak actionSheet] in
actionSheet?.dismissAnimated() actionSheet?.dismissAnimated()
if let strongSelf = self { if let strongSelf = self {
strongSelf.forwardMessages(messageIds) strongSelf.forwardMessages(messageIds)
} }
}), }))
ActionSheetButtonItem(title: strongSelf.presentationData.strings.Conversation_ContextMenuDelete, color: .destructive, action: { [weak actionSheet] in if actions.options.contains(.deleteLocally) || actions.options.contains(.deleteGlobally) {
items.append( ActionSheetButtonItem(title: strongSelf.presentationData.strings.Conversation_ContextMenuDelete, color: .destructive, action: { [weak actionSheet] in
actionSheet?.dismissAnimated() actionSheet?.dismissAnimated()
if let strongSelf = self { if let strongSelf = self {
strongSelf.deleteMessages(messageIds) strongSelf.deleteMessages(messageIds)
} }
}) }))
]), ActionSheetItemGroup(items: [ }
actionSheet.setItemGroups([ActionSheetItemGroup(items: items), ActionSheetItemGroup(items: [
ActionSheetButtonItem(title: strongSelf.presentationData.strings.Common_Cancel, color: .accent, font: .bold, action: { [weak actionSheet] in ActionSheetButtonItem(title: strongSelf.presentationData.strings.Common_Cancel, color: .accent, font: .bold, action: { [weak actionSheet] in
actionSheet?.dismissAnimated() actionSheet?.dismissAnimated()
}) })
@ -173,6 +181,7 @@ public class PeerMediaCollectionController: TelegramBaseController {
strongSelf.present(actionSheet, in: .window(.root)) strongSelf.present(actionSheet, in: .window(.root))
} }
} }
})
}, openMessageContextActions: { [weak self] message, node, rect, gesture in }, openMessageContextActions: { [weak self] message, node, rect, gesture in
guard let strongSelf = self else { guard let strongSelf = self else {
gesture?.cancel() gesture?.cancel()