Skip to content

Commit

Permalink
fix(greader): handle group stream id (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashinch authored Feb 6, 2024
1 parent 5f1c92b commit d74f675
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ abstract class AbstractRssRepository(
private val dispatcherDefault: CoroutineDispatcher,
) {

open val importSubscription: Boolean = true
open val addSubscription: Boolean = true
open val moveSubscription: Boolean = true
open val deleteSubscription: Boolean = true
Expand Down Expand Up @@ -192,6 +193,11 @@ abstract class AbstractRssRepository(
workManager.cancelAllWork()
}

fun doSyncOneTime() {
workManager.cancelAllWork()
SyncWorker.enqueueOneTimeWork(workManager)
}

suspend fun doSync(isOnStart: Boolean = false) {
workManager.cancelAllWork()
accountDao.queryById(context.currentAccountId)?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class FeverRssService @Inject constructor(
feedDao, workManager, rssHelper, notificationHelper, ioDispatcher, defaultDispatcher
) {

override val importSubscription: Boolean = false
override val addSubscription: Boolean = false
override val moveSubscription: Boolean = false
override val deleteSubscription: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import me.ash.reader.infrastructure.di.MainDispatcher
import me.ash.reader.infrastructure.html.Readability
import me.ash.reader.infrastructure.rss.RssHelper
import me.ash.reader.infrastructure.rss.provider.greader.GoogleReaderAPI
import me.ash.reader.infrastructure.rss.provider.greader.GoogleReaderAPI.Companion.ofCategoryIdToStreamId
import me.ash.reader.infrastructure.rss.provider.greader.GoogleReaderAPI.Companion.ofCategoryStreamIdToId
import me.ash.reader.infrastructure.rss.provider.greader.GoogleReaderAPI.Companion.ofFeedStreamIdToId
import me.ash.reader.infrastructure.rss.provider.greader.GoogleReaderAPI.Companion.ofItemStreamIdToId
Expand Down Expand Up @@ -61,6 +62,7 @@ class GoogleReaderRssService @Inject constructor(
feedDao, workManager, rssHelper, notificationHelper, ioDispatcher, defaultDispatcher
) {

override val importSubscription: Boolean = false
override val addSubscription: Boolean = true
override val moveSubscription: Boolean = true
override val deleteSubscription: Boolean = true
Expand Down Expand Up @@ -114,19 +116,18 @@ class GoogleReaderRssService @Inject constructor(
isNotification = isNotification,
isFullContent = isFullContent,
))
SyncWorker.enqueueOneTimeWork(workManager)
// TODO: When users need to subscribe to multiple feeds continuously, this makes them uncomfortable.
// It is necessary to make syncWork support synchronizing individual specified feeds.
// super.doSyncOneTime()
}

override suspend fun addGroup(
destFeed: Feed?,
newGroupName: String,
): String {
override suspend fun addGroup(destFeed: Feed?, newGroupName: String): String {
val accountId = context.currentAccountId
getGoogleReaderAPI().subscriptionEdit(
destFeedId = destFeed?.id?.dollarLast(),
destCategoryId = newGroupName
)
val id = accountId.spacerDollar(newGroupName)
val id = accountId.spacerDollar(newGroupName.ofCategoryIdToStreamId())
groupDao.insert(
Group(
id = id,
Expand All @@ -149,8 +150,8 @@ class GoogleReaderRssService @Inject constructor(
override suspend fun moveFeed(originGroupId: String, feed: Feed) {
getGoogleReaderAPI().subscriptionEdit(
destFeedId = feed.id.dollarLast(),
destCategoryId = feed.groupId.dollarLast(),
originCategoryId = originGroupId.dollarLast(),
destCategoryId = feed.groupId.dollarLast().ofCategoryStreamIdToId(),
originCategoryId = originGroupId.dollarLast().ofCategoryStreamIdToId(),
)
super.moveFeed(originGroupId, feed)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,10 @@ class GoogleReaderAPI private constructor(
return "user/-/label/$this"
}

private val categoryStreamIdRegex = "user/[^/]+/label/".toRegex()

fun String.ofCategoryStreamIdToId(): String {
return replace("user/-/label/", "")
return replace(categoryStreamIdRegex, "")
}

private val instances: ConcurrentHashMap<String, GoogleReaderAPI> = ConcurrentHashMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ package me.ash.reader.ui.page.home.feeds.subscribe

import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.*
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.with
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.CreateNewFolder
Expand Down Expand Up @@ -170,7 +176,7 @@ fun SubscribeDialog(
}
},
dismissButton = {
if (subscribeUiState.isSearchPage) {
if (subscribeUiState.isSearchPage && subscribeViewModel.rssService.get().importSubscription) {
TextButton(
onClick = {
focusManager.clearFocus()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ class AccountViewModel @Inject constructor(
addAccountJob = applicationScope.launch(ioDispatcher) {
val addAccount = accountService.addAccount(account)
try {
if (rssService.get(addAccount.type.id).validCredentials(account)) {
val rssService = rssService.get(addAccount.type.id)
if (rssService.validCredentials(account)) {
rssService.doSyncOneTime()
withContext(mainDispatcher) {
callback(addAccount, null)
}
Expand Down

0 comments on commit d74f675

Please sign in to comment.