fix: highlight comment from own profile

This commit is contained in:
Diego Beraldin 2023-10-05 22:40:48 +02:00
parent 5fc21db784
commit 5ca4d268ba
2 changed files with 24 additions and 16 deletions

View File

@ -33,6 +33,7 @@ interface PostDetailMviModel :
val post: PostModel = PostModel(),
val refreshing: Boolean = false,
val loading: Boolean = false,
val initial: Boolean = true,
val canFetchMore: Boolean = true,
val sortType: SortType = SortType.New,
val comments: List<CommentModel> = emptyList(),

View File

@ -58,11 +58,7 @@ class PostDetailViewModel(
override fun onStarted() {
mvi.onStarted()
mvi.updateState {
it.copy(
post = post,
)
}
mvi.scope?.launch {
themeRepository.postLayout.onEach { layout ->
mvi.updateState { it.copy(postLayout = layout) }
@ -88,23 +84,28 @@ class PostDetailViewModel(
}
if (post.title.isEmpty()) {
// empty post must be loaded
postRepository.get(post.id)?.also { updatedPost ->
val updatedPost = postRepository.get(post.id)
if (updatedPost != null) {
mvi.updateState {
it.copy(
post = updatedPost,
)
}
}
} else {
mvi.updateState {
it.copy(
post = post,
)
}
}
mvi.scope?.launch {
if (highlightCommentId != null) {
val auth = identityRepository.authToken.value
val comment = commentRepository.getBy(highlightCommentId, auth)
highlightCommentPath = comment?.path
}
if (mvi.uiState.value.comments.isEmpty()) {
refresh()
}
if (highlightCommentId != null) {
val auth = identityRepository.authToken.value
val comment = commentRepository.getBy(highlightCommentId, auth)
highlightCommentPath = comment?.path
}
if (mvi.uiState.value.comments.isEmpty()) {
refresh()
}
}
}
@ -140,7 +141,12 @@ class PostDetailViewModel(
override fun reduce(intent: PostDetailMviModel.Intent) {
when (intent) {
PostDetailMviModel.Intent.LoadNextPage -> loadNextPage()
PostDetailMviModel.Intent.LoadNextPage -> {
if (!uiState.value.initial) {
loadNextPage()
}
}
PostDetailMviModel.Intent.Refresh -> refresh()
PostDetailMviModel.Intent.RefreshPost -> refreshPost()
PostDetailMviModel.Intent.HapticIndication -> hapticFeedback.vibrate()
@ -242,6 +248,7 @@ class PostDetailViewModel(
loading = false,
canFetchMore = canFetchMore,
refreshing = false,
initial = false,
)
}
if (highlightCommentPath != null && !commentWasHighlighted) {