Recognize hashtags in posts on Akkoma and Pixelfed servers (#2261)

Fixes #2260
This commit is contained in:
Mackenzie 2025-05-27 01:03:03 -04:00 committed by GitHub
parent 7a14ce9e6f
commit 5591a6d52c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View file

@ -146,7 +146,8 @@ public enum SettingsStartingPoint {
}
public func handleStatus(status: AnyStatus, url: URL) -> OpenURLAction.Result {
if url.pathComponents.count == 3, url.pathComponents[1] == "tags",
if url.pathComponents.count == 3,
url.pathComponents[1] == "tags" || url.pathComponents[1] == "tag",
url.host() == status.account.url?.host(),
let tag = url.pathComponents.last
{
@ -155,6 +156,17 @@ public enum SettingsStartingPoint {
// That is on the same host as the person that posted the tag,
// i.e. not a link that matches the pattern but elsewhere on the internet
// In those circumstances, hijack the link and goto the tags page instead
// The second is "tags" on Mastodon and "tag" on Akkoma.
navigate(to: .hashTag(tag: tag, account: nil))
return .handled
} else if url.pathComponents.count == 4,
url.pathComponents[1] == "discover",
url.pathComponents[2] == "tags",
url.host() == status.account.url?.host(),
let tag = url.pathComponents.last
{
// Similar to above, but for ["/", "discover", "tags", "tagname"]
// as used in Pixelfed
navigate(to: .hashTag(tag: tag, account: nil))
return .handled
} else if let mention = status.mentions.first(where: { $0.url == url }) {

View file

@ -23,6 +23,24 @@ func testRouterTagsURL() {
#expect(router.path.first == .hashTag(tag: "test", account: nil))
}
@Test
@MainActor
func testRouterTagsAkkomaURL() {
let router = RouterPath()
let url = URL(string: "https://genserver.social/tag/test")!
_ = router.handle(url: url)
#expect(router.path.first == .hashTag(tag: "test", account: nil))
}
@Test
@MainActor
func testRouterTagsPixelfedURL() {
let router = RouterPath()
let url = URL(string: "https://pixelfed.social/discover/tags/test")!
_ = router.handle(url: url)
#expect(router.path.first == .hashTag(tag: "test", account: nil))
}
@Test
@MainActor
func testRouterLocalStatusURL() {