mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-09 23:42:32 +02:00
Fixing mark as read
This commit is contained in:
@@ -72,6 +72,15 @@ class FeedContentState(
|
|||||||
viewModelScope.launch(Dispatchers.Default) { refreshSuspended() }
|
viewModelScope.launch(Dispatchers.Default) { refreshSuspended() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun visibleNotes(): List<Note> {
|
||||||
|
val currentState = _feedContent.value
|
||||||
|
return if (currentState is FeedState.Loaded) {
|
||||||
|
currentState.feed.value.list
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun refreshSuspended() {
|
fun refreshSuspended() {
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
|
|
||||||
|
@@ -71,7 +71,6 @@ import com.vitorpamplona.amethyst.ui.components.UrlPreviewState
|
|||||||
import com.vitorpamplona.amethyst.ui.components.toasts.ToastManager
|
import com.vitorpamplona.amethyst.ui.components.toasts.ToastManager
|
||||||
import com.vitorpamplona.amethyst.ui.feeds.FeedState
|
import com.vitorpamplona.amethyst.ui.feeds.FeedState
|
||||||
import com.vitorpamplona.amethyst.ui.navigation.routes.Route
|
import com.vitorpamplona.amethyst.ui.navigation.routes.Route
|
||||||
import com.vitorpamplona.amethyst.ui.navigation.routes.routeFor
|
|
||||||
import com.vitorpamplona.amethyst.ui.note.ZapAmountCommentNotification
|
import com.vitorpamplona.amethyst.ui.note.ZapAmountCommentNotification
|
||||||
import com.vitorpamplona.amethyst.ui.note.ZapraiserStatus
|
import com.vitorpamplona.amethyst.ui.note.ZapraiserStatus
|
||||||
import com.vitorpamplona.amethyst.ui.note.showAmount
|
import com.vitorpamplona.amethyst.ui.note.showAmount
|
||||||
@@ -109,6 +108,7 @@ import com.vitorpamplona.quartz.nip19Bech32.entities.NProfile
|
|||||||
import com.vitorpamplona.quartz.nip19Bech32.entities.NPub
|
import com.vitorpamplona.quartz.nip19Bech32.entities.NPub
|
||||||
import com.vitorpamplona.quartz.nip19Bech32.entities.NRelay
|
import com.vitorpamplona.quartz.nip19Bech32.entities.NRelay
|
||||||
import com.vitorpamplona.quartz.nip19Bech32.entities.NSec
|
import com.vitorpamplona.quartz.nip19Bech32.entities.NSec
|
||||||
|
import com.vitorpamplona.quartz.nip28PublicChat.base.IsInPublicChatChannel
|
||||||
import com.vitorpamplona.quartz.nip37Drafts.DraftEvent
|
import com.vitorpamplona.quartz.nip37Drafts.DraftEvent
|
||||||
import com.vitorpamplona.quartz.nip47WalletConnect.Nip47WalletConnect
|
import com.vitorpamplona.quartz.nip47WalletConnect.Nip47WalletConnect
|
||||||
import com.vitorpamplona.quartz.nip47WalletConnect.Response
|
import com.vitorpamplona.quartz.nip47WalletConnect.Response
|
||||||
@@ -1188,26 +1188,16 @@ class AccountViewModel(
|
|||||||
return onIsNew
|
return onIsNew
|
||||||
}
|
}
|
||||||
|
|
||||||
fun markAllAsRead(
|
fun markAllChatNotesAsRead(notes: List<Note>) {
|
||||||
notes: ImmutableList<Note>,
|
|
||||||
accountViewModel: AccountViewModel,
|
|
||||||
onDone: () -> Unit,
|
|
||||||
) {
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
for (note in notes) {
|
for (note in notes) {
|
||||||
note.event?.createdAt?.let { date ->
|
val noteEvent = note.event
|
||||||
val route = routeFor(note, accountViewModel.account)
|
if (noteEvent is IsInPublicChatChannel) {
|
||||||
route?.let {
|
account.markAsRead("Channel/${noteEvent.channelId()}", noteEvent.createdAt)
|
||||||
if (route is Route.Room) {
|
} else if (noteEvent is ChatroomKeyable) {
|
||||||
account.markAsRead("Room/${route.id}", date)
|
account.markAsRead("Room/${noteEvent.chatroomKey(account.signer.pubKey).hashCode()}", noteEvent.createdAt)
|
||||||
} else if (route is Route.PublicChatChannel) {
|
|
||||||
account.markAsRead("Channel/${route.id}", date)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onDone()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,8 +28,6 @@ import androidx.compose.foundation.lazy.LazyListState
|
|||||||
import androidx.compose.foundation.lazy.itemsIndexed
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.MutableState
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
@@ -53,11 +51,10 @@ fun ChatroomListFeedView(
|
|||||||
scrollStateKey: String,
|
scrollStateKey: String,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: INav,
|
nav: INav,
|
||||||
markAsRead: MutableState<Boolean>,
|
|
||||||
) {
|
) {
|
||||||
RefresheableBox(feedContentState, true) {
|
RefresheableBox(feedContentState, true) {
|
||||||
SaveableFeedContentState(feedContentState, scrollStateKey) { listState ->
|
SaveableFeedContentState(feedContentState, scrollStateKey) { listState ->
|
||||||
CrossFadeState(feedContentState, listState, accountViewModel, nav, markAsRead)
|
CrossFadeState(feedContentState, listState, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,7 +65,6 @@ private fun CrossFadeState(
|
|||||||
listState: LazyListState,
|
listState: LazyListState,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: INav,
|
nav: INav,
|
||||||
markAsRead: MutableState<Boolean>,
|
|
||||||
) {
|
) {
|
||||||
val feedState by feedContentState.feedContent.collectAsStateWithLifecycle()
|
val feedState by feedContentState.feedContent.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
@@ -85,7 +81,7 @@ private fun CrossFadeState(
|
|||||||
FeedError(state.errorMessage) { feedContentState.invalidateData() }
|
FeedError(state.errorMessage) { feedContentState.invalidateData() }
|
||||||
}
|
}
|
||||||
is FeedState.Loaded -> {
|
is FeedState.Loaded -> {
|
||||||
FeedLoaded(state, listState, accountViewModel, nav, markAsRead)
|
FeedLoaded(state, listState, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
FeedState.Loading -> {
|
FeedState.Loading -> {
|
||||||
LoadingFeed()
|
LoadingFeed()
|
||||||
@@ -100,16 +96,9 @@ private fun FeedLoaded(
|
|||||||
listState: LazyListState,
|
listState: LazyListState,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: INav,
|
nav: INav,
|
||||||
markAsRead: MutableState<Boolean>,
|
|
||||||
) {
|
) {
|
||||||
val items by loaded.feed.collectAsStateWithLifecycle()
|
val items by loaded.feed.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
LaunchedEffect(key1 = markAsRead.value) {
|
|
||||||
if (markAsRead.value) {
|
|
||||||
accountViewModel.markAllAsRead(items.list, accountViewModel) { markAsRead.value = false }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
contentPadding = FeedPadding,
|
contentPadding = FeedPadding,
|
||||||
state = listState,
|
state = listState,
|
||||||
|
@@ -38,7 +38,6 @@ import androidx.compose.material3.TabRow
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import androidx.compose.runtime.MutableState
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@@ -62,7 +61,6 @@ class MessagesTabItem(
|
|||||||
val resource: Int,
|
val resource: Int,
|
||||||
val scrollStateKey: String,
|
val scrollStateKey: String,
|
||||||
val feedContentState: FeedContentState,
|
val feedContentState: FeedContentState,
|
||||||
val markAsRead: MutableState<Boolean>,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -132,7 +130,6 @@ fun MessagesPager(
|
|||||||
scrollStateKey = tabs[page].scrollStateKey,
|
scrollStateKey = tabs[page].scrollStateKey,
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
nav = nav,
|
nav = nav,
|
||||||
markAsRead = tabs[page].markAsRead,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,6 @@ import androidx.compose.foundation.pager.rememberPagerState
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.derivedStateOf
|
import androidx.compose.runtime.derivedStateOf
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.ui.feeds.FeedContentState
|
import com.vitorpamplona.amethyst.ui.feeds.FeedContentState
|
||||||
@@ -53,20 +52,17 @@ fun MessagesSinglePane(
|
|||||||
) {
|
) {
|
||||||
val pagerState = rememberPagerState { 2 }
|
val pagerState = rememberPagerState { 2 }
|
||||||
|
|
||||||
val markKnownAsRead = remember { mutableStateOf(false) }
|
|
||||||
val markNewAsRead = remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
WatchLifecycleAndUpdateModel(knownFeedContentState)
|
WatchLifecycleAndUpdateModel(knownFeedContentState)
|
||||||
WatchLifecycleAndUpdateModel(newFeedContentState)
|
WatchLifecycleAndUpdateModel(newFeedContentState)
|
||||||
|
|
||||||
ChatroomListFilterAssemblerSubscription(accountViewModel)
|
ChatroomListFilterAssemblerSubscription(accountViewModel)
|
||||||
|
|
||||||
val tabs by
|
val tabs by
|
||||||
remember(knownFeedContentState, markKnownAsRead) {
|
remember(knownFeedContentState) {
|
||||||
derivedStateOf {
|
derivedStateOf {
|
||||||
listOf(
|
listOf(
|
||||||
MessagesTabItem(R.string.known, ScrollStateKeys.MESSAGES_KNOWN, knownFeedContentState, markKnownAsRead),
|
MessagesTabItem(R.string.known, ScrollStateKeys.MESSAGES_KNOWN, knownFeedContentState),
|
||||||
MessagesTabItem(R.string.new_requests, ScrollStateKeys.MESSAGES_NEW, newFeedContentState, markNewAsRead),
|
MessagesTabItem(R.string.new_requests, ScrollStateKeys.MESSAGES_NEW, newFeedContentState),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,8 +75,8 @@ fun MessagesSinglePane(
|
|||||||
MessagesTabHeader(
|
MessagesTabHeader(
|
||||||
pagerState,
|
pagerState,
|
||||||
tabs,
|
tabs,
|
||||||
{ markKnownAsRead.value = true },
|
{ accountViewModel.markAllChatNotesAsRead(knownFeedContentState.visibleNotes()) },
|
||||||
{ markNewAsRead.value = true },
|
{ accountViewModel.markAllChatNotesAsRead(newFeedContentState.visibleNotes()) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@@ -26,7 +26,6 @@ import androidx.compose.foundation.pager.rememberPagerState
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.derivedStateOf
|
import androidx.compose.runtime.derivedStateOf
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
@@ -49,20 +48,17 @@ fun ChatroomList(
|
|||||||
) {
|
) {
|
||||||
val pagerState = rememberPagerState { 2 }
|
val pagerState = rememberPagerState { 2 }
|
||||||
|
|
||||||
val markKnownAsRead = remember { mutableStateOf(false) }
|
|
||||||
val markNewAsRead = remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
WatchLifecycleAndUpdateModel(knownFeedContentState)
|
WatchLifecycleAndUpdateModel(knownFeedContentState)
|
||||||
WatchLifecycleAndUpdateModel(newFeedContentState)
|
WatchLifecycleAndUpdateModel(newFeedContentState)
|
||||||
|
|
||||||
ChatroomListFilterAssemblerSubscription(accountViewModel)
|
ChatroomListFilterAssemblerSubscription(accountViewModel)
|
||||||
|
|
||||||
val tabs by
|
val tabs by
|
||||||
remember(knownFeedContentState, markKnownAsRead) {
|
remember(knownFeedContentState) {
|
||||||
derivedStateOf {
|
derivedStateOf {
|
||||||
listOf(
|
listOf(
|
||||||
MessagesTabItem(R.string.known, ScrollStateKeys.MESSAGES_KNOWN, knownFeedContentState, markKnownAsRead),
|
MessagesTabItem(R.string.known, ScrollStateKeys.MESSAGES_KNOWN, knownFeedContentState),
|
||||||
MessagesTabItem(R.string.new_requests, ScrollStateKeys.MESSAGES_NEW, newFeedContentState, markNewAsRead),
|
MessagesTabItem(R.string.new_requests, ScrollStateKeys.MESSAGES_NEW, newFeedContentState),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,8 +67,8 @@ fun ChatroomList(
|
|||||||
MessagesTabHeader(
|
MessagesTabHeader(
|
||||||
pagerState,
|
pagerState,
|
||||||
tabs,
|
tabs,
|
||||||
{ markKnownAsRead.value = true },
|
{ accountViewModel.markAllChatNotesAsRead(knownFeedContentState.visibleNotes()) },
|
||||||
{ markNewAsRead.value = true },
|
{ accountViewModel.markAllChatNotesAsRead(newFeedContentState.visibleNotes()) },
|
||||||
)
|
)
|
||||||
|
|
||||||
MessagesPager(
|
MessagesPager(
|
||||||
|
Reference in New Issue
Block a user