mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-09 09:08:39 +01:00
fix(inbox): correct header for replies and mentions
This commit is contained in:
parent
4e27fd5f32
commit
74a2a77254
@ -26,9 +26,15 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PersonMentionM
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PostModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
|
||||
|
||||
sealed interface InboxCardType {
|
||||
data object Mention : InboxCardType
|
||||
data object Reply : InboxCardType
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun InboxMentionCard(
|
||||
fun InboxCard(
|
||||
mention: PersonMentionModel,
|
||||
type: InboxCardType,
|
||||
postLayout: PostLayout = PostLayout.Card,
|
||||
onOpenPost: (PostModel) -> Unit,
|
||||
onOpenCreator: (UserModel) -> Unit,
|
||||
@ -61,8 +67,9 @@ fun InboxMentionCard(
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(Spacing.xs),
|
||||
) {
|
||||
InboxReplyHeader(
|
||||
InboxCardHeader(
|
||||
mention = mention,
|
||||
type = type,
|
||||
)
|
||||
PostCardBody(
|
||||
modifier = Modifier.padding(
|
@ -15,13 +15,29 @@ import com.github.diegoberaldin.raccoonforlemmy.resources.MR
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
|
||||
@Composable
|
||||
fun InboxReplyHeader(mention: PersonMentionModel) {
|
||||
fun InboxCardHeader(
|
||||
mention: PersonMentionModel,
|
||||
type: InboxCardType,
|
||||
) {
|
||||
val header = buildAnnotatedString {
|
||||
withStyle(SpanStyle(fontWeight = FontWeight.Bold)) {
|
||||
append(mention.creator.name)
|
||||
}
|
||||
append(" ")
|
||||
append(stringResource(MR.strings.inbox_item_mention))
|
||||
when (type) {
|
||||
InboxCardType.Mention -> {
|
||||
append(stringResource(MR.strings.inbox_item_mention))
|
||||
}
|
||||
|
||||
InboxCardType.Reply -> {
|
||||
if (mention.isOwnPost) {
|
||||
append(stringResource(MR.strings.inbox_item_reply_post))
|
||||
} else {
|
||||
append(stringResource(MR.strings.inbox_item_reply_comment))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
append(" ")
|
||||
withStyle(SpanStyle(fontWeight = FontWeight.Bold)) {
|
||||
append(mention.post.title)
|
@ -178,7 +178,7 @@ internal fun CommentReplyView.toModel() = PersonMentionModel(
|
||||
thumbnailUrl = post.thumbnailUrl.orEmpty(),
|
||||
url = post.url,
|
||||
community = community.toModel(),
|
||||
creator = creator.toModel(),
|
||||
creator = UserModel(id = post.creatorId),
|
||||
saved = saved,
|
||||
myVote = myVote ?: 0,
|
||||
publishDate = post.published,
|
||||
|
@ -1,39 +0,0 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.feature.inbox.mentions
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.withStyle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PersonMentionModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
|
||||
@Composable
|
||||
fun InboxMentionHeader(mention: PersonMentionModel) {
|
||||
val header = buildAnnotatedString {
|
||||
withStyle(SpanStyle(fontWeight = FontWeight.Bold)) {
|
||||
append(mention.creator.name)
|
||||
}
|
||||
append(" ")
|
||||
if (mention.isOwnPost) {
|
||||
append(stringResource(MR.strings.inbox_item_reply_post))
|
||||
} else {
|
||||
append(stringResource(MR.strings.inbox_item_reply_comment))
|
||||
}
|
||||
append(" ")
|
||||
withStyle(SpanStyle(fontWeight = FontWeight.Bold)) {
|
||||
append(mention.post.title)
|
||||
}
|
||||
}
|
||||
Text(
|
||||
modifier = Modifier.padding(vertical = Spacing.xs),
|
||||
text = header,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
)
|
||||
}
|
@ -39,7 +39,8 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communitydetail.CommunityDetailScreen
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.InboxMentionCard
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.InboxCard
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.InboxCardType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeableCard
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.di.getNavigationCoordinator
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.postdetail.PostDetailScreen
|
||||
@ -127,9 +128,10 @@ class InboxMentionsScreen : Tab {
|
||||
)
|
||||
},
|
||||
content = {
|
||||
InboxMentionCard(
|
||||
InboxCard(
|
||||
mention = mention,
|
||||
postLayout = uiState.postLayout,
|
||||
type = InboxCardType.Mention,
|
||||
onOpenPost = { post ->
|
||||
navigator?.push(
|
||||
PostDetailScreen(post),
|
||||
|
@ -45,7 +45,8 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepos
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communitydetail.CommunityDetailScreen
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.InboxMentionCard
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.InboxCard
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.InboxCardType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SwipeableCard
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.di.getNavigationCoordinator
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.postdetail.PostDetailScreen
|
||||
@ -156,9 +157,10 @@ class InboxRepliesScreen : Tab {
|
||||
)
|
||||
},
|
||||
content = {
|
||||
InboxMentionCard(
|
||||
InboxCard(
|
||||
mention = mention,
|
||||
postLayout = uiState.postLayout,
|
||||
type = InboxCardType.Reply,
|
||||
onOpenPost = { post ->
|
||||
navigator?.push(
|
||||
PostDetailScreen(post),
|
||||
|
@ -38,6 +38,7 @@ class InboxRepliesViewModel(
|
||||
MviModel<InboxRepliesMviModel.Intent, InboxRepliesMviModel.UiState, InboxRepliesMviModel.Effect> by mvi {
|
||||
|
||||
private var currentPage: Int = 1
|
||||
private var currentUserId: Int? = null
|
||||
|
||||
init {
|
||||
notificationCenter.addObserver({
|
||||
@ -99,8 +100,13 @@ class InboxRepliesViewModel(
|
||||
private fun refresh() {
|
||||
currentPage = 1
|
||||
mvi.updateState { it.copy(canFetchMore = true, refreshing = true) }
|
||||
loadNextPage()
|
||||
updateUnreadItems()
|
||||
mvi.scope?.launch {
|
||||
val auth = identityRepository.authToken.value
|
||||
val currentUser = siteRepository.getCurrentUser(auth.orEmpty())
|
||||
currentUserId = currentUser?.id
|
||||
loadNextPage()
|
||||
updateUnreadItems()
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeUnreadOnly(value: Boolean) {
|
||||
@ -118,7 +124,6 @@ class InboxRepliesViewModel(
|
||||
mvi.scope?.launch(Dispatchers.IO) {
|
||||
mvi.updateState { it.copy(loading = true) }
|
||||
val auth = identityRepository.authToken.value
|
||||
val currentUser = siteRepository.getCurrentUser(auth.orEmpty())
|
||||
val refreshing = currentState.refreshing
|
||||
val unreadOnly = currentState.unreadOnly
|
||||
val itemList = userRepository.getReplies(
|
||||
@ -127,7 +132,7 @@ class InboxRepliesViewModel(
|
||||
unreadOnly = unreadOnly,
|
||||
sort = SortType.New,
|
||||
).map {
|
||||
val isOwnPost = it.post.creator?.id == currentUser?.id
|
||||
val isOwnPost = it.post.creator?.id == currentUserId
|
||||
it.copy(isOwnPost = isOwnPost)
|
||||
}
|
||||
|
||||
@ -254,20 +259,18 @@ class InboxRepliesViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateUnreadItems() {
|
||||
mvi.scope?.launch(Dispatchers.IO) {
|
||||
val auth = identityRepository.authToken.value
|
||||
val unreadCount = if (!auth.isNullOrEmpty()) {
|
||||
val mentionCount =
|
||||
userRepository.getMentions(auth, page = 1, limit = 50).count()
|
||||
val replyCount =
|
||||
userRepository.getReplies(auth, page = 1, limit = 50).count()
|
||||
mentionCount + replyCount
|
||||
} else {
|
||||
0
|
||||
}
|
||||
mvi.emitEffect(InboxRepliesMviModel.Effect.UpdateUnreadItems(unreadCount))
|
||||
private suspend fun updateUnreadItems() {
|
||||
val auth = identityRepository.authToken.value
|
||||
val unreadCount = if (!auth.isNullOrEmpty()) {
|
||||
val mentionCount =
|
||||
userRepository.getMentions(auth, page = 1, limit = 50).count()
|
||||
val replyCount =
|
||||
userRepository.getReplies(auth, page = 1, limit = 50).count()
|
||||
mentionCount + replyCount
|
||||
} else {
|
||||
0
|
||||
}
|
||||
mvi.emitEffect(InboxRepliesMviModel.Effect.UpdateUnreadItems(unreadCount))
|
||||
}
|
||||
|
||||
private fun handleLogout() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user