mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 15:47:03 +05:30
fix(common): manually roll equals/hashCode for CommentNode
Excludes the parent field for comparison since it can trigger cycles in some situations Fixes COMPOSE-LOBSTERS-5G
This commit is contained in:
parent
bf52966772
commit
8224b71465
1 changed files with 29 additions and 2 deletions
|
@ -9,9 +9,9 @@ package dev.msfjarvis.claw.common.comments
|
||||||
import dev.msfjarvis.claw.database.local.PostComments
|
import dev.msfjarvis.claw.database.local.PostComments
|
||||||
import dev.msfjarvis.claw.model.Comment
|
import dev.msfjarvis.claw.model.Comment
|
||||||
|
|
||||||
internal data class CommentNode(
|
internal class CommentNode(
|
||||||
val comment: Comment,
|
val comment: Comment,
|
||||||
var parent: CommentNode? = null,
|
private var parent: CommentNode? = null,
|
||||||
val children: MutableList<CommentNode> = mutableListOf(),
|
val children: MutableList<CommentNode> = mutableListOf(),
|
||||||
val isUnread: Boolean = false,
|
val isUnread: Boolean = false,
|
||||||
val indentLevel: Int,
|
val indentLevel: Int,
|
||||||
|
@ -34,6 +34,33 @@ internal data class CommentNode(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [CommentNode.equals] and [CommentNode.hashCode] are hand-rolled to drop the
|
||||||
|
* [CommentNode.parent] field from the comparison since it's possible for there to be cycles in
|
||||||
|
* this comparison check. For our purposes we're fine with foregoing the field.
|
||||||
|
*/
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as CommentNode
|
||||||
|
|
||||||
|
if (comment != other.comment) return false
|
||||||
|
if (children != other.children) return false
|
||||||
|
if (isUnread != other.isUnread) return false
|
||||||
|
if (indentLevel != other.indentLevel) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = comment.hashCode()
|
||||||
|
result = 31 * result + children.hashCode()
|
||||||
|
result = 31 * result + isUnread.hashCode()
|
||||||
|
result = 31 * result + indentLevel
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun createListNode(
|
internal fun createListNode(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue