Sun, 10 Oct 2021 15:12:12 +0200
fix diff generated between feed entries with different issue IDs
src/main/kotlin/de/uapcore/lightpit/servlet/FeedServlet.kt | file | annotate | diff | comparison | revisions |
--- a/src/main/kotlin/de/uapcore/lightpit/servlet/FeedServlet.kt Sun Oct 10 14:56:03 2021 +0200 +++ b/src/main/kotlin/de/uapcore/lightpit/servlet/FeedServlet.kt Sun Oct 10 15:12:12 2021 +0200 @@ -73,10 +73,14 @@ val diff = fullContent(cur) val result = generator.generateDiffRows( - listOf(prev.subject, prev.component, prev.status, - prev.category, prev.assignee, prev.eta, prev.affected, prev.resolved), - listOf(diff.subject, diff.component, diff.status, - diff.category, diff.assignee, diff.eta, diff.affected, diff.resolved) + listOf( + prev.subject, prev.component, prev.status, + prev.category, prev.assignee, prev.eta, prev.affected, prev.resolved + ), + listOf( + diff.subject, diff.component, diff.status, + diff.category, diff.assignee, diff.eta, diff.affected, diff.resolved + ) ) diff.subject = result[0].oldLine @@ -100,15 +104,20 @@ * Generates the feed entries. * Assumes that [historyEntry] is already sorted by timestamp (descending). */ - private fun generateFeedEntries(historyEntry: List<IssueHistoryEntry>) = - if (historyEntry.isEmpty()) emptyList() - else historyEntry.zipWithNext().map { (cur, next) -> - IssueFeedEntry( - cur.time, cur.type, diffContent(cur.data, next.data) - ) - }.plus( - historyEntry.last().let { IssueFeedEntry(it.time, it.type, fullContent(it.data)) } - ) + private fun generateFeedEntries(historyEntry: List<IssueHistoryEntry>): List<IssueFeedEntry> = + if (historyEntry.isEmpty()) { + emptyList() + } else { + historyEntry.groupBy { it.data.id }.mapValues { (_, history) -> + history.zipWithNext().map { (cur, next) -> + IssueFeedEntry( + cur.time, cur.type, diffContent(cur.data, next.data) + ) + }.plus( + history.last().let { IssueFeedEntry(it.time, it.type, fullContent(it.data)) } + ) + }.flatMap { it.value }.sortedByDescending { it.time } + } private fun issues(http: HttpRequest, dao: DataAccessObject) { val project = http.pathParams["project"]?.let { dao.findProjectByNode(it) }