From 059a36c6b83bc9fd78b2c23eeb951536ad912839 Mon Sep 17 00:00:00 2001 From: Eric Andrews Date: Thu, 5 Oct 2023 18:27:33 -0400 Subject: [PATCH] fixed comments not showing up --- Mlem/Views/Tabs/Profile/User View.swift | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Mlem/Views/Tabs/Profile/User View.swift b/Mlem/Views/Tabs/Profile/User View.swift index aa611e43f..5b2ab843d 100644 --- a/Mlem/Views/Tabs/Profile/User View.swift +++ b/Mlem/Views/Tabs/Profile/User View.swift @@ -228,20 +228,26 @@ struct UserView: View { appState.setActiveAccount(updatedAccount) } - privateCommentTracker.comments = authoredContent.comments + // accumulate comments and posts so we don't update state more than we need to + var newComments = authoredContent.comments .sorted(by: { $0.comment.published > $1.comment.published }) .map { HierarchicalComment(comment: $0, children: [], parentCollapsed: false, collapsed: false) } - privatePostTracker.reset(with: authoredContent.posts.map { PostModel(from: $0) }) + var newPosts = authoredContent.posts.map { PostModel(from: $0) } + // add saved content, if present if let savedContent = savedContentData { - privateCommentTracker.comments = savedContent.comments - .sorted(by: { $0.comment.published > $1.comment.published }) - .map { HierarchicalComment(comment: $0, children: [], parentCollapsed: false, collapsed: false) } + newComments.append(contentsOf: + savedContent.comments + .sorted(by: { $0.comment.published > $1.comment.published }) + .map { HierarchicalComment(comment: $0, children: [], parentCollapsed: false, collapsed: false) }) - privatePostTracker.add(savedContent.posts.map { PostModel(from: $0) }) + newPosts.append(contentsOf: savedContent.posts.map { PostModel(from: $0) }) } + privateCommentTracker.comments = newComments + privatePostTracker.reset(with: newPosts) + userDetails = authoredContent.personView moderatedCommunities = authoredContent.moderates updateAvatarSubtext()