Correctly lists chat participants...
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
package ac.cord.auxiliary.compose.database.dao
|
||||
|
||||
import ac.cord.auxiliary.compose.database.model.ChatRoom
|
||||
import ac.cord.auxiliary.compose.database.model.Relay
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalChatRoom
|
||||
import androidx.room3.Dao
|
||||
import androidx.room3.Query
|
||||
import androidx.room3.Upsert
|
||||
import fr.acinq.bitcoin.PublicKey
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface ChatRoomDao {
|
||||
@@ -15,7 +12,7 @@ interface ChatRoomDao {
|
||||
fun findChatRoomById(id: String): LocalChatRoom?
|
||||
|
||||
@Query("SELECT * FROM ChatRoom WHERE userPublicKey = :userPublicKey")
|
||||
fun observeChatRoomByUserPublicKey(userPublicKey: String): Flow<List<LocalChatRoom>>
|
||||
fun getChatRoomListByUserPublicKey(userPublicKey: String): List<LocalChatRoom>
|
||||
|
||||
@Upsert
|
||||
suspend fun upsert(chatRoom: ChatRoom)
|
||||
|
||||
@@ -692,8 +692,8 @@ class DatabaseNostrRepository(
|
||||
return database.profileDao().observeProfileWithFollowingByPublicKey(publicKey)
|
||||
}
|
||||
|
||||
override suspend fun observeChatRoomsByPublicKey(publicKey: String): Flow<List<LocalChatRoom>> {
|
||||
return database.chatRoomDao().observeChatRoomByUserPublicKey(publicKey)
|
||||
override suspend fun getChatRoomListByPublicKey(publicKey: String): List<LocalChatRoom> {
|
||||
return database.chatRoomDao().getChatRoomListByUserPublicKey(publicKey)
|
||||
}
|
||||
|
||||
override suspend fun getRecentSearches(): List<RecentSearch> {
|
||||
|
||||
@@ -124,7 +124,7 @@ interface NostrRepository {
|
||||
|
||||
suspend fun observeProfileWithFollowing(publicKey: String): Flow<LocalProfileWithFollowing?>
|
||||
|
||||
suspend fun observeChatRoomsByPublicKey(publicKey: String): Flow<List<LocalChatRoom>>
|
||||
suspend fun getChatRoomListByPublicKey(publicKey: String): List<LocalChatRoom>
|
||||
|
||||
suspend fun getRecentSearches(): List<RecentSearch>
|
||||
|
||||
@@ -298,7 +298,7 @@ interface NostrRepository {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun observeChatRoomsByPublicKey(publicKey: String): Flow<List<LocalChatRoom>> {
|
||||
override suspend fun getChatRoomListByPublicKey(publicKey: String): List<LocalChatRoom> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ fun ChatRoomDetailScreen(
|
||||
) {
|
||||
chatRoomDetailUIState.localChatRoom.participants.forEach { participant ->
|
||||
Text(
|
||||
participant.profile?.humanReadableNameOrPubkey() ?: participant.participant.participantPublicKey
|
||||
"- ${participant.profile?.humanReadableNameOrPubkey() ?: participant.participant.participantPublicKey}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package ac.cord.auxiliary.compose.ui.view.model
|
||||
|
||||
import ac.cord.auxiliary.compose.database.model.ChatRoom
|
||||
import ac.cord.auxiliary.compose.database.model.NegentropySynchronizeRequest
|
||||
import ac.cord.auxiliary.compose.database.model.types.SynchronizationFilter
|
||||
import ac.cord.auxiliary.compose.nostr.Relays
|
||||
@@ -21,7 +20,6 @@ import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
||||
import androidx.compose.material3.LoadingIndicator
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
@@ -59,12 +57,12 @@ class ChatRoomListViewModel(
|
||||
fun observeChatRoomFeed() {
|
||||
logger.d("observeChatRoomFeed")
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
nostrRepository.observeChatRoomsByPublicKey(
|
||||
nostrRepository.getChatRoomListByPublicKey(
|
||||
publicKey
|
||||
).distinctUntilChanged().collect {
|
||||
logger.d("ChatRoomList: $it")
|
||||
).let { chatRooms ->
|
||||
logger.d("ChatRoomList: $chatRooms")
|
||||
chatRoomListUIState = ChatRoomListUIState.Loaded(
|
||||
chatRoomList = it
|
||||
chatRoomList = chatRooms
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -155,11 +153,19 @@ class ChatRoomListViewModel(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
// TODO: Remove active user pubKey
|
||||
val participantNames = localChatRoom.participants.map { it.profile?.humanReadableNameOrPubkey() ?: "unknown participant" }
|
||||
|
||||
Text(
|
||||
text = localChatRoom.chatRoom.subject ?: participantNames.joinToString { ", " }
|
||||
)
|
||||
if (localChatRoom.participants.size == 1) {
|
||||
Text(
|
||||
text = "Note to Self (${localChatRoom.participants.first().profile?.humanReadableNameOrPubkey()})"
|
||||
)
|
||||
} else {
|
||||
// Remove the active user publicKey from participants...
|
||||
val participantNames = localChatRoom.participants.filter { it.participant.participantPublicKey != localChatRoom.chatRoom.userPublicKey }.map { it.profile?.humanReadableNameOrPubkey() ?: "unknown participant" }
|
||||
|
||||
Text(
|
||||
text = localChatRoom.chatRoom.subject ?: participantNames.joinToString()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user