Skip to content

Commit

Permalink
Fix remnants of method signature change
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterJ93 committed Jul 9, 2024
1 parent 3d8cb4a commit 718fbff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,34 @@ extension ATProtoKit {
_ likeRecord: inout ATProtoTools.RecordQuery?) async throws {
switch record {
case .recordQuery(let recordQuery):
// Perform the fetch and validation based on recordQuery.
let output = try await self.getRepositoryRecord(from: recordQuery.repository, collection: recordQuery.collection,
recordKey: recordQuery.recordKey, recordCID: recordQuery.recordCID, pdsURL: sessionURL)
do {
// Perform the fetch and validation based on recordQuery.
let output = try await self.getRepositoryRecord(from: recordQuery.repository, collection: recordQuery.collection,
recordKey: recordQuery.recordKey, recordCID: recordQuery.recordCID, pdsURL: sessionURL)

switch output {
case .success(let result):
let recordURI = "at://\(recordQuery.repository)/\(recordQuery.collection)/\(recordQuery.recordKey)"
guard result.recordURI == recordURI else {
throw ATRequestPrepareError.invalidRecord
}
let recordURI = "at://\(recordQuery.repository)/\(recordQuery.collection)/\(recordQuery.recordKey)"

likeRecord = recordQuery
case .failure(let error):
throw error
guard output.recordURI == recordURI else {
throw ATRequestPrepareError.invalidRecord
}
} catch {
throw error
}

case .recordURI(let recordURI):
// Perform the fetch and validation based on the parsed URI.
let parsedURI = try ATProtoTools().parseURI(recordURI)
let output = try await self.getRepositoryRecord(from: parsedURI.repository, collection: parsedURI.collection,
recordKey: parsedURI.recordKey, recordCID: parsedURI.recordCID, pdsURL: sessionURL)
do {
// Perform the fetch and validation based on the parsed URI.
let parsedURI = try ATProtoTools().parseURI(recordURI)
let output = try await self.getRepositoryRecord(from: parsedURI.repository, collection: parsedURI.collection,
recordKey: parsedURI.recordKey, recordCID: parsedURI.recordCID, pdsURL: sessionURL)

switch output {
case .success(let result):
guard recordURI == result.recordURI else {
throw ATRequestPrepareError.invalidRecord
}
guard recordURI == output.recordURI else {
throw ATRequestPrepareError.invalidRecord
}

likeRecord = parsedURI
case .failure(let error):
throw error
likeRecord = parsedURI
} catch {
throw error
}
}
}
Expand Down
21 changes: 8 additions & 13 deletions Sources/ATProtoKit/Utilities/ATFacetParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,15 @@ public class ATFacetParser {

let mentionResult = try await ATProtoKit().resolveHandle(from: notATHandle, pdsURL: pdsURL)

switch mentionResult {
case .success(let resolveHandleOutput):
guard let start = mention["start"] as? Int, let end = mention["end"] as? Int else { return }

let mentionFacet = AppBskyLexicon.RichText.Facet(
index: AppBskyLexicon.RichText.Facet.ByteSlice(byteStart: start, byteEnd: end),
features: [.mention(AppBskyLexicon.RichText.Facet.Mention(did: resolveHandleOutput.handleDID))])

await facets.append(mentionFacet)
case .failure(let error):
print("Error: \(error)")
}
} catch {
guard let start = mention["start"] as? Int, let end = mention["end"] as? Int else { return }

let mentionFacet = AppBskyLexicon.RichText.Facet(
index: AppBskyLexicon.RichText.Facet.ByteSlice(byteStart: start, byteEnd: end),
features: [.mention(AppBskyLexicon.RichText.Facet.Mention(did: mentionResult.handleDID))])

await facets.append(mentionFacet)
} catch {
print("Error: \(error)")
}
}
}
Expand Down

0 comments on commit 718fbff

Please sign in to comment.