Skip to content

Commit 7e4893e

Browse files
Restore in-app opening of mentions and hashtags
As previously in MetaText, rely on matching to the mentions and tags provided with the Status by the server. Contributes to IOS-430
1 parent dfad61f commit 7e4893e

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

Mastodon/In Progress New Layout and Datamodel/Timeline/HomeTimelineListViewController.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,13 @@ private struct HomeTimelinePostRowView: View {
777777
.onTapGesture {
778778
viewModel.openThreadView()
779779
}
780-
780+
.environment(\.openURL, OpenURLAction { url in
781+
if viewModel.openURL(url) {
782+
return .handled
783+
} else {
784+
return .systemAction(url)
785+
}
786+
})
781787

782788
if let attachment = viewModel.fullPost?.actionablePost?.content.attachment {
783789
switch attachment {
@@ -1084,6 +1090,20 @@ struct AttributedStringDisplayInfo {
10841090
false))))), transition: .show)
10851091
}
10861092

1093+
func openURL(_ url: URL) -> Bool {
1094+
if let mention = fullPost?.actionablePost?.content.htmlWithEntities?.mentions.first(where: { $0.url == url.absoluteString }) {
1095+
goToProfile(mention)
1096+
return true
1097+
} else if let hashtag = fullPost?.actionablePost?.content.htmlWithEntities?.tags.first(where: { $0.name.lowercased() == url.lastPathComponent.lowercased() && url.pathComponents.contains("tags") }) {
1098+
guard let currentUser = AuthenticationServiceProvider.shared.currentActiveUser.value else { return false }
1099+
let hashtagTimelineViewModel = HashtagTimelineViewModel(authenticationBox: currentUser, hashtag: hashtag.name)
1100+
actionHandler?.presentScene(.hashtagTimeline(viewModel: hashtagTimelineViewModel), transition: .show)
1101+
return true
1102+
} else {
1103+
return false
1104+
}
1105+
}
1106+
10871107
func didSelect(meta: Meta?) {
10881108
switch meta {
10891109
case .none:

0 commit comments

Comments
 (0)