This commit is contained in:
Marcin Czachursk 2023-01-15 13:31:37 +01:00
parent 5fbaacd365
commit 08ce50573e
1 changed files with 1 additions and 9 deletions

View File

@ -43,16 +43,8 @@ public class TimelineService {
public func getComments(for statusId: String, and accountData: AccountData) async throws -> [CommentViewModel] { public func getComments(for statusId: String, and accountData: AccountData) async throws -> [CommentViewModel] {
var commentViewModels: [CommentViewModel] = [] var commentViewModels: [CommentViewModel] = []
// Get first level of comments.
let client = MastodonClient(baseURL: accountData.serverUrl).getAuthenticated(token: accountData.accessToken ?? String.empty()) let client = MastodonClient(baseURL: accountData.serverUrl).getAuthenticated(token: accountData.accessToken ?? String.empty())
let context = try await client.getContext(for: statusId) try await self.getCommentDescendants(for: statusId, client: client, to: &commentViewModels)
// Iterate throught first level of comments and download descendants/
let descendants = context.descendants.toStatusViewModel()
for status in descendants {
commentViewModels.append(CommentViewModel(status: status, showDivider: true))
try await self.getCommentDescendants(for: status.id, client: client, to: &commentViewModels)
}
return commentViewModels return commentViewModels
} }