Last active
April 8, 2021 15:26
-
-
Save binrebin/af66ddbb486ea3c2dcd64870107cdcf4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Keep | |
data class CommentsResponse( | |
@SerializedName("comments") private val commentsResponse: List<CommentResponse>) { | |
fun toComments() = commentsResponse.map { it.toComment() } | |
fun findChildren(cid: String): List<Comment> { | |
val comments = toComments() | |
val groups = comments | |
.sortedWith(compareBy({ it.parentid }, { it.comid })) | |
.groupBy { it.parentid } | |
return groups[comid] ?: emptyList() | |
} | |
@Keep | |
data class CommentResponse( | |
@SerializedName("comment_id") private val comid: String, | |
@SerializedName("post_id") private val postid: String, | |
@SerializedName("parent_id") private val parentid: String?, | |
){ | |
fun toComment() = Comment( comid, postid, parentid, children?? ) | |
} | |
} | |
data class Comment( | |
val comid: String, | |
val postid: String, | |
val parentid: String, | |
val children: List<Comment>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment