mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-02 15:36:43 +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 {
|
||||
data object Refresh : Intent
|
||||
data object LoadNextPage : Intent
|
||||
data class MarkAsRead(val read: Boolean, val id: Int) : Intent
|
||||
}
|
||||
|
||||
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.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(
|
||||
|
@ -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()) }
|
||||
}
|
||||
|
@ -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
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user