Revert "refactor: make PostComments non-nullable"

This reverts commit 39e3d783cd.
This commit is contained in:
Harsh Shandilya 2024-09-16 12:30:37 +05:30
parent a0276c4873
commit 1dfea689c6
4 changed files with 8 additions and 13 deletions

View file

@ -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<Comment>) {
withContext(dbDispatcher) {

View file

@ -65,10 +65,10 @@ internal class CommentNode(
internal fun createListNode(
comments: List<Comment>,
commentState: PostComments,
commentState: PostComments?,
): MutableList<CommentNode> {
val commentNodes = mutableListOf<CommentNode>()
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) {

View file

@ -33,7 +33,7 @@ fun CommentsPage(
postId: String,
postActions: PostActions,
htmlConverter: HTMLConverter,
getSeenComments: suspend (String) -> PostComments,
getSeenComments: suspend (String) -> PostComments?,
markSeenComments: (String, List<Comment>) -> Unit,
contentPadding: PaddingValues,
modifier: Modifier = Modifier,
@ -48,9 +48,7 @@ fun CommentsPage(
)
}
val commentState by
produceState(initialValue = PostComments(postId, emptyList())) {
value = getSeenComments(postId)
}
produceState<PostComments?>(initialValue = null) { value = getSeenComments(postId) }
when (postDetails) {
is Success<*> -> {

View file

@ -53,7 +53,7 @@ internal fun CommentsPageInternal(
details: UIPost,
postActions: PostActions,
htmlConverter: HTMLConverter,
commentState: PostComments,
commentState: PostComments?,
markSeenComments: (String, List<Comment>) -> 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) {