mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 07:37:03 +05:30
Revert "refactor: make PostComments non-nullable"
This reverts commit 39e3d783cd
.
This commit is contained in:
parent
a0276c4873
commit
1dfea689c6
4 changed files with 8 additions and 13 deletions
|
@ -22,10 +22,7 @@ constructor(
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun getSeenComments(postId: String) =
|
suspend fun getSeenComments(postId: String) =
|
||||||
withContext(dbDispatcher) {
|
withContext(dbDispatcher) { postCommentsQueries.getCommentIds(postId).executeAsOneOrNull() }
|
||||||
postCommentsQueries.getCommentIds(postId).executeAsOneOrNull()
|
|
||||||
?: PostComments(postId = postId, commentIds = emptyList())
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun markSeenComments(postId: String, comments: List<Comment>) {
|
suspend fun markSeenComments(postId: String, comments: List<Comment>) {
|
||||||
withContext(dbDispatcher) {
|
withContext(dbDispatcher) {
|
||||||
|
|
|
@ -65,10 +65,10 @@ internal class CommentNode(
|
||||||
|
|
||||||
internal fun createListNode(
|
internal fun createListNode(
|
||||||
comments: List<Comment>,
|
comments: List<Comment>,
|
||||||
commentState: PostComments,
|
commentState: PostComments?,
|
||||||
): MutableList<CommentNode> {
|
): MutableList<CommentNode> {
|
||||||
val commentNodes = mutableListOf<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) {
|
for (i in comments.indices) {
|
||||||
if (comments[i].parentComment == null) {
|
if (comments[i].parentComment == null) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ fun CommentsPage(
|
||||||
postId: String,
|
postId: String,
|
||||||
postActions: PostActions,
|
postActions: PostActions,
|
||||||
htmlConverter: HTMLConverter,
|
htmlConverter: HTMLConverter,
|
||||||
getSeenComments: suspend (String) -> PostComments,
|
getSeenComments: suspend (String) -> PostComments?,
|
||||||
markSeenComments: (String, List<Comment>) -> Unit,
|
markSeenComments: (String, List<Comment>) -> Unit,
|
||||||
contentPadding: PaddingValues,
|
contentPadding: PaddingValues,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
@ -48,9 +48,7 @@ fun CommentsPage(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val commentState by
|
val commentState by
|
||||||
produceState(initialValue = PostComments(postId, emptyList())) {
|
produceState<PostComments?>(initialValue = null) { value = getSeenComments(postId) }
|
||||||
value = getSeenComments(postId)
|
|
||||||
}
|
|
||||||
|
|
||||||
when (postDetails) {
|
when (postDetails) {
|
||||||
is Success<*> -> {
|
is Success<*> -> {
|
||||||
|
|
|
@ -53,7 +53,7 @@ internal fun CommentsPageInternal(
|
||||||
details: UIPost,
|
details: UIPost,
|
||||||
postActions: PostActions,
|
postActions: PostActions,
|
||||||
htmlConverter: HTMLConverter,
|
htmlConverter: HTMLConverter,
|
||||||
commentState: PostComments,
|
commentState: PostComments?,
|
||||||
markSeenComments: (String, List<Comment>) -> Unit,
|
markSeenComments: (String, List<Comment>) -> Unit,
|
||||||
openUserProfile: (String) -> Unit,
|
openUserProfile: (String) -> Unit,
|
||||||
contentPadding: PaddingValues,
|
contentPadding: PaddingValues,
|
||||||
|
@ -62,8 +62,8 @@ internal fun CommentsPageInternal(
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val commentNodes = createListNode(details.comments, commentState)
|
val commentNodes = createListNode(details.comments, commentState)
|
||||||
LaunchedEffect(key1 = commentNodes) {
|
LaunchedEffect(key1 = commentNodes) {
|
||||||
if (details.comments.isNotEmpty() && commentState.commentIds.isNotEmpty()) {
|
if (details.comments.isNotEmpty() && !commentState?.commentIds.isNullOrEmpty()) {
|
||||||
val unreadCount = details.comments.size - commentState.commentIds.size
|
val unreadCount = details.comments.size - (commentState?.commentIds?.size ?: 0)
|
||||||
if (unreadCount > 0) {
|
if (unreadCount > 0) {
|
||||||
val text =
|
val text =
|
||||||
when (unreadCount) {
|
when (unreadCount) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue