mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 04:07:03 +05:30
feat(android): wire up PostCommentsQueries
This commit is contained in:
parent
8433f38f6e
commit
1345709450
2 changed files with 21 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2021-2022 Harsh Shandilya.
|
* Copyright © 2021-2023 Harsh Shandilya.
|
||||||
* Use of this source code is governed by an MIT-style
|
* Use of this source code is governed by an MIT-style
|
||||||
* license that can be found in the LICENSE file or at
|
* license that can be found in the LICENSE file or at
|
||||||
* https://opensource.org/licenses/MIT.
|
* https://opensource.org/licenses/MIT.
|
||||||
|
@ -20,6 +20,7 @@ import dev.msfjarvis.claw.android.paging.LobstersPagingSource.Companion.STARTING
|
||||||
import dev.msfjarvis.claw.android.ui.toLocalDateTime
|
import dev.msfjarvis.claw.android.ui.toLocalDateTime
|
||||||
import dev.msfjarvis.claw.api.LobstersApi
|
import dev.msfjarvis.claw.api.LobstersApi
|
||||||
import dev.msfjarvis.claw.database.local.SavedPost
|
import dev.msfjarvis.claw.database.local.SavedPost
|
||||||
|
import dev.msfjarvis.claw.model.Comment
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.time.Month
|
import java.time.Month
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -91,6 +92,12 @@ constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getSeenComments(postId: String) = savedPostsRepository.getSeenComments(postId)
|
||||||
|
|
||||||
|
fun markSeenComments(postId: String, comments: List<Comment>) {
|
||||||
|
viewModelScope.launch { savedPostsRepository.markSeenComments(postId, comments) }
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun getLinkMetadata(url: String) =
|
suspend fun getLinkMetadata(url: String) =
|
||||||
withContext(ioDispatcher) { linkMetadataRepository.getLinkMetadata(url) }
|
withContext(ioDispatcher) { linkMetadataRepository.getLinkMetadata(url) }
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2021-2022 Harsh Shandilya.
|
* Copyright © 2021-2023 Harsh Shandilya.
|
||||||
* Use of this source code is governed by an MIT-style
|
* Use of this source code is governed by an MIT-style
|
||||||
* license that can be found in the LICENSE file or at
|
* license that can be found in the LICENSE file or at
|
||||||
* https://opensource.org/licenses/MIT.
|
* https://opensource.org/licenses/MIT.
|
||||||
|
@ -10,7 +10,9 @@ import app.cash.sqldelight.coroutines.asFlow
|
||||||
import app.cash.sqldelight.coroutines.mapToList
|
import app.cash.sqldelight.coroutines.mapToList
|
||||||
import dev.msfjarvis.claw.android.injection.DatabaseDispatcher
|
import dev.msfjarvis.claw.android.injection.DatabaseDispatcher
|
||||||
import dev.msfjarvis.claw.database.LobstersDatabase
|
import dev.msfjarvis.claw.database.LobstersDatabase
|
||||||
|
import dev.msfjarvis.claw.database.local.PostComments
|
||||||
import dev.msfjarvis.claw.database.local.SavedPost
|
import dev.msfjarvis.claw.database.local.SavedPost
|
||||||
|
import dev.msfjarvis.claw.model.Comment
|
||||||
import io.github.aakira.napier.Napier
|
import io.github.aakira.napier.Napier
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
@ -23,6 +25,7 @@ constructor(
|
||||||
@DatabaseDispatcher private val dbDispatcher: CoroutineDispatcher,
|
@DatabaseDispatcher private val dbDispatcher: CoroutineDispatcher,
|
||||||
) {
|
) {
|
||||||
private val savedPostQueries = database.savedPostQueries
|
private val savedPostQueries = database.savedPostQueries
|
||||||
|
private val postCommentsQueries = database.postCommentsQueries
|
||||||
val savedPosts = savedPostQueries.selectAllPosts().asFlow().mapToList(dbDispatcher)
|
val savedPosts = savedPostQueries.selectAllPosts().asFlow().mapToList(dbDispatcher)
|
||||||
|
|
||||||
suspend fun savePost(post: SavedPost) {
|
suspend fun savePost(post: SavedPost) {
|
||||||
|
@ -44,6 +47,15 @@ constructor(
|
||||||
withContext(dbDispatcher) { savedPostQueries.deletePost(post.shortId) }
|
withContext(dbDispatcher) { savedPostQueries.deletePost(post.shortId) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getSeenComments(postId: String) =
|
||||||
|
withContext(dbDispatcher) { postCommentsQueries.getCommentIds(postId).executeAsOneOrNull() }
|
||||||
|
|
||||||
|
suspend fun markSeenComments(postId: String, comments: List<Comment>) {
|
||||||
|
withContext(dbDispatcher) {
|
||||||
|
postCommentsQueries.rememberComments(PostComments(postId, comments.map { it.shortId }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
private const val TAG = "SavedPostsRepository"
|
private const val TAG = "SavedPostsRepository"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue