diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/viewmodel/CommentsRepository.kt b/android/src/main/kotlin/dev/msfjarvis/claw/android/viewmodel/CommentsRepository.kt index 55bc4f29..986a3378 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/viewmodel/CommentsRepository.kt +++ b/android/src/main/kotlin/dev/msfjarvis/claw/android/viewmodel/CommentsRepository.kt @@ -22,10 +22,7 @@ constructor( ) { suspend fun getSeenComments(postId: String) = - withContext(dbDispatcher) { - postCommentsQueries.getCommentIds(postId).executeAsOneOrNull() - ?: PostComments(postId = postId, commentIds = emptyList()) - } + withContext(dbDispatcher) { postCommentsQueries.getCommentIds(postId).executeAsOneOrNull() } suspend fun markSeenComments(postId: String, comments: List) { withContext(dbDispatcher) { diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentNode.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentNode.kt index 30f1e347..392024c3 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentNode.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentNode.kt @@ -65,10 +65,10 @@ internal class CommentNode( internal fun createListNode( comments: List, - commentState: PostComments, + commentState: PostComments?, ): MutableList { val commentNodes = mutableListOf() - val isUnread = { id: String -> !commentState.commentIds.contains(id) } + val isUnread = { id: String -> commentState?.commentIds?.contains(id) == false } for (i in comments.indices) { if (comments[i].parentComment == null) { diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentsPage.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentsPage.kt index 14c452e3..5853d753 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentsPage.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentsPage.kt @@ -33,7 +33,7 @@ fun CommentsPage( postId: String, postActions: PostActions, htmlConverter: HTMLConverter, - getSeenComments: suspend (String) -> PostComments, + getSeenComments: suspend (String) -> PostComments?, markSeenComments: (String, List) -> Unit, contentPadding: PaddingValues, modifier: Modifier = Modifier, @@ -48,9 +48,7 @@ fun CommentsPage( ) } val commentState by - produceState(initialValue = PostComments(postId, emptyList())) { - value = getSeenComments(postId) - } + produceState(initialValue = null) { value = getSeenComments(postId) } when (postDetails) { is Success<*> -> { diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentsPageImpl.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentsPageImpl.kt index 349b2360..f9cff833 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentsPageImpl.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentsPageImpl.kt @@ -53,7 +53,7 @@ internal fun CommentsPageInternal( details: UIPost, postActions: PostActions, htmlConverter: HTMLConverter, - commentState: PostComments, + commentState: PostComments?, markSeenComments: (String, List) -> Unit, openUserProfile: (String) -> Unit, contentPadding: PaddingValues, @@ -62,8 +62,8 @@ internal fun CommentsPageInternal( val context = LocalContext.current val commentNodes = createListNode(details.comments, commentState) LaunchedEffect(key1 = commentNodes) { - if (details.comments.isNotEmpty() && commentState.commentIds.isNotEmpty()) { - val unreadCount = details.comments.size - commentState.commentIds.size + if (details.comments.isNotEmpty() && !commentState?.commentIds.isNullOrEmpty()) { + val unreadCount = details.comments.size - (commentState?.commentIds?.size ?: 0) if (unreadCount > 0) { val text = when (unreadCount) {