From 1345709450f7fd03b21ba13f0582639d9ebe61be Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Thu, 12 Jan 2023 01:00:32 +0530 Subject: [PATCH] feat(android): wire up PostCommentsQueries --- .../claw/android/viewmodel/ClawViewModel.kt | 9 ++++++++- .../claw/android/viewmodel/SavedPostsRepository.kt | 14 +++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/viewmodel/ClawViewModel.kt b/android/src/main/kotlin/dev/msfjarvis/claw/android/viewmodel/ClawViewModel.kt index 54526a89..95d41b5b 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/viewmodel/ClawViewModel.kt +++ b/android/src/main/kotlin/dev/msfjarvis/claw/android/viewmodel/ClawViewModel.kt @@ -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 * license that can be found in the LICENSE file or at * 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.api.LobstersApi import dev.msfjarvis.claw.database.local.SavedPost +import dev.msfjarvis.claw.model.Comment import java.io.IOException import java.time.Month import javax.inject.Inject @@ -91,6 +92,12 @@ constructor( } } + suspend fun getSeenComments(postId: String) = savedPostsRepository.getSeenComments(postId) + + fun markSeenComments(postId: String, comments: List) { + viewModelScope.launch { savedPostsRepository.markSeenComments(postId, comments) } + } + suspend fun getLinkMetadata(url: String) = withContext(ioDispatcher) { linkMetadataRepository.getLinkMetadata(url) } diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/viewmodel/SavedPostsRepository.kt b/android/src/main/kotlin/dev/msfjarvis/claw/android/viewmodel/SavedPostsRepository.kt index 092cef83..5ae2c04d 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/viewmodel/SavedPostsRepository.kt +++ b/android/src/main/kotlin/dev/msfjarvis/claw/android/viewmodel/SavedPostsRepository.kt @@ -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 * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. @@ -10,7 +10,9 @@ import app.cash.sqldelight.coroutines.asFlow import app.cash.sqldelight.coroutines.mapToList import dev.msfjarvis.claw.android.injection.DatabaseDispatcher import dev.msfjarvis.claw.database.LobstersDatabase +import dev.msfjarvis.claw.database.local.PostComments import dev.msfjarvis.claw.database.local.SavedPost +import dev.msfjarvis.claw.model.Comment import io.github.aakira.napier.Napier import javax.inject.Inject import kotlinx.coroutines.CoroutineDispatcher @@ -23,6 +25,7 @@ constructor( @DatabaseDispatcher private val dbDispatcher: CoroutineDispatcher, ) { private val savedPostQueries = database.savedPostQueries + private val postCommentsQueries = database.postCommentsQueries val savedPosts = savedPostQueries.selectAllPosts().asFlow().mapToList(dbDispatcher) suspend fun savePost(post: SavedPost) { @@ -44,6 +47,15 @@ constructor( withContext(dbDispatcher) { savedPostQueries.deletePost(post.shortId) } } + suspend fun getSeenComments(postId: String) = + withContext(dbDispatcher) { postCommentsQueries.getCommentIds(postId).executeAsOneOrNull() } + + suspend fun markSeenComments(postId: String, comments: List) { + withContext(dbDispatcher) { + postCommentsQueries.rememberComments(PostComments(postId, comments.map { it.shortId })) + } + } + private companion object { private const val TAG = "SavedPostsRepository" }