mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 13:27:03 +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,
|
var parent: CommentNode? = null,
|
||||||
val children: MutableList<CommentNode> = mutableListOf(),
|
val children: MutableList<CommentNode> = mutableListOf(),
|
||||||
val isUnread: Boolean = false,
|
val isUnread: Boolean = false,
|
||||||
var indentLevel: Int,
|
val indentLevel: Int,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun addChild(child: CommentNode) {
|
fun addChild(child: CommentNode) {
|
||||||
|
@ -22,8 +22,16 @@ internal data class CommentNode(
|
||||||
children.add(child)
|
children.add(child)
|
||||||
child.parent = this
|
child.parent = this
|
||||||
} else {
|
} else {
|
||||||
child.indentLevel += 1
|
children
|
||||||
children.lastOrNull()?.addChild(child)
|
.lastOrNull()
|
||||||
|
?.addChild(
|
||||||
|
CommentNode(
|
||||||
|
comment = child.comment,
|
||||||
|
parent = child.parent,
|
||||||
|
isUnread = child.isUnread,
|
||||||
|
indentLevel = child.indentLevel + 1,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,12 +53,12 @@ internal fun createListNode(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
commentNodes.lastOrNull()?.let {
|
commentNodes.lastOrNull()?.let { commentNode ->
|
||||||
it.addChild(
|
commentNode.addChild(
|
||||||
CommentNode(
|
CommentNode(
|
||||||
comment = comments[i],
|
comment = comments[i],
|
||||||
isUnread = isUnread(comments[i].shortId),
|
isUnread = isUnread(comments[i].shortId),
|
||||||
indentLevel = it.indentLevel + 1,
|
indentLevel = commentNode.indentLevel + 1,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue