diff --git a/app/src/main/java/net/buzzert/kordophonedroid/ui/conversationlist/ConversationListScreen.kt b/app/src/main/java/net/buzzert/kordophonedroid/ui/conversationlist/ConversationListScreen.kt index 23f568f..2766837 100644 --- a/app/src/main/java/net/buzzert/kordophonedroid/ui/conversationlist/ConversationListScreen.kt +++ b/app/src/main/java/net/buzzert/kordophonedroid/ui/conversationlist/ConversationListScreen.kt @@ -30,7 +30,7 @@ fun ConversationListScreen( viewModel: ConversationListViewModel = hiltViewModel(), onConversationSelected: (conversationID: String) -> Unit ) { - val conversations by viewModel.conversations.collectAsStateWithLifecycle(initialValue = listOf()) + val conversations by viewModel.conversations.collectAsStateWithLifecycle(initialValue = emptyList()) ConversationListView(conversations = conversations, onConversationSelected = onConversationSelected) } diff --git a/app/src/main/java/net/buzzert/kordophonedroid/ui/conversationlist/ConversationListViewModel.kt b/app/src/main/java/net/buzzert/kordophonedroid/ui/conversationlist/ConversationListViewModel.kt index e0335da..ef33459 100644 --- a/app/src/main/java/net/buzzert/kordophonedroid/ui/conversationlist/ConversationListViewModel.kt +++ b/app/src/main/java/net/buzzert/kordophonedroid/ui/conversationlist/ConversationListViewModel.kt @@ -24,6 +24,9 @@ class ConversationListViewModel @Inject constructor( } init { + // TODO: Is this the best place to put these? + // TODO: Need error handling (exceptions thrown below) + viewModelScope.launch { repository.synchronize() } @@ -31,11 +34,5 @@ class ConversationListViewModel @Inject constructor( viewModelScope.launch { repository.beginWatchingForUpdates(this) } - - viewModelScope.launch { - repository.conversationChanges.collect { - Log.v("ViewModel", "Got conversationChanges") - } - } } } \ No newline at end of file diff --git a/backend/src/main/java/net/buzzert/kordophone/backend/model/Conversation.kt b/backend/src/main/java/net/buzzert/kordophone/backend/model/Conversation.kt index dbad24b..2370449 100644 --- a/backend/src/main/java/net/buzzert/kordophone/backend/model/Conversation.kt +++ b/backend/src/main/java/net/buzzert/kordophone/backend/model/Conversation.kt @@ -41,7 +41,8 @@ data class Conversation( date == o.date && participants == o.participants && displayName == o.displayName && - unreadCount == o.unreadCount + unreadCount == o.unreadCount && + lastMessagePreview == o.lastMessagePreview ) } diff --git a/backend/src/main/java/net/buzzert/kordophone/backend/server/ChatRepository.kt b/backend/src/main/java/net/buzzert/kordophone/backend/server/ChatRepository.kt index 71519f6..57b0e0c 100644 --- a/backend/src/main/java/net/buzzert/kordophone/backend/server/ChatRepository.kt +++ b/backend/src/main/java/net/buzzert/kordophone/backend/server/ChatRepository.kt @@ -7,6 +7,7 @@ import kotlinx.coroutines.cancel import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import net.buzzert.kordophone.backend.db.CachedChatDatabase @@ -38,6 +39,7 @@ class ChatRepository( // Changes Flow val conversationChanges: Flow> get() = database.conversationChanges + .onEach { Log.d(REPO_LOG, "Got database conversations changed") } fun messagesChanged(conversation: Conversation): Flow> = database.messagesChanged(conversation)