Refactors thread assembler to reduce number of lists used.
This commit is contained in:
@@ -37,12 +37,11 @@ class ThreadAssembler {
|
|||||||
val note = LocalCache.getOrCreateNote(noteId)
|
val note = LocalCache.getOrCreateNote(noteId)
|
||||||
|
|
||||||
if (note.event != null) {
|
if (note.event != null) {
|
||||||
val thread = mutableListOf<Note>()
|
val thread = mutableSetOf<Note>()
|
||||||
val threadSet = mutableSetOf<Note>()
|
|
||||||
|
|
||||||
val threadRoot = searchRoot(note) ?: note
|
val threadRoot = searchRoot(note, thread) ?: note
|
||||||
|
|
||||||
loadDown(threadRoot, thread, threadSet)
|
loadDown(threadRoot, thread)
|
||||||
|
|
||||||
thread.toSet()
|
thread.toSet()
|
||||||
} else {
|
} else {
|
||||||
@@ -55,13 +54,12 @@ class ThreadAssembler {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadDown(note: Note, thread: MutableList<Note>, threadSet: MutableSet<Note>) {
|
fun loadDown(note: Note, thread: MutableSet<Note>) {
|
||||||
if (note !in threadSet) {
|
if (note !in thread) {
|
||||||
thread.add(note)
|
thread.add(note)
|
||||||
threadSet.add(note)
|
|
||||||
|
|
||||||
note.replies.forEach {
|
note.replies.forEach {
|
||||||
loadDown(it, thread, threadSet)
|
loadDown(it, thread)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user