mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 06:10:03 +00:00
Various fixes
This commit is contained in:
parent
07c46dfc7e
commit
4c697dcbfa
@ -292,12 +292,12 @@ public struct ChatControllerInitialAttachBotStart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public struct ChatControllerInitialBotAppStart {
|
public struct ChatControllerInitialBotAppStart {
|
||||||
public let botApp: BotApp
|
public let botApp: BotApp?
|
||||||
public let payload: String?
|
public let payload: String?
|
||||||
public let justInstalled: Bool
|
public let justInstalled: Bool
|
||||||
public let compact: Bool
|
public let compact: Bool
|
||||||
|
|
||||||
public init(botApp: BotApp, payload: String?, justInstalled: Bool, compact: Bool) {
|
public init(botApp: BotApp?, payload: String?, justInstalled: Bool, compact: Bool) {
|
||||||
self.botApp = botApp
|
self.botApp = botApp
|
||||||
self.payload = payload
|
self.payload = payload
|
||||||
self.justInstalled = justInstalled
|
self.justInstalled = justInstalled
|
||||||
|
|||||||
@ -402,12 +402,13 @@ public extension ChatControllerImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func presentBotApp(botApp: BotApp, botPeer: EnginePeer, payload: String?, compact: Bool, concealed: Bool = false, commit: @escaping () -> Void = {}) {
|
func presentBotApp(botApp: BotApp?, botPeer: EnginePeer, payload: String?, compact: Bool, concealed: Bool = false, commit: @escaping () -> Void = {}) {
|
||||||
guard let peerId = self.chatLocation.peerId else {
|
guard let peerId = self.chatLocation.peerId else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.attachmentController?.dismiss(animated: true, completion: nil)
|
self.attachmentController?.dismiss(animated: true, completion: nil)
|
||||||
|
|
||||||
|
if let botApp {
|
||||||
let openBotApp: (Bool, Bool) -> Void = { [weak self] allowWrite, justInstalled in
|
let openBotApp: (Bool, Bool) -> Void = { [weak self] allowWrite, justInstalled in
|
||||||
guard let strongSelf = self else {
|
guard let strongSelf = self else {
|
||||||
return
|
return
|
||||||
@ -553,5 +554,8 @@ public extension ChatControllerImpl {
|
|||||||
openBotApp(false, false)
|
openBotApp(false, false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
self.context.sharedContext.openWebApp(context: self.context, parentController: self, updatedPresentationData: self.updatedPresentationData, peer: botPeer, threadId: nil, buttonText: "", url: "", simple: true, source: .generic, skipTermsOfService: false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9211,10 +9211,15 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
|||||||
let _ = (strongSelf.context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId.id))
|
let _ = (strongSelf.context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId.id))
|
||||||
|> deliverOnMainQueue).startStandalone(next: { [weak self] peer in
|
|> deliverOnMainQueue).startStandalone(next: { [weak self] peer in
|
||||||
if let strongSelf = self, let peer {
|
if let strongSelf = self, let peer {
|
||||||
strongSelf.presentBotApp(botApp: botAppStart.botApp, botPeer: peer, payload: botAppStart.payload, compact: botAppStart.compact, concealed: concealed, commit: {
|
if let botApp = botAppStart.botApp {
|
||||||
|
strongSelf.presentBotApp(botApp: botApp, botPeer: peer, payload: botAppStart.payload, compact: botAppStart.compact, concealed: concealed, commit: {
|
||||||
dismissWebAppControllers()
|
dismissWebAppControllers()
|
||||||
commit()
|
commit()
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
strongSelf.context.sharedContext.openWebApp(context: strongSelf.context, parentController: strongSelf, updatedPresentationData: strongSelf.updatedPresentationData, peer: peer, threadId: nil, buttonText: "", url: "", simple: true, source: .generic, skipTermsOfService: false)
|
||||||
|
commit()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -292,6 +292,19 @@ public func parseInternalUrl(sharedContext: SharedAccountContext, query: String)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return .startAttach(peerName, value, choose)
|
return .startAttach(peerName, value, choose)
|
||||||
|
} else if queryItem.name == "startapp" {
|
||||||
|
var compact = false
|
||||||
|
if let queryItems = components.queryItems {
|
||||||
|
for queryItem in queryItems {
|
||||||
|
if let value = queryItem.value {
|
||||||
|
if queryItem.name == "mode", value == "compact" {
|
||||||
|
compact = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return .peer(.name(peerName), .appStart("", queryItem.value, compact))
|
||||||
} else if queryItem.name == "story" {
|
} else if queryItem.name == "story" {
|
||||||
if let id = Int32(value) {
|
if let id = Int32(value) {
|
||||||
return .peer(.name(peerName), .story(id))
|
return .peer(.name(peerName), .story(id))
|
||||||
@ -321,6 +334,19 @@ public func parseInternalUrl(sharedContext: SharedAccountContext, query: String)
|
|||||||
return .peer(.name(peerName), .boost)
|
return .peer(.name(peerName), .boost)
|
||||||
} else if queryItem.name == "profile" {
|
} else if queryItem.name == "profile" {
|
||||||
return .peer(.name(peerName), .profile)
|
return .peer(.name(peerName), .profile)
|
||||||
|
} else if queryItem.name == "startapp" {
|
||||||
|
var compact = false
|
||||||
|
if let queryItems = components.queryItems {
|
||||||
|
for queryItem in queryItems {
|
||||||
|
if let value = queryItem.value {
|
||||||
|
if queryItem.name == "mode", value == "compact" {
|
||||||
|
compact = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return .peer(.name(peerName), .appStart("", nil, compact))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -720,6 +746,13 @@ private func resolveInternalUrl(context: AccountContext, url: ParsedInternalUrl)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case let .appStart(name, payload, compact):
|
case let .appStart(name, payload, compact):
|
||||||
|
if name.isEmpty {
|
||||||
|
if case let .user(user) = peer, let botInfo = user.botInfo, botInfo.flags.contains(.hasWebApp) {
|
||||||
|
return .single(.result(.peer(peer._asPeer(), .withBotApp(ChatControllerInitialBotAppStart(botApp: nil, payload: payload, justInstalled: false, compact: compact)))))
|
||||||
|
} else {
|
||||||
|
return .single(.result(.peer(peer._asPeer(), .chat(textInputState: nil, subject: nil, peekData: nil))))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
return .single(.progress) |> then(context.engine.messages.getBotApp(botId: peer.id, shortName: name, cached: false)
|
return .single(.progress) |> then(context.engine.messages.getBotApp(botId: peer.id, shortName: name, cached: false)
|
||||||
|> map(Optional.init)
|
|> map(Optional.init)
|
||||||
|> `catch` { _ -> Signal<BotApp?, NoError> in
|
|> `catch` { _ -> Signal<BotApp?, NoError> in
|
||||||
@ -732,6 +765,7 @@ private func resolveInternalUrl(context: AccountContext, url: ParsedInternalUrl)
|
|||||||
return .single(.result(.peer(peer._asPeer(), .chat(textInputState: nil, subject: nil, peekData: nil))))
|
return .single(.result(.peer(peer._asPeer(), .chat(textInputState: nil, subject: nil, peekData: nil))))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
case let .channelMessage(id, timecode):
|
case let .channelMessage(id, timecode):
|
||||||
if case let .channel(channel) = peer, channel.flags.contains(.isForum) {
|
if case let .channel(channel) = peer, channel.flags.contains(.isForum) {
|
||||||
let messageId = MessageId(peerId: channel.id, namespace: Namespaces.Message.Cloud, id: id)
|
let messageId = MessageId(peerId: channel.id, namespace: Namespaces.Message.Cloud, id: id)
|
||||||
|
|||||||
@ -333,9 +333,6 @@ public final class WebAppController: ViewController, AttachmentContainable {
|
|||||||
if let parsedUrl = URL(string: url) {
|
if let parsedUrl = URL(string: url) {
|
||||||
self.webView?.load(URLRequest(url: parsedUrl))
|
self.webView?.load(URLRequest(url: parsedUrl))
|
||||||
}
|
}
|
||||||
|
|
||||||
self.checkBotIdAndUrl(url)
|
|
||||||
|
|
||||||
if let keepAliveSignal = controller.keepAliveSignal {
|
if let keepAliveSignal = controller.keepAliveSignal {
|
||||||
self.keepAliveDisposable = (keepAliveSignal
|
self.keepAliveDisposable = (keepAliveSignal
|
||||||
|> deliverOnMainQueue).start(error: { [weak self] _ in
|
|> deliverOnMainQueue).start(error: { [weak self] _ in
|
||||||
@ -355,7 +352,6 @@ public final class WebAppController: ViewController, AttachmentContainable {
|
|||||||
guard let strongSelf = self else {
|
guard let strongSelf = self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
strongSelf.checkBotIdAndUrl(result.url)
|
|
||||||
if let parsedUrl = URL(string: result.url) {
|
if let parsedUrl = URL(string: result.url) {
|
||||||
strongSelf.queryId = result.queryId
|
strongSelf.queryId = result.queryId
|
||||||
strongSelf.webView?.load(URLRequest(url: parsedUrl))
|
strongSelf.webView?.load(URLRequest(url: parsedUrl))
|
||||||
@ -368,17 +364,16 @@ public final class WebAppController: ViewController, AttachmentContainable {
|
|||||||
guard let self, let controller = self.controller else {
|
guard let self, let controller = self.controller else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard case let .peer(peer, params) = result, let peer, case let .withBotApp(appStart) = params else {
|
guard case let .peer(peer, params) = result, let peer, case let .withBotApp(appStart) = params, let botApp = appStart.botApp else {
|
||||||
controller.dismiss()
|
controller.dismiss()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let _ = (self.context.engine.messages.requestAppWebView(peerId: peer.id, appReference: .id(id: appStart.botApp.id, accessHash: appStart.botApp.accessHash), payload: appStart.payload, themeParams: generateWebAppThemeParams(self.presentationData.theme), compact: appStart.compact, allowWrite: true)
|
let _ = (self.context.engine.messages.requestAppWebView(peerId: peer.id, appReference: .id(id: botApp.id, accessHash: botApp.accessHash), payload: appStart.payload, themeParams: generateWebAppThemeParams(self.presentationData.theme), compact: appStart.compact, allowWrite: true)
|
||||||
|> deliverOnMainQueue).startStandalone(next: { [weak self] result in
|
|> deliverOnMainQueue).startStandalone(next: { [weak self] result in
|
||||||
guard let self, let parsedUrl = URL(string: result.url) else {
|
guard let self, let parsedUrl = URL(string: result.url) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.checkBotIdAndUrl(result.url)
|
self.controller?.titleView?.title = WebAppTitle(title: botApp.title, counter: self.presentationData.strings.WebApp_Miniapp, isVerified: controller.botVerified)
|
||||||
self.controller?.titleView?.title = WebAppTitle(title: appStart.botApp.title, counter: self.presentationData.strings.WebApp_Miniapp, isVerified: controller.botVerified)
|
|
||||||
self.webView?.load(URLRequest(url: parsedUrl))
|
self.webView?.load(URLRequest(url: parsedUrl))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -391,8 +386,6 @@ public final class WebAppController: ViewController, AttachmentContainable {
|
|||||||
strongSelf.queryId = result.queryId
|
strongSelf.queryId = result.queryId
|
||||||
strongSelf.webView?.load(URLRequest(url: parsedUrl))
|
strongSelf.webView?.load(URLRequest(url: parsedUrl))
|
||||||
|
|
||||||
strongSelf.checkBotIdAndUrl(result.url)
|
|
||||||
|
|
||||||
if let keepAliveSignal = result.keepAliveSignal {
|
if let keepAliveSignal = result.keepAliveSignal {
|
||||||
strongSelf.keepAliveDisposable = (keepAliveSignal
|
strongSelf.keepAliveDisposable = (keepAliveSignal
|
||||||
|> deliverOnMainQueue).start(error: { [weak self] _ in
|
|> deliverOnMainQueue).start(error: { [weak self] _ in
|
||||||
@ -412,14 +405,6 @@ public final class WebAppController: ViewController, AttachmentContainable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkBotIdAndUrl(_ url: String) {
|
|
||||||
// if url.hasPrefix("https://walletbot.me"), let botId = self.controller?.botId.id._internalGetInt64Value(), botId != 1985737506 {
|
|
||||||
// let alertController = textAlertController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, title: nil, text: "Bot id mismatch, please report steps to app developer", actions: [TextAlertAction(type: .defaultAction, title: self.presentationData.strings.Common_OK, action: {
|
|
||||||
// })])
|
|
||||||
// self.controller?.present(alertController, in: .window(.root))
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc fileprivate func mainButtonPressed() {
|
@objc fileprivate func mainButtonPressed() {
|
||||||
if let mainButtonState = self.mainButtonState, !mainButtonState.isVisible || !mainButtonState.isEnabled {
|
if let mainButtonState = self.mainButtonState, !mainButtonState.isVisible || !mainButtonState.isEnabled {
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user