~ knotless Search/
↑↓ move↵ open⇧↵ all results

geesawra.industries/old-fella

Old people's social media app

0
1

feat(posts): share and copy post links

Merged geesawra.industries asked to merge into main from geesawra.industries/old-fella:feat/post-sharing
Sources/Oldsky/BlueskyService.swift+3−0
@@ -353,6 +353,9 @@ struct MockBlueskyService: BlueskyService {
posts[0].text = "A thread starts here with enough text to wrap across several lines. This text must stay above the quoted post."
posts[0].quote = Post.Quote(postID: "post-3", author: authors[2], text: "The quoted post.")
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-share") {
posts.insert(Post(id: "at://did:plc:sharetest/app.bsky.feed.post/abc123", author: authors[0], text: "A post to share.", likeCount: 0, repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyIDs: []), at: 0)
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-facets") {
let rootText = "Root context: @alex.example shared https://oldsky.app/post?uri=post-2 and https://example.com/reply."
posts[0].text = rootText
Sources/Oldsky/Models.swift+14−0
@@ -144,6 +144,20 @@ struct Post: Identifiable, Equatable {
var externalTitle: String? = nil
var externalDescription: String? = nil
var shareURL: URL? {
let prefix = "at://"
guard id.hasPrefix(prefix) else { return nil }
let parts = id.dropFirst(prefix.count).split(separator: "/", omittingEmptySubsequences: false)
guard parts.count == 3, parts[1] == "app.bsky.feed.post",
!parts[0].isEmpty, !parts[2].isEmpty else { return nil }
let actorCharacters = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:-")
let keyCharacters = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._~-")
guard parts[0].unicodeScalars.allSatisfy(actorCharacters.contains),
parts[2].unicodeScalars.allSatisfy(keyCharacters.contains),
parts[2] != ".", parts[2] != ".." else { return nil }
return URL(string: "https://bsky.app/profile/\(parts[0])/post/\(parts[2])")
}
static func destination(for url: URL) -> MediaDestination {
let path = url.path.lowercased()
if path.hasSuffix(".gif") { return .gif }
Sources/Oldsky/OldskyApp.swift+19−1
@@ -1351,6 +1351,24 @@ struct PostRow: View {
actionButton(title: "Quote", label: "Quote", icon: "quote.bubble") { openComposer(nil, post.id) }
.labelStyle(.iconOnly)
.accessibilityIdentifier(accessibilityIdentifier("quoteButton"))
if let url = post.shareURL {
Menu {
ShareLink(item: url) {
Label("Share post", systemImage: "square.and.arrow.up")
}
Button {
UIPasteboard.general.url = url
} label: {
Label("Copy link", systemImage: "link")
}
} label: {
Image(systemName: "square.and.arrow.up")
.frame(maxWidth: .infinity, minHeight: 44)
.contentShape(Rectangle())
}
.accessibilityLabel("Share post")
.accessibilityIdentifier(accessibilityIdentifier("shareButton-\(post.id)"))
}
Spacer(minLength: 0)
if post.author.id != model.account?.id {
Button {
@@ -1372,7 +1390,7 @@ struct PostRow: View {
}
private enum PostTextFacets {
enum PostTextFacets {
static func render(_ text: String, facets: [PostFacet]) -> AttributedString {
var result = AttributedString(text)
let utf8 = text.utf8
Sources/Oldsky/PostLinks.swift+3−4
@@ -29,10 +29,9 @@ struct PostLinks: View {
}
private func internalPostID(for url: URL) -> String? {
guard url.host == "oldsky.app" else { return nil }
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
let uri = components.queryItems?.first(where: { $0.name == "uri" })?.value else { return nil }
return uri
var postID: String?
_ = PostTextFacets.openInternalURL(url, openActor: { _ in }, openPost: { postID = $0 })
return postID
}
}
Tests/OldskyTests/AppModelTests.swift+16−0
@@ -23,6 +23,22 @@ final class ImageTestProtocol: URLProtocol {
@MainActor
final class AppModelTests: XCTestCase {
func testPostShareURLUsesRecordURIAndOpensInApp() {
func post(_ id: String) -> Post {
Post(id: id, author: Post.Author(id: "other", name: "Other", handle: "changed.example"), text: "", likeCount: 0, repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyIDs: [])
}
let uri = "at://did:plc:sharetest/app.bsky.feed.post/abc123"
let url = post(uri).shareURL!
XCTAssertEqual(url.absoluteString, "https://bsky.app/profile/did:plc:sharetest/post/abc123")
var opened: String?
XCTAssertTrue(PostTextFacets.openInternalURL(url, openActor: { _ in }, openPost: { opened = $0 }))
XCTAssertEqual(opened, uri)
XCTAssertEqual(post("at://alice.example/app.bsky.feed.post/key-1").shareURL?.absoluteString, "https://bsky.app/profile/alice.example/post/key-1")
for invalid in ["post-1", "at://did:plc:test/app.bsky.feed.like/key", "at://did:plc:test/app.bsky.feed.post/", "at://did:plc:test/app.bsky.feed.post/../extra", "at://did:plc:test/app.bsky.feed.post/a?b"] {
XCTAssertNil(post(invalid).shareURL, invalid)
}
}
func testModerationRecoveryDestination() {
XCTAssertEqual(BlueskyLinks.moderation.absoluteString, "https://bsky.app/moderation")
}
Tests/OldskyUITests/OldskyUITests.swift+19−0
@@ -1,6 +1,25 @@
import XCTest
final class OldskyUITests: XCTestCase {
func testPostShareActionsInFeedAndDetail() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-share"]
app.launch()
let uri = "at://did:plc:sharetest/app.bsky.feed.post/abc123"
let share = app.buttons["shareButton-\(uri)"].firstMatch
XCTAssertTrue(share.waitForExistence(timeout: 5))
share.tap()
XCTAssertTrue(app.buttons["Copy link"].waitForExistence(timeout: 5))
app.buttons["Copy link"].tap()
app.buttons["postText-\(uri)"].firstMatch.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
let detailShare = app.buttons["shareButton-\(uri)"].firstMatch
XCTAssertTrue(detailShare.waitForExistence(timeout: 5))
detailShare.tap()
app.buttons.matching(identifier: "Share post").element(boundBy: 1).tap()
XCTAssertTrue(app.otherElements["ActivityListView"].waitForExistence(timeout: 5) || app.buttons["Copy"].waitForExistence(timeout: 5))
}
func testMissingAltTextReminderAllowsEditingAndPosting() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images"]