From c2b0154bb5e5186164108057ce41aab19ed9195e Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sat, 29 Mar 2025 16:07:11 -0400 Subject: [PATCH] Fixes mark as seen when drafts are the last post in messages --- .../ui/screen/loggedIn/AccountViewModel.kt | 18 +++++------------- .../chats/rooms/feed/ChatroomListFeedView.kt | 2 +- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index 349caffc0..54e8e71b8 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -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, + 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) } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/feed/ChatroomListFeedView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/feed/ChatroomListFeedView.kt index 69d521b28..4619e0965 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/feed/ChatroomListFeedView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/feed/ChatroomListFeedView.kt @@ -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 } } }