mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-28 17:47:52 +02:00
Groups notifications by day first.
This commit is contained in:
@@ -34,6 +34,9 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import java.time.Instant
|
||||||
|
import java.time.ZoneId
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
import kotlin.time.measureTimedValue
|
import kotlin.time.measureTimedValue
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
@@ -173,6 +176,8 @@ open class CardFeedViewModel(val localFilter: FeedFilter<Note>) : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd") // SimpleDateFormat()
|
||||||
|
|
||||||
val allBaseNotes = zapsPerEvent.keys + boostsPerEvent.keys + reactionsPerEvent.keys
|
val allBaseNotes = zapsPerEvent.keys + boostsPerEvent.keys + reactionsPerEvent.keys
|
||||||
val multiCards = allBaseNotes.map { baseNote ->
|
val multiCards = allBaseNotes.map { baseNote ->
|
||||||
val boostsInCard = boostsPerEvent[baseNote] ?: emptyList()
|
val boostsInCard = boostsPerEvent[baseNote] ?: emptyList()
|
||||||
@@ -180,10 +185,20 @@ open class CardFeedViewModel(val localFilter: FeedFilter<Note>) : ViewModel() {
|
|||||||
val zapsInCard = zapsPerEvent[baseNote] ?: emptyList()
|
val zapsInCard = zapsPerEvent[baseNote] ?: emptyList()
|
||||||
|
|
||||||
val singleList = (boostsInCard + zapsInCard.map { it.response } + reactionsInCard)
|
val singleList = (boostsInCard + zapsInCard.map { it.response } + reactionsInCard)
|
||||||
.sortedWith(compareBy({ it.createdAt() }, { it.idHex }))
|
.groupBy {
|
||||||
.reversed()
|
sdf.format(
|
||||||
|
Instant.ofEpochSecond(it.createdAt() ?: 0)
|
||||||
|
.atZone(ZoneId.systemDefault())
|
||||||
|
.toLocalDateTime()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
singleList.chunked(30).map { chunk ->
|
val days = singleList.keys.sortedBy { it }
|
||||||
|
|
||||||
|
days.mapNotNull {
|
||||||
|
val sortedList = singleList.get(it)?.sortedWith(compareBy({ it.createdAt() }, { it.idHex }))?.reversed()
|
||||||
|
|
||||||
|
sortedList?.chunked(30)?.map { chunk ->
|
||||||
MultiSetCard(
|
MultiSetCard(
|
||||||
baseNote,
|
baseNote,
|
||||||
boostsInCard.filter { it in chunk }.toImmutableList(),
|
boostsInCard.filter { it in chunk }.toImmutableList(),
|
||||||
@@ -192,14 +207,25 @@ open class CardFeedViewModel(val localFilter: FeedFilter<Note>) : ViewModel() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}.flatten()
|
}.flatten()
|
||||||
|
}.flatten()
|
||||||
|
|
||||||
val userZaps = zapsPerUser.map {
|
val userZaps = zapsPerUser.map { user ->
|
||||||
ZapUserSetCard(
|
val byDay = user.value.groupBy {
|
||||||
it.key,
|
sdf.format(
|
||||||
it.value.toImmutableList()
|
Instant.ofEpochSecond(it.createdAt() ?: 0)
|
||||||
|
.atZone(ZoneId.systemDefault())
|
||||||
|
.toLocalDateTime()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byDay.values.map {
|
||||||
|
ZapUserSetCard(
|
||||||
|
user.key,
|
||||||
|
it.sortedWith(compareBy({ it.createdAt() }, { it.idHex() })).reversed().toImmutableList()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}.flatten()
|
||||||
|
|
||||||
val textNoteCards = notes.filter { it.event !is ReactionEvent && it.event !is RepostEvent && it.event !is GenericRepostEvent && it.event !is LnZapEvent }.map {
|
val textNoteCards = notes.filter { it.event !is ReactionEvent && it.event !is RepostEvent && it.event !is GenericRepostEvent && it.event !is LnZapEvent }.map {
|
||||||
if (it.event is PrivateDmEvent || it.event is ChatMessageEvent) {
|
if (it.event is PrivateDmEvent || it.event is ChatMessageEvent) {
|
||||||
MessageSetCard(it)
|
MessageSetCard(it)
|
||||||
|
Reference in New Issue
Block a user