mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 21:07:04 +05:30
refactor: pull down comments stuff into common
This commit is contained in:
parent
0d47787a73
commit
7c9f833ade
6 changed files with 13 additions and 31 deletions
|
@ -211,8 +211,6 @@ fun LobstersPostsScreen(
|
|||
CommentsPage(
|
||||
postId = dest.postId,
|
||||
postActions = postActions,
|
||||
getSeenComments = viewModel::getSeenComments,
|
||||
markSeenComments = viewModel::markSeenComments,
|
||||
contentPadding = contentPadding,
|
||||
openUserProfile = { clawBackStack.add(User(it)) },
|
||||
)
|
||||
|
|
|
@ -30,7 +30,6 @@ import dev.msfjarvis.claw.android.paging.SearchPagingSource
|
|||
import dev.msfjarvis.claw.api.LobstersApi
|
||||
import dev.msfjarvis.claw.core.injection.IODispatcher
|
||||
import dev.msfjarvis.claw.core.injection.MainDispatcher
|
||||
import dev.msfjarvis.claw.model.Comment
|
||||
import dev.msfjarvis.claw.model.UIPost
|
||||
import dev.msfjarvis.claw.model.fromSavedPost
|
||||
import java.io.InputStream
|
||||
|
@ -52,7 +51,6 @@ class ClawViewModel
|
|||
@Inject
|
||||
constructor(
|
||||
private val api: LobstersApi,
|
||||
private val commentsRepository: CommentsRepository,
|
||||
private val readPostsRepository: ReadPostsRepository,
|
||||
private val savedPostsRepository: SavedPostsRepository,
|
||||
private val linkMetadataRepository: LinkMetadataRepository,
|
||||
|
@ -136,12 +134,6 @@ constructor(
|
|||
return _savedPosts.contains(post.shortId)
|
||||
}
|
||||
|
||||
suspend fun getSeenComments(postId: String) = commentsRepository.getSeenComments(postId)
|
||||
|
||||
fun markSeenComments(postId: String, comments: List<Comment>) {
|
||||
viewModelScope.launch { commentsRepository.markSeenComments(postId, comments) }
|
||||
}
|
||||
|
||||
suspend fun getLinkMetadata(url: String) =
|
||||
withContext(ioDispatcher) { linkMetadataRepository.getLinkMetadata(url) }
|
||||
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Copyright © Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.android.viewmodel
|
||||
|
||||
import dev.msfjarvis.claw.core.injection.DatabaseReadDispatcher
|
||||
import dev.msfjarvis.claw.core.injection.DatabaseWriteDispatcher
|
||||
import dev.msfjarvis.claw.database.local.PostComments
|
||||
import dev.msfjarvis.claw.database.local.PostCommentsQueries
|
||||
import dev.msfjarvis.claw.model.Comment
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class CommentsRepository
|
||||
@Inject
|
||||
constructor(
|
||||
private val postCommentsQueries: PostCommentsQueries,
|
||||
@DatabaseReadDispatcher private val readDispatcher: CoroutineDispatcher,
|
||||
@DatabaseWriteDispatcher private val writeDispatcher: CoroutineDispatcher,
|
||||
) {
|
||||
|
||||
suspend fun getSeenComments(postId: String) =
|
||||
withContext(readDispatcher) { postCommentsQueries.getCommentIds(postId).executeAsOneOrNull() }
|
||||
|
||||
suspend fun markSeenComments(postId: String, comments: List<Comment>) {
|
||||
withContext(writeDispatcher) {
|
||||
postCommentsQueries.rememberComments(PostComments(postId, comments.map { it.shortId }))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue