mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 21:07:04 +05:30
refactor(common): get rid of interior mutability in CommentNode
This commit is contained in:
parent
d55ff24add
commit
c50790e4f9
1 changed files with 14 additions and 6 deletions
|
@ -14,7 +14,7 @@ internal data class CommentNode(
|
|||
var parent: CommentNode? = null,
|
||||
val children: MutableList<CommentNode> = mutableListOf(),
|
||||
val isUnread: Boolean = false,
|
||||
var indentLevel: Int,
|
||||
val indentLevel: Int,
|
||||
) {
|
||||
|
||||
fun addChild(child: CommentNode) {
|
||||
|
@ -22,8 +22,16 @@ internal data class CommentNode(
|
|||
children.add(child)
|
||||
child.parent = this
|
||||
} else {
|
||||
child.indentLevel += 1
|
||||
children.lastOrNull()?.addChild(child)
|
||||
children
|
||||
.lastOrNull()
|
||||
?.addChild(
|
||||
CommentNode(
|
||||
comment = child.comment,
|
||||
parent = child.parent,
|
||||
isUnread = child.isUnread,
|
||||
indentLevel = child.indentLevel + 1,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,12 +53,12 @@ internal fun createListNode(
|
|||
)
|
||||
)
|
||||
} else {
|
||||
commentNodes.lastOrNull()?.let {
|
||||
it.addChild(
|
||||
commentNodes.lastOrNull()?.let { commentNode ->
|
||||
commentNode.addChild(
|
||||
CommentNode(
|
||||
comment = comments[i],
|
||||
isUnread = isUnread(comments[i].shortId),
|
||||
indentLevel = it.indentLevel + 1,
|
||||
indentLevel = commentNode.indentLevel + 1,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue