mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-23 19:26:18 +02:00
Fixing Public chat's event order.
This commit is contained in:
@@ -10,22 +10,28 @@ object NostrChannelDataSource: NostrDataSource<Note>("ChatroomFeed") {
|
|||||||
|
|
||||||
fun loadMessagesBetween(channelId: String) {
|
fun loadMessagesBetween(channelId: String) {
|
||||||
channel = LocalCache.channels[channelId]
|
channel = LocalCache.channels[channelId]
|
||||||
|
resetFilters()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createMessagesToChannelFilter() = JsonFilter(
|
fun createMessagesToChannelFilter(): JsonFilter? {
|
||||||
kinds = listOf(ChannelMessageEvent.kind),
|
if (channel != null) {
|
||||||
tags = mapOf("e" to listOf(channel?.idHex).filterNotNull()),
|
return JsonFilter(
|
||||||
limit = 100
|
kinds = listOf(ChannelMessageEvent.kind),
|
||||||
)
|
tags = mapOf("e" to listOfNotNull(channel?.idHex)),
|
||||||
|
since = System.currentTimeMillis() / 1000 - (60 * 60 * 24 * 1), // 24 hours
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
val messagesChannel = requestNewChannel()
|
val messagesChannel = requestNewChannel()
|
||||||
|
|
||||||
// returns the last Note of each user.
|
// returns the last Note of each user.
|
||||||
override fun feed(): List<Note> {
|
override fun feed(): List<Note> {
|
||||||
return channel?.notes?.values?.sortedBy { it.event!!.createdAt } ?: emptyList()
|
return channel?.notes?.values?.sortedBy { it.event?.createdAt } ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateChannelFilters() {
|
override fun updateChannelFilters() {
|
||||||
messagesChannel.filter = listOf(createMessagesToChannelFilter()).ifEmpty { null }
|
messagesChannel.filter = listOfNotNull(createMessagesToChannelFilter()).ifEmpty { null }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -114,7 +114,6 @@ abstract class NostrDataSource<T>(val debugName: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalTime::class)
|
|
||||||
fun loadTop(): List<T> {
|
fun loadTop(): List<T> {
|
||||||
val returningList = feed().take(100)
|
val returningList = feed().take(100)
|
||||||
|
|
||||||
|
@@ -71,7 +71,6 @@ class AccountStateViewModel(private val encryptedPreferences: EncryptedSharedPre
|
|||||||
NostrNotificationDataSource.account = account
|
NostrNotificationDataSource.account = account
|
||||||
NostrChatroomListDataSource.account = account
|
NostrChatroomListDataSource.account = account
|
||||||
|
|
||||||
NostrChannelDataSource.start()
|
|
||||||
NostrAccountDataSource.start()
|
NostrAccountDataSource.start()
|
||||||
NostrGlobalDataSource.start()
|
NostrGlobalDataSource.start()
|
||||||
NostrHomeDataSource.start()
|
NostrHomeDataSource.start()
|
||||||
|
@@ -7,7 +7,16 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.LocalCacheState
|
import com.vitorpamplona.amethyst.model.LocalCacheState
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
|
import com.vitorpamplona.amethyst.service.NostrChannelDataSource
|
||||||
|
import com.vitorpamplona.amethyst.service.NostrChatRoomDataSource
|
||||||
|
import com.vitorpamplona.amethyst.service.NostrChatroomListDataSource
|
||||||
import com.vitorpamplona.amethyst.service.NostrDataSource
|
import com.vitorpamplona.amethyst.service.NostrDataSource
|
||||||
|
import com.vitorpamplona.amethyst.service.NostrGlobalDataSource
|
||||||
|
import com.vitorpamplona.amethyst.service.NostrHomeDataSource
|
||||||
|
import com.vitorpamplona.amethyst.service.NostrThreadDataSource
|
||||||
|
import com.vitorpamplona.amethyst.service.NostrUserProfileDataSource
|
||||||
|
import com.vitorpamplona.amethyst.service.NostrUserProfileFollowersDataSource
|
||||||
|
import com.vitorpamplona.amethyst.service.NostrUserProfileFollowsDataSource
|
||||||
import kotlin.time.ExperimentalTime
|
import kotlin.time.ExperimentalTime
|
||||||
import kotlin.time.measureTimedValue
|
import kotlin.time.measureTimedValue
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@@ -19,8 +28,16 @@ import kotlinx.coroutines.flow.asStateFlow
|
|||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class NostrChannelFeedViewModel: FeedViewModel(NostrChannelDataSource)
|
||||||
|
class NostrChatroomListFeedViewModel: FeedViewModel(NostrChatroomListDataSource)
|
||||||
|
class NostrChatRoomFeedViewModel: FeedViewModel(NostrChatRoomDataSource)
|
||||||
|
class NostrHomeFeedViewModel: FeedViewModel(NostrHomeDataSource)
|
||||||
|
class NostrGlobalFeedViewModel: FeedViewModel(NostrGlobalDataSource)
|
||||||
|
class NostrThreadFeedViewModel: FeedViewModel(NostrThreadDataSource)
|
||||||
|
class NostrUserProfileFeedViewModel: FeedViewModel(NostrUserProfileDataSource)
|
||||||
|
|
||||||
class FeedViewModel(val dataSource: NostrDataSource<Note>): ViewModel() {
|
|
||||||
|
abstract class FeedViewModel(val dataSource: NostrDataSource<Note>): ViewModel() {
|
||||||
private val _feedContent = MutableStateFlow<FeedState>(FeedState.Loading)
|
private val _feedContent = MutableStateFlow<FeedState>(FeedState.Loading)
|
||||||
val feedContent = _feedContent.asStateFlow()
|
val feedContent = _feedContent.asStateFlow()
|
||||||
|
|
||||||
|
@@ -50,7 +50,7 @@ fun ChannelScreen(channelId: String?, accountViewModel: AccountViewModel, navCon
|
|||||||
val channelState by NostrChannelDataSource.channel!!.live.observeAsState()
|
val channelState by NostrChannelDataSource.channel!!.live.observeAsState()
|
||||||
val channel = channelState?.channel ?: return
|
val channel = channelState?.channel ?: return
|
||||||
|
|
||||||
val feedViewModel: FeedViewModel = viewModel { FeedViewModel( NostrChannelDataSource ) }
|
val feedViewModel: NostrChannelFeedViewModel = viewModel()
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
feedViewModel.refresh()
|
feedViewModel.refresh()
|
||||||
|
@@ -19,7 +19,7 @@ fun ChatroomListScreen(accountViewModel: AccountViewModel, navController: NavCon
|
|||||||
val account by accountViewModel.accountLiveData.observeAsState()
|
val account by accountViewModel.accountLiveData.observeAsState()
|
||||||
|
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
val feedViewModel: FeedViewModel = viewModel { FeedViewModel( NostrChatroomListDataSource ) }
|
val feedViewModel: NostrChatroomListFeedViewModel = viewModel()
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
feedViewModel.refresh()
|
feedViewModel.refresh()
|
||||||
|
@@ -46,7 +46,7 @@ fun ChatroomScreen(userId: String?, accountViewModel: AccountViewModel, navContr
|
|||||||
|
|
||||||
NostrChatRoomDataSource.loadMessagesBetween(account, userId)
|
NostrChatRoomDataSource.loadMessagesBetween(account, userId)
|
||||||
|
|
||||||
val feedViewModel: FeedViewModel = viewModel { FeedViewModel( NostrChatRoomDataSource ) }
|
val feedViewModel: NostrChatRoomFeedViewModel = viewModel()
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
feedViewModel.refresh()
|
feedViewModel.refresh()
|
||||||
|
@@ -25,7 +25,7 @@ fun HomeScreen(accountViewModel: AccountViewModel, navController: NavController)
|
|||||||
val accountState by accountViewModel.accountLiveData.observeAsState()
|
val accountState by accountViewModel.accountLiveData.observeAsState()
|
||||||
|
|
||||||
if (accountState != null) {
|
if (accountState != null) {
|
||||||
val feedViewModel: FeedViewModel = viewModel { FeedViewModel( NostrHomeDataSource ) }
|
val feedViewModel: NostrHomeFeedViewModel = viewModel()
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
feedViewModel.refresh()
|
feedViewModel.refresh()
|
||||||
|
@@ -19,8 +19,7 @@ fun NotificationScreen(accountViewModel: AccountViewModel, navController: NavCon
|
|||||||
val account by accountViewModel.accountLiveData.observeAsState()
|
val account by accountViewModel.accountLiveData.observeAsState()
|
||||||
|
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
val feedViewModel: CardFeedViewModel =
|
val feedViewModel: CardFeedViewModel = viewModel { CardFeedViewModel( NostrNotificationDataSource ) }
|
||||||
viewModel { CardFeedViewModel( NostrNotificationDataSource ) }
|
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
feedViewModel.refresh()
|
feedViewModel.refresh()
|
||||||
|
@@ -222,7 +222,7 @@ fun ProfileScreen(userId: String?, accountViewModel: AccountViewModel, navContro
|
|||||||
fun TabNotes(user: User, accountViewModel: AccountViewModel, navController: NavController) {
|
fun TabNotes(user: User, accountViewModel: AccountViewModel, navController: NavController) {
|
||||||
val accountState by accountViewModel.accountLiveData.observeAsState()
|
val accountState by accountViewModel.accountLiveData.observeAsState()
|
||||||
if (accountState != null) {
|
if (accountState != null) {
|
||||||
val feedViewModel: FeedViewModel = viewModel { FeedViewModel( NostrUserProfileDataSource ) }
|
val feedViewModel: NostrUserProfileFeedViewModel = viewModel()
|
||||||
|
|
||||||
Column(Modifier.fillMaxHeight()) {
|
Column(Modifier.fillMaxHeight()) {
|
||||||
Column(
|
Column(
|
||||||
|
@@ -56,7 +56,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SearchScreen(accountViewModel: AccountViewModel, navController: NavController) {
|
fun SearchScreen(accountViewModel: AccountViewModel, navController: NavController) {
|
||||||
val feedViewModel: FeedViewModel = viewModel { FeedViewModel( NostrGlobalDataSource ) }
|
val feedViewModel: NostrGlobalFeedViewModel = viewModel()
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
feedViewModel.refresh()
|
feedViewModel.refresh()
|
||||||
|
@@ -27,7 +27,7 @@ fun ThreadScreen(noteId: String?, accountViewModel: AccountViewModel, navControl
|
|||||||
if (account != null && noteId != null) {
|
if (account != null && noteId != null) {
|
||||||
NostrThreadDataSource.loadThread(noteId)
|
NostrThreadDataSource.loadThread(noteId)
|
||||||
|
|
||||||
val feedViewModel: FeedViewModel = viewModel { FeedViewModel( NostrThreadDataSource ) }
|
val feedViewModel: NostrThreadFeedViewModel = viewModel()
|
||||||
|
|
||||||
Column(Modifier.fillMaxHeight()) {
|
Column(Modifier.fillMaxHeight()) {
|
||||||
Column(
|
Column(
|
||||||
|
Reference in New Issue
Block a user