Fix call issue

This commit is contained in:
Ali 2020-06-09 17:05:24 +04:00
parent 5ffff6fc84
commit 874396fbbb
5 changed files with 65 additions and 19 deletions

View File

@ -1726,11 +1726,8 @@ final class SharedApplicationContext {
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if #available(iOS 10.0, *) {
if let startCallIntent = userActivity.interaction?.intent as? SupportedStartCallIntent {
guard let context = self.contextValue?.context else {
return true
}
let startCall: (Int32) -> Void = { userId in
let _ = context.sharedContext.callManager?.requestCall(account: context.account, peerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: userId), endCurrentIfAny: false)
self.startCallWhenReady(accountId: nil, peerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: userId))
}
func cleanPhoneNumber(_ text: String) -> String {
@ -1776,6 +1773,9 @@ final class SharedApplicationContext {
case .phoneNumber:
let phoneNumber = cleanPhoneNumber(value)
if !phoneNumber.isEmpty {
guard let context = self.contextValue?.context else {
return true
}
let _ = (context.account.postbox.transaction { transaction -> PeerId? in
var result: PeerId?
for peerId in transaction.getContactPeerIds() {
@ -1907,13 +1907,35 @@ final class SharedApplicationContext {
}
private func openNotificationSettingsWhenReady() {
let signal = (self.authorizedContext()
let _ = (self.authorizedContext()
|> take(1)
|> deliverOnMainQueue).start(next: { context in
context.openNotificationSettings()
})
}
private func startCallWhenReady(accountId: AccountRecordId?, peerId: PeerId) {
let signal = self.sharedContextPromise.get()
|> take(1)
|> mapToSignal { sharedApplicationContext -> Signal<AuthorizedApplicationContext, NoError> in
if let accountId = accountId {
sharedApplicationContext.sharedContext.switchToAccount(id: accountId)
return self.authorizedContext()
|> filter { context in
context.context.account.id == accountId
}
|> take(1)
} else {
return self.authorizedContext()
|> take(1)
}
}
self.openChatWhenReadyDisposable.set((signal
|> deliverOnMainQueue).start(next: { context in
context.startCall(peerId: peerId)
}))
}
private func openChatWhenReady(accountId: AccountRecordId?, peerId: PeerId, messageId: MessageId? = nil, activateInput: Bool = false) {
let signal = self.sharedContextPromise.get()
|> take(1)

View File

@ -84,7 +84,8 @@ final class AuthorizedApplicationContext {
let notificationController: NotificationContainerController
private var scheduledOpenNotificationSettings: Bool = false
private var scheduledOperChatWithPeerId: (PeerId, MessageId?, Bool)?
private var scheduledOpenChatWithPeerId: (PeerId, MessageId?, Bool)?
private let scheduledCallPeerDisposable = MetaDisposable()
private var scheduledOpenExternalUrl: URL?
private let passcodeStatusDisposable = MetaDisposable()
@ -738,6 +739,7 @@ final class AuthorizedApplicationContext {
self.termsOfServiceProceedToBotDisposable.dispose()
self.watchNavigateToMessageDisposable.dispose()
self.permissionsDisposable.dispose()
self.scheduledCallPeerDisposable.dispose()
}
func openNotificationSettings() {
@ -748,6 +750,23 @@ final class AuthorizedApplicationContext {
}
}
func startCall(peerId: PeerId) {
guard let appLockContext = self.context.sharedContext.appLockContext as? AppLockContextImpl else {
return
}
self.scheduledCallPeerDisposable.set((appLockContext.isCurrentlyLocked
|> filter {
!$0
}
|> take(1)
|> deliverOnMainQueue).start(next: { [weak self] _ in
guard let strongSelf = self else {
return
}
let _ = strongSelf.context.sharedContext.callManager?.requestCall(account: strongSelf.context.account, peerId: peerId, endCurrentIfAny: false)
}))
}
func openChatWithPeerId(peerId: PeerId, messageId: MessageId? = nil, activateInput: Bool = false) {
var visiblePeerId: PeerId?
if let controller = self.rootController.topViewController as? ChatControllerImpl, case let .peer(peerId) = controller.chatLocation {
@ -758,7 +777,7 @@ final class AuthorizedApplicationContext {
if self.rootController.rootTabController != nil {
self.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: self.rootController, context: self.context, chatLocation: .peer(peerId), subject: messageId.flatMap { .message($0) }, activateInput: activateInput))
} else {
self.scheduledOperChatWithPeerId = (peerId, messageId, activateInput)
self.scheduledOpenChatWithPeerId = (peerId, messageId, activateInput)
}
}
}

View File

@ -1223,7 +1223,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
if let strongSelf = self {
switch action {
case let .url(url):
var (cleanUrl, _) = parseUrl(url: url)
var (cleanUrl, _) = parseUrl(url: url, wasConcealed: false)
var canAddToReadingList = true
var canOpenIn = availableOpenInOptions(context: strongSelf.context, item: .url(url: url)).count > 1
let mailtoString = "mailto:"
@ -9272,7 +9272,7 @@ private final class ContextControllerContentSourceImpl: ContextControllerContent
}
}
func parseUrl(url: String) -> (string: String, concealed: Bool) {
func parseUrl(url: String, wasConcealed: Bool) -> (string: String, concealed: Bool) {
var parsedUrlValue: URL?
if let parsed = URL(string: url) {
parsedUrlValue = parsed
@ -9300,7 +9300,7 @@ func parseUrl(url: String) -> (string: String, concealed: Bool) {
hasNonLatin = true
}
}
var concealed = false
var concealed = wasConcealed
if hasLatin && hasNonLatin {
concealed = true
}
@ -9316,6 +9316,13 @@ func parseUrl(url: String) -> (string: String, concealed: Bool) {
concealed = false
}
let whitelistedSchemes: [String] = [
"tel",
]
if let parsedUrlValue = parsedUrlValue, let scheme = parsedUrlValue.scheme, whitelistedSchemes.contains(scheme) {
concealed = false
}
return (rawDisplayUrl, concealed)
}
@ -9356,10 +9363,8 @@ func openUserGeneratedUrl(context: AccountContext, url: String, concealed: Bool,
}))
}
let (parsedString, parsedConcealed) = parseUrl(url: url)
if parsedConcealed {
concealed = true
}
let (parsedString, parsedConcealed) = parseUrl(url: url, wasConcealed: concealed)
concealed = parsedConcealed
if concealed {
var rawDisplayUrl: String = parsedString

View File

@ -244,7 +244,7 @@ final class ListMessageSnippetItemNode: ListMessageNode {
isInstantView = true
}
let (parsedUrl, _) = parseUrl(url: content.url)
let (parsedUrl, _) = parseUrl(url: content.url, wasConcealed: false)
primaryUrl = parsedUrl
@ -316,7 +316,7 @@ final class ListMessageSnippetItemNode: ListMessageNode {
}
let tempUrlString = nsString.substring(with: range)
var (urlString, concealed) = parseUrl(url: tempUrlString)
var (urlString, concealed) = parseUrl(url: tempUrlString, wasConcealed: false)
let rawUrlString = urlString
var parsedUrl = URL(string: urlString)
@ -338,7 +338,7 @@ final class ListMessageSnippetItemNode: ListMessageNode {
}
let mutableDescriptionText = NSMutableAttributedString()
let (messageTextUrl, _) = parseUrl(url: item.message.text)
let (messageTextUrl, _) = parseUrl(url: item.message.text, wasConcealed: false)
if messageTextUrl != rawUrlString {
mutableDescriptionText.append(NSAttributedString(string: item.message.text + "\n", font: descriptionFont, textColor: item.theme.list.itemSecondaryTextColor))

View File

@ -91,7 +91,7 @@ func handleTextLinkActionImpl(context: AccountContext, peerId: PeerId?, navigate
case .tap:
switch itemLink {
case .url(let url, var concealed):
let (parsedString, parsedConcealed) = parseUrl(url: url)
let (parsedString, parsedConcealed) = parseUrl(url: url, wasConcealed: false)
if parsedConcealed {
concealed = true
}
@ -128,7 +128,7 @@ func handleTextLinkActionImpl(context: AccountContext, peerId: PeerId?, navigate
let canOpenIn = availableOpenInOptions(context: context, item: .url(url: url)).count > 1
let openText = canOpenIn ? presentationData.strings.Conversation_FileOpenIn : presentationData.strings.Conversation_LinkDialogOpen
let actionSheet = ActionSheetController(presentationData: presentationData)
let (displayUrl, _) = parseUrl(url: url)
let (displayUrl, _) = parseUrl(url: url, wasConcealed: false)
actionSheet.setItemGroups([ActionSheetItemGroup(items: [
ActionSheetTextItem(title: displayUrl),
ActionSheetButtonItem(title: openText, color: .accent, action: { [weak actionSheet] in