mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-02 18:06:59 +01:00
chore: remove unread indicator for private messages (#526)
This commit is contained in:
parent
221e9f3480
commit
704d2a006f
@ -12,7 +12,6 @@ interface InboxMessagesMviModel :
|
|||||||
sealed interface Intent {
|
sealed interface Intent {
|
||||||
data object Refresh : Intent
|
data object Refresh : Intent
|
||||||
data object LoadNextPage : Intent
|
data object LoadNextPage : Intent
|
||||||
data class MarkAsRead(val read: Boolean, val id: Int) : Intent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class UiState(
|
data class UiState(
|
||||||
|
@ -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.core.utils.compose.rememberCallbackArgs
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.otherUser
|
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.otherUser
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.unit.chat.InboxChatScreen
|
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.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
|
||||||
@ -123,21 +125,11 @@ class InboxMessagesScreen : Tab {
|
|||||||
user = chat.otherUser(uiState.currentUserId),
|
user = chat.otherUser(uiState.currentUserId),
|
||||||
autoLoadImages = uiState.autoLoadImages,
|
autoLoadImages = uiState.autoLoadImages,
|
||||||
lastMessage = chat.content.orEmpty(),
|
lastMessage = chat.content.orEmpty(),
|
||||||
read = chat.read,
|
|
||||||
lastMessageDate = chat.publishDate,
|
lastMessageDate = chat.publishDate,
|
||||||
onOpenUser = rememberCallbackArgs { user ->
|
onOpenUser = rememberCallbackArgs { user ->
|
||||||
detailOpener.openUserDetail(user, "")
|
detailOpener.openUserDetail(user, "")
|
||||||
},
|
},
|
||||||
onOpen = rememberCallback {
|
onOpen = rememberCallback {
|
||||||
if (!chat.read) {
|
|
||||||
model.reduce(
|
|
||||||
InboxMessagesMviModel.Intent.MarkAsRead(
|
|
||||||
read = true,
|
|
||||||
id = chat.id,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val userId = chat.otherUser(uiState.currentUserId)?.id
|
val userId = chat.otherUser(uiState.currentUserId)?.id
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
navigationCoordinator.pushScreen(
|
navigationCoordinator.pushScreen(
|
||||||
|
@ -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.core.persistence.repository.SettingsRepository
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository.IdentityRepository
|
import com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository.IdentityRepository
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.domain.inbox.InboxCoordinator
|
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.data.otherUser
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.PrivateMessageRepository
|
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.PrivateMessageRepository
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.SiteRepository
|
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.SiteRepository
|
||||||
@ -79,13 +78,6 @@ class InboxMessagesViewModel(
|
|||||||
InboxMessagesMviModel.Intent.Refresh -> scope?.launch(Dispatchers.IO) {
|
InboxMessagesMviModel.Intent.Refresh -> scope?.launch(Dispatchers.IO) {
|
||||||
refresh()
|
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() {
|
private fun handleLogout() {
|
||||||
updateState { it.copy(chats = emptyList()) }
|
updateState { it.copy(chats = emptyList()) }
|
||||||
}
|
}
|
||||||
|
@ -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.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
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.layout.size
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
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.MoreHoriz
|
||||||
import androidx.compose.material.icons.filled.Schedule
|
import androidx.compose.material.icons.filled.Schedule
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
@ -51,7 +50,6 @@ internal fun ChatCard(
|
|||||||
user: UserModel?,
|
user: UserModel?,
|
||||||
autoLoadImages: Boolean = true,
|
autoLoadImages: Boolean = true,
|
||||||
preferNicknames: Boolean = true,
|
preferNicknames: Boolean = true,
|
||||||
read: Boolean = true,
|
|
||||||
lastMessage: String,
|
lastMessage: String,
|
||||||
lastMessageDate: String? = null,
|
lastMessageDate: String? = null,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
@ -125,13 +123,6 @@ internal fun ChatCard(
|
|||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = ancillaryColor,
|
color = ancillaryColor,
|
||||||
)
|
)
|
||||||
if (!read) {
|
|
||||||
Icon(
|
|
||||||
modifier = Modifier.size(IconSize.xs),
|
|
||||||
imageVector = Icons.Filled.FiberManualRecord,
|
|
||||||
contentDescription = null,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
CustomizedContent {
|
CustomizedContent {
|
||||||
// last message text
|
// last message text
|
@ -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.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
Loading…
x
Reference in New Issue
Block a user