Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterJ93 committed Oct 19, 2024
2 parents 2900d19 + 408fa1f commit de8c222
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
1 change: 1 addition & 0 deletions API_GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ The [Swift API Design Guidelines](https://www.swift.org/documentation/api-design
- decentralized identifier (DID)
- content identifer (CID)
- Namespaced Identifier (NSID)
- Personal Data Server (PDS)

## Lexicon Models
Lexicons are relevant to models and methods. Here are some general guidelines:
Expand Down
3 changes: 3 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Thank you for supporting `ATProtoKit`. Right now, it's just me at the moment, bu
- Joshua Holme
- GitHub: JoshuaHolme
- Bluesky: @josh.holme.social
- Aaron Vegh
- GitHub: aaronvegh
- Bluesky: @aaronvegh.bsky.social

## Security Contributions
If you've submitted any security contributions and they've been resolved, your name will be listed in here, along with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension ATProtoBluesky {
var resolvedReplyTo: AppBskyLexicon.Feed.PostRecord.ReplyReference? = nil
if let replyURI = replyTo {
do {
resolvedReplyTo = try await ATProtoTools().resolveReplyReferences(parentURI: replyURI)
resolvedReplyTo = try await ATProtoTools().resolveReplyReferences(parentURI: replyURI, session: session)
} catch {
throw error
}
Expand Down
18 changes: 12 additions & 6 deletions Sources/ATProtoKit/Utilities/ATProtoTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ public class ATProtoTools {

/// Resolves the reply references to prepare them for a later post record request.
///
/// - Parameter parentURI: The URI of the post record the current one is directly replying to.
/// - Parameters:
/// - parentURI: The URI of the post record the current one is directly replying to.
/// - session: The ``UserSession`` instance in relation to the reply. Optional.
/// Defaults to `nil`.
/// - Returns: A ``AppBskyLexicon/Feed/PostRecord/ReplyReference``.
public func resolveReplyReferences(parentURI: String) async throws -> AppBskyLexicon.Feed.PostRecord.ReplyReference {
let threadRecords = try await fetchRecordForURI(parentURI)
public func resolveReplyReferences(parentURI: String, session: UserSession? = nil) async throws -> AppBskyLexicon.Feed.PostRecord.ReplyReference {
let threadRecords = try await fetchRecordForURI(parentURI, session: session)

guard let parentRecord = threadRecords.value else {
return createReplyReference(from: threadRecords)
Expand Down Expand Up @@ -78,13 +81,16 @@ public class ATProtoTools {

/// Gets a record from the user's repository.
///
/// - Parameter uri: The URI of the record.
/// - Parameters:
/// - uri: The URI of the record.
/// - session: The ``UserSession`` instance in relation to the reply. Optional.
/// Defaults to `nil`.
/// - Returns: A ``ComAtprotoLexicon/Repository/GetRecordOutput``
public func fetchRecordForURI(_ uri: String) async throws -> ComAtprotoLexicon.Repository.GetRecordOutput {
public func fetchRecordForURI(_ uri: String, session: UserSession? = nil) async throws -> ComAtprotoLexicon.Repository.GetRecordOutput {
let query = try parseURI(uri)

do {
let record = try await ATProtoKit().getRepositoryRecord(from: query.repository, collection: query.collection, recordKey: query.recordKey, pdsURL: nil)
let record = try await ATProtoKit().getRepositoryRecord(from: query.repository, collection: query.collection, recordKey: query.recordKey, pdsURL: session?.pdsURL)

return record
} catch {
Expand Down
23 changes: 14 additions & 9 deletions Sources/ATProtoKit/Utilities/ExtensionHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,21 @@ extension URL {
///
///- Returns: The fragment component of the URL
public func hostname() -> String? {
let url = self

// Manually extract the hostname from the URL without using .host().
let hostname = url.absoluteString.split(separator: "//").last?.split(separator: "/").first

// Convert from Substring to a String.
if let hostname {
return String(hostname)
let absoluteString = self.absoluteString

// Find the range of "://" to extract the host component.
guard let schemeRangeEnd = absoluteString.range(of: "://")?.upperBound else {
return nil
}

return nil
// Extract everything after the scheme.
let remainder = absoluteString[schemeRangeEnd...]

// Find the first "/" or end of the string to isolate the host.
if let slashIndex = remainder.firstIndex(of: "/") {
return String(remainder[..<slashIndex])
} else {
return String(remainder)
}
}
}

0 comments on commit de8c222

Please sign in to comment.