mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Add support for peer type filtering in switch inline
This commit is contained in:
parent
283f481ef2
commit
6179c3a939
@ -17,8 +17,25 @@ extension ReplyMarkupButton {
|
||||
self.init(title: text, titleWhenForwarded: nil, action: .requestMap)
|
||||
case let .keyboardButtonRequestPhone(text):
|
||||
self.init(title: text, titleWhenForwarded: nil, action: .requestPhone)
|
||||
case let .keyboardButtonSwitchInline(flags, text, query, _):
|
||||
self.init(title: text, titleWhenForwarded: nil, action: .switchInline(samePeer: (flags & (1 << 0)) != 0, query: query))
|
||||
case let .keyboardButtonSwitchInline(flags, text, query, types):
|
||||
var peerTypes = ReplyMarkupButtonAction.PeerTypes()
|
||||
if let types = types {
|
||||
for type in types {
|
||||
switch type {
|
||||
case .inlineQueryPeerTypePM:
|
||||
peerTypes.insert(.users)
|
||||
case .inlineQueryPeerTypeBotPM:
|
||||
peerTypes.insert(.bots)
|
||||
case .inlineQueryPeerTypeBroadcast:
|
||||
peerTypes.insert(.channels)
|
||||
case .inlineQueryPeerTypeChat, .inlineQueryPeerTypeMegagroup:
|
||||
peerTypes.insert(.groups)
|
||||
case .inlineQueryPeerTypeSameBotPM:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
self.init(title: text, titleWhenForwarded: nil, action: .switchInline(samePeer: (flags & (1 << 0)) != 0, query: query, peerTypes: peerTypes))
|
||||
case let .keyboardButtonUrl(text, url):
|
||||
self.init(title: text, titleWhenForwarded: nil, action: .url(url))
|
||||
case let .keyboardButtonGame(text):
|
||||
|
@ -181,12 +181,50 @@ public enum ReplyMarkupButtonRequestPeerType: Codable, Equatable {
|
||||
}
|
||||
|
||||
public enum ReplyMarkupButtonAction: PostboxCoding, Equatable {
|
||||
public struct PeerTypes: OptionSet {
|
||||
public var rawValue: Int32
|
||||
|
||||
public init(rawValue: Int32) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
public init() {
|
||||
self.rawValue = 0
|
||||
}
|
||||
|
||||
public static let users = PeerTypes(rawValue: 1 << 0)
|
||||
public static let bots = PeerTypes(rawValue: 1 << 1)
|
||||
public static let channels = PeerTypes(rawValue: 1 << 2)
|
||||
public static let groups = PeerTypes(rawValue: 1 << 3)
|
||||
|
||||
public var requestPeerTypes: [ReplyMarkupButtonRequestPeerType]? {
|
||||
if self.isEmpty {
|
||||
return nil
|
||||
}
|
||||
|
||||
var types: [ReplyMarkupButtonRequestPeerType] = []
|
||||
if self.contains(.users) {
|
||||
types.append(.user(.init(isBot: false, isPremium: nil)))
|
||||
}
|
||||
if self.contains(.bots) {
|
||||
types.append(.user(.init(isBot: true, isPremium: nil)))
|
||||
}
|
||||
if self.contains(.channels) {
|
||||
types.append(.channel(.init(isCreator: false, hasUsername: nil, userAdminRights: nil, botAdminRights: nil)))
|
||||
}
|
||||
if self.contains(.groups) {
|
||||
types.append(.group(.init(isCreator: false, hasUsername: nil, isForum: nil, botParticipant: false, userAdminRights: nil, botAdminRights: nil)))
|
||||
}
|
||||
return types
|
||||
}
|
||||
}
|
||||
|
||||
case text
|
||||
case url(String)
|
||||
case callback(requiresPassword: Bool, data: MemoryBuffer)
|
||||
case requestPhone
|
||||
case requestMap
|
||||
case switchInline(samePeer: Bool, query: String)
|
||||
case switchInline(samePeer: Bool, query: String, peerTypes: PeerTypes)
|
||||
case openWebApp
|
||||
case payment
|
||||
case urlAuth(url: String, buttonId: Int32)
|
||||
@ -208,7 +246,7 @@ public enum ReplyMarkupButtonAction: PostboxCoding, Equatable {
|
||||
case 4:
|
||||
self = .requestMap
|
||||
case 5:
|
||||
self = .switchInline(samePeer: decoder.decodeInt32ForKey("s", orElse: 0) != 0, query: decoder.decodeStringForKey("q", orElse: ""))
|
||||
self = .switchInline(samePeer: decoder.decodeInt32ForKey("s", orElse: 0) != 0, query: decoder.decodeStringForKey("q", orElse: ""), peerTypes: PeerTypes(rawValue: decoder.decodeInt32ForKey("pt", orElse: 0)))
|
||||
case 6:
|
||||
self = .openWebApp
|
||||
case 7:
|
||||
@ -243,10 +281,11 @@ public enum ReplyMarkupButtonAction: PostboxCoding, Equatable {
|
||||
encoder.encodeInt32(3, forKey: "v")
|
||||
case .requestMap:
|
||||
encoder.encodeInt32(4, forKey: "v")
|
||||
case let .switchInline(samePeer, query):
|
||||
case let .switchInline(samePeer, query, peerTypes):
|
||||
encoder.encodeInt32(5, forKey: "v")
|
||||
encoder.encodeInt32(samePeer ? 1 : 0, forKey: "s")
|
||||
encoder.encodeString(query, forKey: "q")
|
||||
encoder.encodeInt32(peerTypes.rawValue, forKey: "pt")
|
||||
case .openWebApp:
|
||||
encoder.encodeInt32(6, forKey: "v")
|
||||
case .payment:
|
||||
|
@ -105,7 +105,7 @@ public final class ChatControllerInteraction {
|
||||
public let sendBotContextResultAsGif: (ChatContextResultCollection, ChatContextResult, UIView, CGRect, Bool, Bool) -> Bool
|
||||
public let requestMessageActionCallback: (MessageId, MemoryBuffer?, Bool, Bool) -> Void
|
||||
public let requestMessageActionUrlAuth: (String, MessageActionUrlSubject) -> Void
|
||||
public let activateSwitchInline: (PeerId?, String) -> Void
|
||||
public let activateSwitchInline: (PeerId?, String, ReplyMarkupButtonAction.PeerTypes?) -> Void
|
||||
public let openUrl: (String, Bool, Bool?, Message?) -> Void
|
||||
public let shareCurrentLocation: () -> Void
|
||||
public let shareAccountContact: () -> Void
|
||||
@ -217,7 +217,7 @@ public final class ChatControllerInteraction {
|
||||
sendBotContextResultAsGif: @escaping (ChatContextResultCollection, ChatContextResult, UIView, CGRect, Bool, Bool) -> Bool,
|
||||
requestMessageActionCallback: @escaping (MessageId, MemoryBuffer?, Bool, Bool) -> Void,
|
||||
requestMessageActionUrlAuth: @escaping (String, MessageActionUrlSubject) -> Void,
|
||||
activateSwitchInline: @escaping (PeerId?, String) -> Void,
|
||||
activateSwitchInline: @escaping (PeerId?, String, ReplyMarkupButtonAction.PeerTypes?) -> Void,
|
||||
openUrl: @escaping (String, Bool, Bool?, Message?) -> Void,
|
||||
shareCurrentLocation: @escaping () -> Void,
|
||||
shareAccountContact: @escaping () -> Void,
|
||||
|
@ -391,7 +391,7 @@ final class ChatButtonKeyboardInputNode: ChatInputNode {
|
||||
if let message = self.message {
|
||||
self.controllerInteraction.requestMessageActionCallback(message.id, data, false, requiresPassword)
|
||||
}
|
||||
case let .switchInline(samePeer, query):
|
||||
case let .switchInline(samePeer, query, _):
|
||||
if let message = message {
|
||||
var botPeer: Peer?
|
||||
|
||||
|
@ -2512,7 +2512,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
}))
|
||||
}
|
||||
}, activateSwitchInline: { [weak self] peerId, inputString in
|
||||
}, activateSwitchInline: { [weak self] peerId, inputString, peerTypes in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
@ -2536,7 +2536,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
})
|
||||
} else {
|
||||
strongSelf.openPeer(peer: nil, navigation: .chat(textInputState: ChatTextInputState(inputText: NSAttributedString(string: inputString)), subject: nil, peekData: nil), fromMessage: nil)
|
||||
strongSelf.openPeer(peer: nil, navigation: .chat(textInputState: ChatTextInputState(inputText: NSAttributedString(string: inputString)), subject: nil, peekData: nil), fromMessage: nil, peerTypes: peerTypes)
|
||||
}
|
||||
}
|
||||
}, openUrl: { [weak self] url, concealed, _, message in
|
||||
@ -4226,12 +4226,12 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
if let strongSelf = self {
|
||||
completion()
|
||||
controller?.dismiss()
|
||||
strongSelf.controllerInteraction?.activateSwitchInline(peer.id, "@\(botAddress) \(query)")
|
||||
strongSelf.controllerInteraction?.activateSwitchInline(peer.id, "@\(botAddress) \(query)", nil)
|
||||
}
|
||||
}
|
||||
strongSelf.push(controller)
|
||||
} else {
|
||||
strongSelf.controllerInteraction?.activateSwitchInline(peerId, "@\(botAddress) \(query)")
|
||||
strongSelf.controllerInteraction?.activateSwitchInline(peerId, "@\(botAddress) \(query)", nil)
|
||||
}
|
||||
}
|
||||
}, getNavigationController: { [weak self] in
|
||||
@ -12873,12 +12873,12 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
if let strongSelf = self {
|
||||
completion()
|
||||
controller?.dismiss()
|
||||
strongSelf.controllerInteraction?.activateSwitchInline(peer.id, "@\(botAddress) \(query)")
|
||||
strongSelf.controllerInteraction?.activateSwitchInline(peer.id, "@\(botAddress) \(query)", nil)
|
||||
}
|
||||
}
|
||||
strongSelf.push(controller)
|
||||
} else {
|
||||
strongSelf.controllerInteraction?.activateSwitchInline(peerId, "@\(botAddress) \(query)")
|
||||
strongSelf.controllerInteraction?.activateSwitchInline(peerId, "@\(botAddress) \(query)", nil)
|
||||
}
|
||||
}
|
||||
}, completion: { [weak self] in
|
||||
@ -16716,7 +16716,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
})
|
||||
}
|
||||
|
||||
private func openPeer(peer: EnginePeer?, navigation: ChatControllerInteractionNavigateToPeer, fromMessage: MessageReference?, fromReactionMessageId: MessageId? = nil, expandAvatar: Bool = false) {
|
||||
private func openPeer(peer: EnginePeer?, navigation: ChatControllerInteractionNavigateToPeer, fromMessage: MessageReference?, fromReactionMessageId: MessageId? = nil, expandAvatar: Bool = false, peerTypes: ReplyMarkupButtonAction.PeerTypes? = nil) {
|
||||
let _ = self.presentVoiceMessageDiscardAlert(action: {
|
||||
if case let .peer(currentPeerId) = self.chatLocation, peer?.id == currentPeerId {
|
||||
switch navigation {
|
||||
@ -16815,7 +16815,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
break
|
||||
case let .chat(textInputState, _, _):
|
||||
if let textInputState = textInputState {
|
||||
let controller = self.context.sharedContext.makePeerSelectionController(PeerSelectionControllerParams(context: self.context, updatedPresentationData: self.updatedPresentationData, selectForumThreads: true))
|
||||
let controller = self.context.sharedContext.makePeerSelectionController(PeerSelectionControllerParams(context: self.context, updatedPresentationData: self.updatedPresentationData, requestPeerType: peerTypes.flatMap { $0.requestPeerTypes }, selectForumThreads: true))
|
||||
controller.peerSelected = { [weak self, weak controller] peer, threadId in
|
||||
let peerId = peer.id
|
||||
|
||||
|
@ -860,7 +860,7 @@ public class ChatMessageItemView: ListViewItemNode, ChatMessageItemNodeProtocol
|
||||
item.controllerInteraction.requestMessageActionCallback(item.message.id, nil, true, false)
|
||||
case let .callback(requiresPassword, data):
|
||||
item.controllerInteraction.requestMessageActionCallback(item.message.id, data, false, requiresPassword)
|
||||
case let .switchInline(samePeer, query):
|
||||
case let .switchInline(samePeer, query, peerTypes):
|
||||
var botPeer: Peer?
|
||||
|
||||
var found = false
|
||||
@ -881,7 +881,7 @@ public class ChatMessageItemView: ListViewItemNode, ChatMessageItemNodeProtocol
|
||||
peerId = item.message.id.peerId
|
||||
}
|
||||
if let botPeer = botPeer, let addressName = botPeer.addressName {
|
||||
item.controllerInteraction.activateSwitchInline(peerId, "@\(addressName) \(query)")
|
||||
item.controllerInteraction.activateSwitchInline(peerId, "@\(addressName) \(query)", peerTypes)
|
||||
}
|
||||
case .payment:
|
||||
item.controllerInteraction.openCheckoutOrReceipt(item.message.id)
|
||||
|
@ -863,7 +863,7 @@ final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
|
||||
controllerInteraction.requestMessageActionCallback(message.id, nil, true, false)
|
||||
case let .callback(requiresPassword, data):
|
||||
controllerInteraction.requestMessageActionCallback(message.id, data, false, requiresPassword)
|
||||
case let .switchInline(samePeer, query):
|
||||
case let .switchInline(samePeer, query, peerTypes):
|
||||
var botPeer: Peer?
|
||||
|
||||
var found = false
|
||||
@ -884,7 +884,7 @@ final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
|
||||
peerId = message.id.peerId
|
||||
}
|
||||
if let botPeer = botPeer, let addressName = botPeer.addressName {
|
||||
controllerInteraction.activateSwitchInline(peerId, "@\(addressName) \(query)")
|
||||
controllerInteraction.activateSwitchInline(peerId, "@\(addressName) \(query)", peerTypes)
|
||||
}
|
||||
case .payment:
|
||||
controllerInteraction.openCheckoutOrReceipt(message.id)
|
||||
|
@ -274,7 +274,7 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode {
|
||||
}, openMessageContextActions: { _, _, _, _ in
|
||||
}, navigateToMessage: { _, _ in }, navigateToMessageStandalone: { _ in
|
||||
}, navigateToThreadMessage: { _, _, _ in
|
||||
}, tapMessage: nil, clickThroughMessage: { }, toggleMessagesSelection: { _, _ in }, sendCurrentMessage: { _ in }, sendMessage: { _ in }, sendSticker: { _, _, _, _, _, _, _, _, _ in return false }, sendEmoji: { _, _, _ in }, sendGif: { _, _, _, _, _ in return false }, sendBotContextResultAsGif: { _, _, _, _, _, _ in return false }, requestMessageActionCallback: { _, _, _, _ in }, requestMessageActionUrlAuth: { _, _ in }, activateSwitchInline: { _, _ in }, openUrl: { [weak self] url, _, _, _ in
|
||||
}, tapMessage: nil, clickThroughMessage: { }, toggleMessagesSelection: { _, _ in }, sendCurrentMessage: { _ in }, sendMessage: { _ in }, sendSticker: { _, _, _, _, _, _, _, _, _ in return false }, sendEmoji: { _, _, _ in }, sendGif: { _, _, _, _, _ in return false }, sendBotContextResultAsGif: { _, _, _, _, _, _ in return false }, requestMessageActionCallback: { _, _, _, _ in }, requestMessageActionUrlAuth: { _, _ in }, activateSwitchInline: { _, _, _ in }, openUrl: { [weak self] url, _, _, _ in
|
||||
self?.openUrl(url)
|
||||
}, shareCurrentLocation: {}, shareAccountContact: {}, sendBotCommand: { _, _ in }, openInstantPage: { [weak self] message, associatedData in
|
||||
if let strongSelf = self, let navigationController = strongSelf.getNavigationController() {
|
||||
|
@ -97,7 +97,7 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, UIGestu
|
||||
return false
|
||||
}, requestMessageActionCallback: { _, _, _, _ in
|
||||
}, requestMessageActionUrlAuth: { _, _ in
|
||||
}, activateSwitchInline: { _, _ in
|
||||
}, activateSwitchInline: { _, _, _ in
|
||||
}, openUrl: { _, _, _, _ in
|
||||
}, shareCurrentLocation: {
|
||||
}, shareAccountContact: {
|
||||
|
@ -2678,7 +2678,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate
|
||||
return false
|
||||
}, requestMessageActionCallback: { _, _, _, _ in
|
||||
}, requestMessageActionUrlAuth: { _, _ in
|
||||
}, activateSwitchInline: { _, _ in
|
||||
}, activateSwitchInline: { _, _, _ in
|
||||
}, openUrl: { [weak self] url, concealed, external, _ in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
|
@ -1457,7 +1457,7 @@ public final class SharedAccountContextImpl: SharedAccountContext {
|
||||
clickThroughMessage?()
|
||||
}, toggleMessagesSelection: { _, _ in }, sendCurrentMessage: { _ in }, sendMessage: { _ in }, sendSticker: { _, _, _, _, _, _, _, _, _ in return false }, sendEmoji: { _, _, _ in }, sendGif: { _, _, _, _, _ in return false }, sendBotContextResultAsGif: { _, _, _, _, _, _ in
|
||||
return false
|
||||
}, requestMessageActionCallback: { _, _, _, _ in }, requestMessageActionUrlAuth: { _, _ in }, activateSwitchInline: { _, _ in }, openUrl: { _, _, _, _ in }, shareCurrentLocation: {}, shareAccountContact: {}, sendBotCommand: { _, _ in }, openInstantPage: { _, _ in }, openWallpaper: { _ in }, openTheme: { _ in }, openHashtag: { _, _ in }, updateInputState: { _ in }, updateInputMode: { _ in }, openMessageShareMenu: { _ in
|
||||
}, requestMessageActionCallback: { _, _, _, _ in }, requestMessageActionUrlAuth: { _, _ in }, activateSwitchInline: { _, _, _ in }, openUrl: { _, _, _, _ in }, shareCurrentLocation: {}, shareAccountContact: {}, sendBotCommand: { _, _ in }, openInstantPage: { _, _ in }, openWallpaper: { _ in }, openTheme: { _ in }, openHashtag: { _, _ in }, updateInputState: { _ in }, updateInputMode: { _ in }, openMessageShareMenu: { _ in
|
||||
}, presentController: { _, _ in
|
||||
}, presentControllerInCurrent: { _, _ in
|
||||
}, navigationController: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user