Skip to content

Commit 5377dbd

Browse files
committed
Re-make refresh() method for feedview post
1 parent 2e6b3a5 commit 5377dbd

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

Sources/ATProtoKit/Errors/ATProtoError.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,12 @@ public enum GetOriginalPostsFromQuotePostsError: ATProtoError {
457457
/// The original post was detacted from the quote post.
458458
case recordDetacted
459459
}
460+
461+
/// An error type related to refreshing feed view posts.
462+
public enum FeedViewPostDefinitionError: ATProtoError {
463+
464+
/// The index number is too high.
465+
///
466+
/// - Parameter index: The index number.
467+
case indexTooHigh(index: Int)
468+
}

Sources/ATProtoKit/Models/Common/ATRecordViewProtocol/ATRecordViewProtocolExtensions.swift

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,39 @@ extension AppBskyLexicon.Feed.FeedViewPostDefinition: Identifiable {
5858
return self.post.uri
5959
}
6060

61-
public func refresh(with sessionConfiguration: SessionConfiguration) async throws -> AppBskyLexicon.Feed.FeedViewPostDefinition {
62-
let atProto = await ATProtoKit(sessionConfiguration: sessionConfiguration, canUseBlueskyRecords: false)
63-
let record = try await atProto.getFeed(by: self.post.uri)
61+
/// Refreshes the record view with updated information.
62+
///
63+
/// You need to pass in the instance of ``SessionConfiguration`` in order to establish
64+
/// a connection. Once that happens, use the appropriate method to get the record view.
65+
/// For example, for ``AppBskyLexicon/Feed/PostViewDefinition``, you can use
66+
/// ``ATProtoKit/ATProtoKit/getPosts(_:)``, which returns that object.
67+
///
68+
///
69+
///
70+
/// - Parameters:
71+
/// - atProtoKitConfiguration: An instance of ``ATProtoKit/ATProtoKit``.
72+
/// - array: The array of the
73+
/// - index: The index number
74+
/// - feedURI: The URI of the feed.
75+
/// - Returns: An updated version of the feed's array.
76+
///
77+
/// - Throws: An ``ATProtoError``-conforming error type, depending on the issue. Go to
78+
/// ``ATAPIError`` and ``ATRequestPrepareError`` for more details.
79+
public func refresh(
80+
with atProtoKitConfiguration: ATProtoKit,
81+
from array: [AppBskyLexicon.Feed.FeedViewPostDefinition],
82+
at index: Int,
83+
feedURI: String
84+
) async throws -> [AppBskyLexicon.Feed.FeedViewPostDefinition] {
85+
let post = try await atProtoKitConfiguration.getFeed(by: feedURI).feed[index]
86+
87+
if index > 99 {
88+
throw FeedViewPostDefinitionError.indexTooHigh(index: index)
89+
}
6490

65-
return record.feed[0]
91+
var newArray = array
92+
newArray[index] = post
93+
return newArray
6694
}
6795
}
6896

0 commit comments

Comments
 (0)