mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix invisible pinned messages button actions
This commit is contained in:
parent
826f87b51e
commit
89abe476d9
@ -1594,152 +1594,160 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}, requestMessageActionCallback: { [weak self] messageId, data, isGame, requiresPassword in
|
}, requestMessageActionCallback: { [weak self] messageId, data, isGame, requiresPassword in
|
||||||
if let strongSelf = self {
|
guard let strongSelf = self else {
|
||||||
guard strongSelf.presentationInterfaceState.subject != .scheduledMessages else {
|
return
|
||||||
strongSelf.present(textAlertController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, title: nil, text: strongSelf.presentationData.strings.ScheduledMessages_BotActionUnavailable, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root))
|
}
|
||||||
|
guard strongSelf.presentationInterfaceState.subject != .scheduledMessages else {
|
||||||
|
strongSelf.present(textAlertController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, title: nil, text: strongSelf.presentationData.strings.ScheduledMessages_BotActionUnavailable, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = (strongSelf.context.account.postbox.transaction { transaction -> Message? in
|
||||||
|
return transaction.getMessage(messageId)
|
||||||
|
}
|
||||||
|
|> deliverOnMainQueue).start(next: { message in
|
||||||
|
guard let strongSelf = self, let message = message else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if let message = strongSelf.chatDisplayNode.historyNode.messageInCurrentHistoryView(messageId) {
|
strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, {
|
||||||
strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, {
|
return $0.updatedTitlePanelContext {
|
||||||
return $0.updatedTitlePanelContext {
|
if !$0.contains(where: {
|
||||||
if !$0.contains(where: {
|
switch $0 {
|
||||||
switch $0 {
|
case .requestInProgress:
|
||||||
case .requestInProgress:
|
return true
|
||||||
return true
|
default:
|
||||||
default:
|
return false
|
||||||
return false
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
var updatedContexts = $0
|
|
||||||
updatedContexts.append(.requestInProgress)
|
|
||||||
return updatedContexts.sorted()
|
|
||||||
}
|
}
|
||||||
return $0
|
}) {
|
||||||
|
var updatedContexts = $0
|
||||||
|
updatedContexts.append(.requestInProgress)
|
||||||
|
return updatedContexts.sorted()
|
||||||
}
|
}
|
||||||
})
|
return $0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let proceedWithResult: (MessageActionCallbackResult) -> Void = { [weak self] result in
|
||||||
|
guard let strongSelf = self else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let proceedWithResult: (MessageActionCallbackResult) -> Void = { [weak self] result in
|
switch result {
|
||||||
guard let strongSelf = self else {
|
case .none:
|
||||||
return
|
break
|
||||||
}
|
case let .alert(text):
|
||||||
|
strongSelf.present(textAlertController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root))
|
||||||
switch result {
|
case let .toast(text):
|
||||||
case .none:
|
let message: Signal<String?, NoError> = .single(text)
|
||||||
break
|
let noMessage: Signal<String?, NoError> = .single(nil)
|
||||||
case let .alert(text):
|
let delayedNoMessage: Signal<String?, NoError> = noMessage |> delay(1.0, queue: Queue.mainQueue())
|
||||||
strongSelf.present(textAlertController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root))
|
strongSelf.botCallbackAlertMessage.set(message |> then(delayedNoMessage))
|
||||||
case let .toast(text):
|
case let .url(url):
|
||||||
let message: Signal<String?, NoError> = .single(text)
|
if isGame {
|
||||||
let noMessage: Signal<String?, NoError> = .single(nil)
|
let openBot: () -> Void = {
|
||||||
let delayedNoMessage: Signal<String?, NoError> = noMessage |> delay(1.0, queue: Queue.mainQueue())
|
guard let strongSelf = self else {
|
||||||
strongSelf.botCallbackAlertMessage.set(message |> then(delayedNoMessage))
|
return
|
||||||
case let .url(url):
|
}
|
||||||
if isGame {
|
|
||||||
let openBot: () -> Void = {
|
strongSelf.chatDisplayNode.dismissInput()
|
||||||
|
strongSelf.effectiveNavigationController?.pushViewController(GameController(context: strongSelf.context, url: url, message: EngineMessage(message)))
|
||||||
|
}
|
||||||
|
|
||||||
|
var botPeer: TelegramUser?
|
||||||
|
for attribute in message.attributes {
|
||||||
|
if let attribute = attribute as? InlineBotMessageAttribute {
|
||||||
|
if let peerId = attribute.peerId {
|
||||||
|
botPeer = message.peers[peerId] as? TelegramUser
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if botPeer == nil {
|
||||||
|
if let peer = message.author as? TelegramUser, peer.botInfo != nil {
|
||||||
|
botPeer = peer
|
||||||
|
} else if let peer = message.peers[message.id.peerId] as? TelegramUser, peer.botInfo != nil {
|
||||||
|
botPeer = peer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let botPeer = botPeer {
|
||||||
|
let _ = (ApplicationSpecificNotice.getBotGameNotice(accountManager: strongSelf.context.sharedContext.accountManager, peerId: botPeer.id)
|
||||||
|
|> deliverOnMainQueue).start(next: { value in
|
||||||
guard let strongSelf = self else {
|
guard let strongSelf = self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
strongSelf.chatDisplayNode.dismissInput()
|
|
||||||
strongSelf.effectiveNavigationController?.pushViewController(GameController(context: strongSelf.context, url: url, message: EngineMessage(message)))
|
|
||||||
}
|
|
||||||
|
|
||||||
var botPeer: TelegramUser?
|
if value {
|
||||||
for attribute in message.attributes {
|
openBot()
|
||||||
if let attribute = attribute as? InlineBotMessageAttribute {
|
} else {
|
||||||
if let peerId = attribute.peerId {
|
strongSelf.present(textAlertController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, title: nil, text: strongSelf.presentationData.strings.Conversation_BotInteractiveUrlAlert(EnginePeer(botPeer).displayTitle(strings: strongSelf.presentationData.strings, displayOrder: strongSelf.presentationData.nameDisplayOrder)).string, actions: [TextAlertAction(type: .genericAction, title: strongSelf.presentationData.strings.Common_Cancel, action: { }), TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {
|
||||||
botPeer = message.peers[peerId] as? TelegramUser
|
if let strongSelf = self {
|
||||||
}
|
let _ = ApplicationSpecificNotice.setBotGameNotice(accountManager: strongSelf.context.sharedContext.accountManager, peerId: botPeer.id).start()
|
||||||
|
openBot()
|
||||||
|
}
|
||||||
|
})]), in: .window(.root), with: nil)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
if botPeer == nil {
|
|
||||||
if let peer = message.author as? TelegramUser, peer.botInfo != nil {
|
|
||||||
botPeer = peer
|
|
||||||
} else if let peer = message.peers[message.id.peerId] as? TelegramUser, peer.botInfo != nil {
|
|
||||||
botPeer = peer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let botPeer = botPeer {
|
|
||||||
let _ = (ApplicationSpecificNotice.getBotGameNotice(accountManager: strongSelf.context.sharedContext.accountManager, peerId: botPeer.id)
|
|
||||||
|> deliverOnMainQueue).start(next: { value in
|
|
||||||
guard let strongSelf = self else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if value {
|
|
||||||
openBot()
|
|
||||||
} else {
|
|
||||||
strongSelf.present(textAlertController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, title: nil, text: strongSelf.presentationData.strings.Conversation_BotInteractiveUrlAlert(EnginePeer(botPeer).displayTitle(strings: strongSelf.presentationData.strings, displayOrder: strongSelf.presentationData.nameDisplayOrder)).string, actions: [TextAlertAction(type: .genericAction, title: strongSelf.presentationData.strings.Common_Cancel, action: { }), TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {
|
|
||||||
if let strongSelf = self {
|
|
||||||
let _ = ApplicationSpecificNotice.setBotGameNotice(accountManager: strongSelf.context.sharedContext.accountManager, peerId: botPeer.id).start()
|
|
||||||
openBot()
|
|
||||||
}
|
|
||||||
})]), in: .window(.root), with: nil)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
strongSelf.openUrl(url, concealed: false)
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
}
|
strongSelf.openUrl(url, concealed: false)
|
||||||
|
|
||||||
let updateProgress = { [weak self] in
|
|
||||||
Queue.mainQueue().async {
|
|
||||||
if let strongSelf = self {
|
|
||||||
strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, {
|
|
||||||
return $0.updatedTitlePanelContext {
|
|
||||||
if let index = $0.firstIndex(where: {
|
|
||||||
switch $0 {
|
|
||||||
case .requestInProgress:
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
var updatedContexts = $0
|
|
||||||
updatedContexts.remove(at: index)
|
|
||||||
return updatedContexts
|
|
||||||
}
|
|
||||||
return $0
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let context = strongSelf.context
|
|
||||||
if requiresPassword {
|
|
||||||
strongSelf.messageActionCallbackDisposable.set(((strongSelf.context.engine.messages.requestMessageActionCallbackPasswordCheck(messageId: messageId, isGame: isGame, data: data)
|
|
||||||
|> afterDisposed {
|
|
||||||
updateProgress()
|
|
||||||
})
|
|
||||||
|> deliverOnMainQueue).start(error: { error in
|
|
||||||
let controller = ownershipTransferController(context: context, updatedPresentationData: strongSelf.updatedPresentationData, initialError: error, present: { c, a in
|
|
||||||
strongSelf.present(c, in: .window(.root), with: a)
|
|
||||||
}, commit: { password in
|
|
||||||
return context.engine.messages.requestMessageActionCallback(messageId: messageId, isGame: isGame, password: password, data: data)
|
|
||||||
|> afterDisposed {
|
|
||||||
updateProgress()
|
|
||||||
}
|
|
||||||
}, completion: { result in
|
|
||||||
proceedWithResult(result)
|
|
||||||
})
|
|
||||||
strongSelf.present(controller, in: .window(.root))
|
|
||||||
}))
|
|
||||||
} else {
|
|
||||||
strongSelf.messageActionCallbackDisposable.set(((context.engine.messages.requestMessageActionCallback(messageId: messageId, isGame: isGame, password: nil, data: data)
|
|
||||||
|> afterDisposed {
|
|
||||||
updateProgress()
|
|
||||||
})
|
|
||||||
|> deliverOnMainQueue).start(next: { result in
|
|
||||||
proceedWithResult(result)
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
let updateProgress = { [weak self] in
|
||||||
|
Queue.mainQueue().async {
|
||||||
|
if let strongSelf = self {
|
||||||
|
strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, {
|
||||||
|
return $0.updatedTitlePanelContext {
|
||||||
|
if let index = $0.firstIndex(where: {
|
||||||
|
switch $0 {
|
||||||
|
case .requestInProgress:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
var updatedContexts = $0
|
||||||
|
updatedContexts.remove(at: index)
|
||||||
|
return updatedContexts
|
||||||
|
}
|
||||||
|
return $0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let context = strongSelf.context
|
||||||
|
if requiresPassword {
|
||||||
|
strongSelf.messageActionCallbackDisposable.set(((strongSelf.context.engine.messages.requestMessageActionCallbackPasswordCheck(messageId: messageId, isGame: isGame, data: data)
|
||||||
|
|> afterDisposed {
|
||||||
|
updateProgress()
|
||||||
|
})
|
||||||
|
|> deliverOnMainQueue).start(error: { error in
|
||||||
|
let controller = ownershipTransferController(context: context, updatedPresentationData: strongSelf.updatedPresentationData, initialError: error, present: { c, a in
|
||||||
|
strongSelf.present(c, in: .window(.root), with: a)
|
||||||
|
}, commit: { password in
|
||||||
|
return context.engine.messages.requestMessageActionCallback(messageId: messageId, isGame: isGame, password: password, data: data)
|
||||||
|
|> afterDisposed {
|
||||||
|
updateProgress()
|
||||||
|
}
|
||||||
|
}, completion: { result in
|
||||||
|
proceedWithResult(result)
|
||||||
|
})
|
||||||
|
strongSelf.present(controller, in: .window(.root))
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
strongSelf.messageActionCallbackDisposable.set(((context.engine.messages.requestMessageActionCallback(messageId: messageId, isGame: isGame, password: nil, data: data)
|
||||||
|
|> afterDisposed {
|
||||||
|
updateProgress()
|
||||||
|
})
|
||||||
|
|> deliverOnMainQueue).start(next: { result in
|
||||||
|
proceedWithResult(result)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
})
|
||||||
}, requestMessageActionUrlAuth: { [weak self] defaultUrl, subject in
|
}, requestMessageActionUrlAuth: { [weak self] defaultUrl, subject in
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
guard strongSelf.presentationInterfaceState.subject != .scheduledMessages else {
|
guard strongSelf.presentationInterfaceState.subject != .scheduledMessages else {
|
||||||
@ -2449,42 +2457,51 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, openCheckoutOrReceipt: { [weak self] messageId in
|
}, openCheckoutOrReceipt: { [weak self] messageId in
|
||||||
if let strongSelf = self {
|
guard let strongSelf = self else {
|
||||||
strongSelf.commitPurposefulAction()
|
return
|
||||||
if let message = strongSelf.chatDisplayNode.historyNode.messageInCurrentHistoryView(messageId) {
|
}
|
||||||
for media in message.media {
|
strongSelf.commitPurposefulAction()
|
||||||
if let invoice = media as? TelegramMediaInvoice {
|
|
||||||
strongSelf.chatDisplayNode.dismissInput()
|
let _ = (strongSelf.context.account.postbox.transaction { transaction -> Message? in
|
||||||
if let receiptMessageId = invoice.receiptMessageId {
|
return transaction.getMessage(messageId)
|
||||||
strongSelf.present(BotReceiptController(context: strongSelf.context, messageId: receiptMessageId), in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
}
|
||||||
} else {
|
|> deliverOnMainQueue).start(next: { message in
|
||||||
let inputData = Promise<BotCheckoutController.InputData?>()
|
guard let strongSelf = self, let message = message else {
|
||||||
inputData.set(BotCheckoutController.InputData.fetch(context: strongSelf.context, messageId: message.id)
|
return
|
||||||
|> map(Optional.init)
|
}
|
||||||
|> `catch` { _ -> Signal<BotCheckoutController.InputData?, NoError> in
|
|
||||||
return .single(nil)
|
for media in message.media {
|
||||||
})
|
if let invoice = media as? TelegramMediaInvoice {
|
||||||
strongSelf.present(BotCheckoutController(context: strongSelf.context, invoice: invoice, messageId: messageId, inputData: inputData, completed: { currencyValue, receiptMessageId in
|
strongSelf.chatDisplayNode.dismissInput()
|
||||||
guard let strongSelf = self else {
|
if let receiptMessageId = invoice.receiptMessageId {
|
||||||
return
|
strongSelf.present(BotReceiptController(context: strongSelf.context, messageId: receiptMessageId), in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||||
}
|
} else {
|
||||||
strongSelf.present(UndoOverlayController(presentationData: strongSelf.presentationData, content: .paymentSent(currencyValue: currencyValue, itemTitle: invoice.title), elevatedLayout: false, action: { action in
|
let inputData = Promise<BotCheckoutController.InputData?>()
|
||||||
guard let strongSelf = self, let receiptMessageId = receiptMessageId else {
|
inputData.set(BotCheckoutController.InputData.fetch(context: strongSelf.context, messageId: message.id)
|
||||||
return false
|
|> map(Optional.init)
|
||||||
}
|
|> `catch` { _ -> Signal<BotCheckoutController.InputData?, NoError> in
|
||||||
|
return .single(nil)
|
||||||
if case .info = action {
|
})
|
||||||
strongSelf.present(BotReceiptController(context: strongSelf.context, messageId: receiptMessageId), in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
strongSelf.present(BotCheckoutController(context: strongSelf.context, invoice: invoice, messageId: messageId, inputData: inputData, completed: { currencyValue, receiptMessageId in
|
||||||
return true
|
guard let strongSelf = self else {
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
strongSelf.present(UndoOverlayController(presentationData: strongSelf.presentationData, content: .paymentSent(currencyValue: currencyValue, itemTitle: invoice.title), elevatedLayout: false, action: { action in
|
||||||
|
guard let strongSelf = self, let receiptMessageId = receiptMessageId else {
|
||||||
return false
|
return false
|
||||||
}), in: .current)
|
}
|
||||||
}), in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
|
||||||
}
|
if case .info = action {
|
||||||
|
strongSelf.present(BotReceiptController(context: strongSelf.context, messageId: receiptMessageId), in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}), in: .current)
|
||||||
|
}), in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}, openSearch: {
|
}, openSearch: {
|
||||||
}, setupReply: { [weak self] messageId in
|
}, setupReply: { [weak self] messageId in
|
||||||
self?.interfaceInteraction?.setupReplyMessage(messageId, { _ in })
|
self?.interfaceInteraction?.setupReplyMessage(messageId, { _ in })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user