From d9c0c75782a311d1674e7aeb767073c772a997ba Mon Sep 17 00:00:00 2001 From: CMK Date: Thu, 8 Jul 2021 16:55:46 +0800 Subject: [PATCH] fix: app may not response to link for some server issue. ticket: #18624MBA --- Mastodon.xcodeproj/project.pbxproj | 2 +- .../xcschemes/xcschememanagement.plist | 4 +- .../xcshareddata/swiftpm/Package.resolved | 4 +- .../StatusProvider/StatusProviderFacade.swift | 40 +++++++++++++------ 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index 26e91f96..b8b64df8 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -4841,7 +4841,7 @@ repositoryURL = "https://github.com/TwidereProject/MetaTextView.git"; requirement = { kind = exactVersion; - version = 1.3.0; + version = 1.3.1; }; }; DB0E2D2C26833FF600865C3C /* XCRemoteSwiftPackageReference "Nuke-FLAnimatedImage-Plugin" */ = { diff --git a/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist b/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist index ecde1bcc..ca6031c4 100644 --- a/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist @@ -12,7 +12,7 @@ CoreDataStack.xcscheme_^#shared#^_ orderHint - 20 + 21 Mastodon - ASDK.xcscheme_^#shared#^_ @@ -37,7 +37,7 @@ NotificationService.xcscheme_^#shared#^_ orderHint - 21 + 22 SuppressBuildableAutocreation diff --git a/Mastodon.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Mastodon.xcworkspace/xcshareddata/swiftpm/Package.resolved index 1f3cc314..5118c78b 100644 --- a/Mastodon.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Mastodon.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -114,8 +114,8 @@ "repositoryURL": "https://github.com/TwidereProject/MetaTextView.git", "state": { "branch": null, - "revision": "e2049e14ef411c6810d53c1baf553b5161c6678f", - "version": "1.3.0" + "revision": "9021b330dd72898583f62ee7f4c98768d72e7654", + "version": "1.3.1" } }, { diff --git a/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift b/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift index eff4ad12..e732789e 100644 --- a/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift +++ b/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift @@ -128,12 +128,10 @@ extension StatusProviderFacade { static func responseToStatusActiveLabelAction(provider: StatusProvider, cell: UITableViewCell, activeLabel: ActiveLabel, didTapEntity entity: ActiveEntity) { switch entity.type { - case .hashtag(let text, _): - let hashtagTimelienViewModel = HashtagTimelineViewModel(context: provider.context, hashtag: text) - provider.coordinator.present(scene: .hashtagTimeline(viewModel: hashtagTimelienViewModel), from: provider, transition: .show) - case .mention(let text, _): - coordinateToStatusMentionProfileScene(for: .primary, provider: provider, cell: cell, mention: text) - case .url(_, _, let url, _): + case .url(_, _, let url, _), + .mention(let url, _) where url.lowercased().hasPrefix("http"): + // note: + // some server mark the normal url as "u-url" class. : guard let url = URL(string: url) else { return } if let domain = provider.context.authenticationService.activeMastodonAuthenticationBox.value?.domain, url.host == domain, url.pathComponents.count >= 4, @@ -146,6 +144,12 @@ extension StatusProviderFacade { } else { provider.coordinator.present(scene: .safari(url: url), from: nil, transition: .safariPresent(animated: true, completion: nil)) } + case .hashtag(let text, _): + let hashtagTimelienViewModel = HashtagTimelineViewModel(context: provider.context, hashtag: text) + provider.coordinator.present(scene: .hashtagTimeline(viewModel: hashtagTimelienViewModel), from: provider, transition: .show) + case .mention(let text, let userInfo): + let href = userInfo?["href"] as? String + coordinateToStatusMentionProfileScene(for: .primary, provider: provider, cell: cell, mention: text, href: href) default: break } @@ -153,7 +157,10 @@ extension StatusProviderFacade { static func responseToStatusMetaTextAction(provider: StatusProvider, cell: UITableViewCell, metaText: MetaText, didSelectMeta meta: Meta) { switch meta { - case .url(_, _, let url, _): + case .url(_, _, let url, _), + .mention(_, let url, _) where url.lowercased().hasPrefix("http"): + // note: + // some server mark the normal url as "u-url" class. highlighted content is a URL guard let url = URL(string: url) else { return } if let domain = provider.context.authenticationService.activeMastodonAuthenticationBox.value?.domain, url.host == domain, url.pathComponents.count >= 4, @@ -169,8 +176,9 @@ extension StatusProviderFacade { case .hashtag(_, let hashtag, _): let hashtagTimelineViewModel = HashtagTimelineViewModel(context: provider.context, hashtag: hashtag) provider.coordinator.present(scene: .hashtagTimeline(viewModel: hashtagTimelineViewModel), from: provider, transition: .show) - case .mention(_, let mention, _): - coordinateToStatusMentionProfileScene(for: .primary, provider: provider, cell: cell, mention: mention) + case .mention(_, let mention, let userInfo): + let href = userInfo?["href"] as? String + coordinateToStatusMentionProfileScene(for: .primary, provider: provider, cell: cell, mention: mention, href: href) default: break } @@ -208,17 +216,17 @@ extension StatusProviderFacade { } #endif - private static func coordinateToStatusMentionProfileScene(for target: Target, provider: StatusProvider, cell: UITableViewCell, mention: String) { + private static func coordinateToStatusMentionProfileScene(for target: Target, provider: StatusProvider, cell: UITableViewCell, mention: String, href: String?) { provider.status(for: cell, indexPath: nil) .sink { [weak provider] status in guard let provider = provider else { return } guard let status = status else { return } - coordinateToStatusMentionProfileScene(for: target, provider: provider, status: status, mention: mention) + coordinateToStatusMentionProfileScene(for: target, provider: provider, status: status, mention: mention, href: href) } .store(in: &provider.disposeBag) } - private static func coordinateToStatusMentionProfileScene(for target: Target, provider: StatusProvider, status: Status, mention: String) { + private static func coordinateToStatusMentionProfileScene(for target: Target, provider: StatusProvider, status: Status, mention: String, href: String?) { guard let activeMastodonAuthenticationBox = provider.context.authenticationService.activeMastodonAuthenticationBox.value else { return } let domain = activeMastodonAuthenticationBox.domain @@ -230,7 +238,13 @@ extension StatusProviderFacade { }() // cannot continue without meta - guard let mentionMeta = (status.mentions ?? Set()).first(where: { $0.username == mention }) else { return } + guard let mentionMeta = (status.mentions ?? Set()).first(where: { $0.username == mention }) else { + // present web page if possible + if let url = href.flatMap({ URL(string: $0) }) { + provider.coordinator.present(scene: .safari(url: url), from: provider, transition: .safariPresent(animated: true, completion: nil)) + } + return + } let userID = mentionMeta.id