···381381}
382382383383sealed class Notification {
384384- data class Like(val post: Post, val author: ProfileView) : Notification()
385385- data class Repost(val repost: Post, val author: ProfileView) : Notification()
386386- data class Reply(val parent: Pair<Cid, AtUri>, val reply: Post, val author: ProfileView) :
384384+ data class RawLike(val post: Post, val author: ProfileView, val createdAt: Instant) :
385385+ Notification()
386386+387387+ data class Like(val data: RepeatedNotification) :
387388 Notification()
388389389389- data class Follow(val follow: ProfileView) : Notification()
390390- data class Mention(val parent: Pair<Cid, AtUri>, val mention: Post, val author: ProfileView) :
390390+ data class Repost(val repost: Post, val author: ProfileView, val createdAt: Instant) :
391391 Notification()
392392393393- data class Quote(val parent: Pair<Cid, AtUri>, val quote: Post, val author: ProfileView) :
393393+ data class Reply(
394394+ val parent: Pair<Cid, AtUri>,
395395+ val reply: Post,
396396+ val author: ProfileView,
397397+ val createdAt: Instant
398398+ ) :
394399 Notification()
400400+401401+ data class Follow(val follow: ProfileView, val createdAt: Instant) : Notification()
402402+ data class Mention(
403403+ val parent: Pair<Cid, AtUri>,
404404+ val mention: Post,
405405+ val author: ProfileView,
406406+ val createdAt: Instant
407407+ ) :
408408+ Notification()
409409+410410+ data class Quote(
411411+ val parent: Pair<Cid, AtUri>,
412412+ val quote: Post,
413413+ val author: ProfileView,
414414+ val createdAt: Instant
415415+ ) :
416416+ Notification()
417417+418418+ fun createdAt(): Instant {
419419+ return when (this) {
420420+ is RawLike -> this.createdAt
421421+ is Follow -> this.createdAt
422422+ is Like -> this.data.timestamp
423423+ is Mention -> this.createdAt
424424+ is Quote -> this.createdAt
425425+ is Reply -> this.createdAt
426426+ is Repost -> this.createdAt
427427+ }
428428+ }
395429}
430430+431431+data class Notifications(
432432+ var list: List<Notification> = listOf()
433433+) {
434434+// fun likes() {
435435+// val likes = mutableMapOf<Post, RepeatedNotification>()
436436+// list.forEach {
437437+// when (it) {
438438+// is Notification.Like -> {
439439+// if (likes.contains(it.post)) {
440440+// val l = likes[it.post]!!
441441+// l.authors += RepeatedAuthor(it.author, it.createdAt)
442442+// if (it.createdAt > l.timestamp) {
443443+// l.timestamp = it.createdAt
444444+// }
445445+// likes[it.post] = l
446446+// } else {
447447+// likes[it.post] = RepeatedNotification(
448448+// kind = RepeatableNotification.Like,
449449+// authors = listOf(RepeatedAuthor(it.author, it.createdAt)),
450450+// timestamp = it.createdAt
451451+// )
452452+// }
453453+// }
454454+//
455455+// else -> null
456456+// }
457457+// }
458458+//
459459+// val asd = likes.entries.sortedByDescending { it.value.timestamp }.associate { it.toPair() }
460460+// Log.d("likes", likes.toString())
461461+// }
462462+}
463463+464464+enum class RepeatableNotification(val u: Unit) {
465465+ Like(Unit),
466466+ Repost(Unit)
467467+}
468468+469469+data class RepeatedNotification(
470470+ val kind: RepeatableNotification,
471471+ val post: Post,
472472+ var authors: List<RepeatedAuthor>,
473473+ var timestamp: Instant
474474+) {
475475+ fun sorted(): RepeatedNotification {
476476+ return this.copy(kind, post, authors.sortedByDescending { it.timestamp }, timestamp)
477477+ }
478478+}
479479+480480+data class RepeatedAuthor(
481481+ val author: ProfileView,
482482+ val timestamp: Instant,
483483+)