Implement auto mark as read for conversations
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
android:theme="@style/Theme.KordophoneDroid"
|
||||
android:name=".KordophoneApplication"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
|
||||
@@ -68,6 +68,7 @@ fun MessageListScreen(
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
Log.d("MessageListScreen", "Launched effect")
|
||||
viewModel.markAsRead()
|
||||
viewModel.synchronize()
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,10 @@ class MessageListViewModel @Inject constructor(
|
||||
return pendingMessages.value.any { it.message.guid == message.guid }
|
||||
}
|
||||
|
||||
fun markAsRead() = viewModelScope.launch {
|
||||
repository.markConversationAsRead(conversation!!)
|
||||
}
|
||||
|
||||
fun synchronize() = viewModelScope.launch {
|
||||
repository.synchronizeConversation(conversation!!)
|
||||
}
|
||||
|
||||
@@ -47,6 +47,9 @@ interface APIInterface {
|
||||
|
||||
@POST("/sendMessage")
|
||||
suspend fun sendMessage(@Body request: SendMessageRequest): Response<SendMessageResponse>
|
||||
|
||||
@POST("/markConversation")
|
||||
suspend fun markConversation(@Query("guid") conversationGUID: String): Response<Void>
|
||||
}
|
||||
|
||||
class ResponseDecodeError(val response: ResponseBody): Exception(response.string())
|
||||
|
||||
@@ -169,6 +169,13 @@ class ChatRepository(
|
||||
_errorEncounteredChannel.emit(Error.ConnectionError(e))
|
||||
}
|
||||
|
||||
suspend fun markConversationAsRead(conversation: Conversation) = try {
|
||||
apiInterface.markConversation(conversation.guid)
|
||||
} catch (e: java.lang.Exception) {
|
||||
// Don't report via the channel, but log it.
|
||||
Log.e(REPO_LOG, "Error marking conversation as read: ${e.message}")
|
||||
}
|
||||
|
||||
fun close() {
|
||||
database.close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user