chore: remove unread indicator for private messages (#526)

This commit is contained in:
Diego Beraldin 2024-02-14 22:55:30 +01:00 committed by GitHub
parent 221e9f3480
commit 704d2a006f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 4 additions and 64 deletions

View File

@ -12,7 +12,6 @@ interface InboxMessagesMviModel :
sealed interface Intent {
data object Refresh : Intent
data object LoadNextPage : Intent
data class MarkAsRead(val read: Boolean, val id: Int) : Intent
}
data class UiState(

View File

@ -40,6 +40,8 @@ import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallb
import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallbackArgs
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.otherUser
import com.github.diegoberaldin.raccoonforlemmy.unit.chat.InboxChatScreen
import com.github.diegoberaldin.raccoonforlemmy.unit.messages.components.ChatCard
import com.github.diegoberaldin.raccoonforlemmy.unit.messages.components.ChatCardPlaceholder
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@ -123,21 +125,11 @@ class InboxMessagesScreen : Tab {
user = chat.otherUser(uiState.currentUserId),
autoLoadImages = uiState.autoLoadImages,
lastMessage = chat.content.orEmpty(),
read = chat.read,
lastMessageDate = chat.publishDate,
onOpenUser = rememberCallbackArgs { user ->
detailOpener.openUserDetail(user, "")
},
onOpen = rememberCallback {
if (!chat.read) {
model.reduce(
InboxMessagesMviModel.Intent.MarkAsRead(
read = true,
id = chat.id,
),
)
}
val userId = chat.otherUser(uiState.currentUserId)?.id
if (userId != null) {
navigationCoordinator.pushScreen(

View File

@ -6,7 +6,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationC
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.repository.SettingsRepository
import com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository.IdentityRepository
import com.github.diegoberaldin.raccoonforlemmy.domain.inbox.InboxCoordinator
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PrivateMessageModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.otherUser
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.PrivateMessageRepository
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.SiteRepository
@ -79,13 +78,6 @@ class InboxMessagesViewModel(
InboxMessagesMviModel.Intent.Refresh -> scope?.launch(Dispatchers.IO) {
refresh()
}
is InboxMessagesMviModel.Intent.MarkAsRead -> {
markAsRead(
read = intent.read,
message = uiState.value.chats.first { it.id == intent.id },
)
}
}
}
@ -166,40 +158,6 @@ class InboxMessagesViewModel(
}
}
private fun markAsRead(read: Boolean, message: PrivateMessageModel) {
val auth = identityRepository.authToken.value
scope?.launch(Dispatchers.IO) {
messageRepository.markAsRead(
read = read,
messageId = message.id,
auth = auth,
)
val currentState = uiState.value
if (read && currentState.unreadOnly) {
updateState {
it.copy(
chats = currentState.chats.filter { c ->
c.id != message.id
}
)
}
} else {
updateState {
it.copy(
chats = currentState.chats.map { c ->
if (c.id == message.id) {
c.copy(read = read)
} else {
c
}
}
)
}
}
updateUnreadItems()
}
}
private fun handleLogout() {
updateState { it.copy(chats = emptyList()) }
}

View File

@ -1,4 +1,4 @@
package com.github.diegoberaldin.raccoonforlemmy.unit.messages
package com.github.diegoberaldin.raccoonforlemmy.unit.messages.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.FiberManualRecord
import androidx.compose.material.icons.filled.MoreHoriz
import androidx.compose.material.icons.filled.Schedule
import androidx.compose.material3.Icon
@ -51,7 +50,6 @@ internal fun ChatCard(
user: UserModel?,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
read: Boolean = true,
lastMessage: String,
lastMessageDate: String? = null,
modifier: Modifier = Modifier,
@ -125,13 +123,6 @@ internal fun ChatCard(
style = MaterialTheme.typography.bodySmall,
color = ancillaryColor,
)
if (!read) {
Icon(
modifier = Modifier.size(IconSize.xs),
imageVector = Icons.Filled.FiberManualRecord,
contentDescription = null,
)
}
}
CustomizedContent {
// last message text

View File

@ -1,4 +1,4 @@
package com.github.diegoberaldin.raccoonforlemmy.unit.messages
package com.github.diegoberaldin.raccoonforlemmy.unit.messages.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box