Fixes mark as seen when drafts are the last post in messages

This commit is contained in:
Vitor Pamplona
2025-03-29 16:07:11 -04:00
parent 21643b781c
commit c2b0154bb5
2 changed files with 6 additions and 14 deletions
@@ -62,6 +62,7 @@ import com.vitorpamplona.amethyst.ui.components.UrlPreviewState
import com.vitorpamplona.amethyst.ui.components.toasts.ToastManager
import com.vitorpamplona.amethyst.ui.feeds.FeedState
import com.vitorpamplona.amethyst.ui.navigation.Route
import com.vitorpamplona.amethyst.ui.navigation.routeFor
import com.vitorpamplona.amethyst.ui.note.ZapAmountCommentNotification
import com.vitorpamplona.amethyst.ui.note.ZapraiserStatus
import com.vitorpamplona.amethyst.ui.note.showAmount
@@ -1221,24 +1222,15 @@ class AccountViewModel(
fun markAllAsRead(
notes: ImmutableList<Note>,
accountViewModel: AccountViewModel,
onDone: () -> Unit,
) {
viewModelScope.launch(Dispatchers.IO) {
for (note in notes) {
note.event?.let { noteEvent ->
val channelHex = note.channelHex()
val route =
if (channelHex != null) {
"Channel/$channelHex"
} else if (note.event is ChatroomKeyable) {
val withKey = (note.event as ChatroomKeyable).chatroomKey(userProfile().pubkeyHex)
"Room/${withKey.hashCode()}"
} else {
null
}
note.event?.createdAt?.let { date ->
val route = routeFor(note, accountViewModel.account.userProfile())
route?.let {
account.markAsRead(route, noteEvent.createdAt)
account.markAsRead(route, date)
}
}
}
@@ -102,7 +102,7 @@ private fun FeedLoaded(
LaunchedEffect(key1 = markAsRead.value) {
if (markAsRead.value) {
accountViewModel.markAllAsRead(items.list) { markAsRead.value = false }
accountViewModel.markAllAsRead(items.list, accountViewModel) { markAsRead.value = false }
}
}