Comments list improvements

This commit is contained in:
Marcin Czachursk 2023-01-15 14:11:48 +01:00
parent 08ce50573e
commit 94ae24d8f3
1 changed files with 7 additions and 4 deletions

View File

@ -44,18 +44,21 @@ public class TimelineService {
var commentViewModels: [CommentViewModel] = [] var commentViewModels: [CommentViewModel] = []
let client = MastodonClient(baseURL: accountData.serverUrl).getAuthenticated(token: accountData.accessToken ?? String.empty()) let client = MastodonClient(baseURL: accountData.serverUrl).getAuthenticated(token: accountData.accessToken ?? String.empty())
try await self.getCommentDescendants(for: statusId, client: client, to: &commentViewModels) try await self.getCommentDescendants(for: statusId, client: client, showDivider: true, to: &commentViewModels)
return commentViewModels return commentViewModels
} }
private func getCommentDescendants(for statusId: String, client: MastodonClientAuthenticated, to commentViewModels: inout [CommentViewModel]) async throws { private func getCommentDescendants(for statusId: String, client: MastodonClientAuthenticated, showDivider: Bool, to commentViewModels: inout [CommentViewModel]) async throws {
let context = try await client.getContext(for: statusId) let context = try await client.getContext(for: statusId)
let descendants = context.descendants.toStatusViewModel() let descendants = context.descendants.toStatusViewModel()
for status in descendants { for status in descendants {
commentViewModels.append(CommentViewModel(status: status, showDivider: false)) commentViewModels.append(CommentViewModel(status: status, showDivider: showDivider))
try await self.getCommentDescendants(for: status.id, client: client, to: &commentViewModels)
if status.repliesCount > 0 {
try await self.getCommentDescendants(for: status.id, client: client, showDivider: false, to: &commentViewModels)
}
} }
} }