Skip to content

Commit

Permalink
feat(greader): support mark as read or starred
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashinch committed Jan 18, 2024
1 parent a9b2279 commit 3bf8ed6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ class GoogleReaderRssService @Inject constructor(
* 6. Remove items that are no longer in unread/starred/tagged ids lists from your local database.
* 7. Fetch contents of items missing in database.
* 8. Mark/unmark items read/starred/tagged in you app comparing local state and ids you've got from the Google Reader API.
*
* Use edit-tag to sync read/starred/tagged status from your app to Google Reader API.
*
* @link https://github.com/bazqux/bazqux-api?tab=readme-ov-file
* @link https://github.com/theoldreader/api
*/
override suspend fun sync(coroutineWorker: CoroutineWorker): ListenableWorker.Result = supervisorScope {
coroutineWorker.setProgress(SyncWorker.setIsSyncing(true))
Expand Down Expand Up @@ -291,7 +291,8 @@ class GoogleReaderRssService @Inject constructor(
link = it.canonical?.first()?.href
?: it.alternate?.first()?.href
?: it.origin?.htmlUrl ?: "",
feedId = accountId.spacerDollar(it.origin?.streamId?.ofFeedStreamIdToId() ?: feedIds.first()),
feedId = accountId.spacerDollar(it.origin?.streamId?.ofFeedStreamIdToId()
?: feedIds.first()),
accountId = accountId,
isUnread = unreadIds?.contains(articleId) ?: true,
isStarred = starredIds?.contains(articleId) ?: false,
Expand All @@ -301,14 +302,8 @@ class GoogleReaderRssService @Inject constructor(
)
}


// 7. Remove items that are no longer in unread/starred/tagged ids lists from your local database

// 8. Fetch contents of items missing in database.

// 9. Mark/unmark items read/starred/tagged in you app comparing local state and ids you've got from the
// GoogleReader

// 7. Mark/unmark items read/starred/tagged in you app comparing
// local state and ids you've got from the GoogleReader
val articlesMeta = articleDao.queryArticleMetadataAll(accountId)
for (meta: ArticleMeta in articlesMeta) {
val articleId = meta.id.dollarLast()
Expand Down Expand Up @@ -368,14 +363,14 @@ class GoogleReaderRssService @Inject constructor(
articleId != null -> {
googleReaderAPI.editTag(
itemIds = listOf(articleId.dollarLast()),
mark = if (!isUnread) GoogleReaderAPI.Label.READ else null,
unmark = if (isUnread) GoogleReaderAPI.Label.READ else null,
mark = if (!isUnread) GoogleReaderAPI.Stream.READ.tag else null,
unmark = if (isUnread) GoogleReaderAPI.Stream.READ.tag else null,
)
}

else -> {
googleReaderAPI.markAllAsRead(
streamId = GoogleReaderAPI.Label.ALL_ITEMS,
streamId = GoogleReaderAPI.Stream.ALL_ITEMS.tag,
sinceTimestamp = sinceTime
)
}
Expand All @@ -386,8 +381,8 @@ class GoogleReaderRssService @Inject constructor(
super.markAsStarred(articleId, isStarred)
getGoogleReaderAPI().editTag(
itemIds = listOf(articleId.dollarLast()),
mark = if (isStarred) GoogleReaderAPI.Label.STARRED else null,
unmark = if (!isStarred) GoogleReaderAPI.Label.STARRED else null,
mark = if (isStarred) GoogleReaderAPI.Stream.STARRED.tag else null,
unmark = if (!isStarred) GoogleReaderAPI.Stream.STARRED.tag else null,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ class GoogleReaderAPI private constructor(
private val httpPassword: String? = null,
) : ProviderAPI() {

data class AuthData(
enum class Stream(val tag: String) {
ALL_ITEMS("user/-/state/com.google/reading-list"),
READ("user/-/state/com.google/read"),
STARRED("user/-/state/com.google/starred"),
LIKE("user/-/state/com.google/like"),
BROADCAST("user/-/state/com.google/broadcast"),
;
}

private data class AuthData(
var clientLoginToken: String?,
var actionToken: String?,
)
Expand Down Expand Up @@ -182,7 +191,7 @@ class GoogleReaderAPI private constructor(
retryableGetRequest<GoogleReaderDTO.ItemIds>(
query = "reader/api/0/stream/items/ids",
params = listOf(
Pair("s", Label.READ),
Pair("s", Stream.READ.tag),
Pair("ot", since.toString()),
Pair("n", MAXIMUM_ITEMS_LIMIT),
))
Expand All @@ -191,16 +200,16 @@ class GoogleReaderAPI private constructor(
retryableGetRequest<GoogleReaderDTO.ItemIds>(
query = "reader/api/0/stream/items/ids",
params = listOf(
Pair("s", Label.ALL_ITEMS),
Pair("xt", Label.READ),
Pair("s", Stream.ALL_ITEMS.tag),
Pair("xt", Stream.READ.tag),
Pair("n", MAXIMUM_ITEMS_LIMIT),
))

suspend fun getStarredItemIds(): GoogleReaderDTO.ItemIds =
retryableGetRequest<GoogleReaderDTO.ItemIds>(
query = "reader/api/0/stream/items/ids",
params = listOf(
Pair("s", Label.STARRED),
Pair("s", Stream.STARRED.tag),
Pair("n", MAXIMUM_ITEMS_LIMIT),
))

Expand All @@ -219,17 +228,6 @@ class GoogleReaderAPI private constructor(
form = listOf(Pair("quickadd", feedUrl))
)

enum class subscriptionOperationType

object Label {

const val ALL_ITEMS = "user/-/state/com.google/reading-list"
const val READ = "user/-/state/com.google/read"
const val STARRED = "user/-/state/com.google/starred"
const val LIKE = "user/-/state/com.google/like"
const val BROADCAST = "user/-/state/com.google/broadcast"
}

suspend fun editTag(itemIds: List<String>, mark: String? = null, unmark: String? = null): String =
retryablePostRequest<String>(
query = "reader/api/0/edit-tag",
Expand Down

0 comments on commit 3bf8ed6

Please sign in to comment.