Skip to content

Commit

Permalink
Update marker API call
Browse files Browse the repository at this point in the history
  • Loading branch information
nikclayton committed Feb 5, 2025
1 parent 8aaddee commit ac7c09e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import app.pachli.core.network.retrofit.MastodonApi
import app.pachli.worker.NotificationWorker
import com.github.michaelbull.result.Err
import com.github.michaelbull.result.Ok
import com.github.michaelbull.result.mapBoth
import com.github.michaelbull.result.onFailure
import com.github.michaelbull.result.onSuccess
import dagger.hilt.android.qualifiers.ApplicationContext
Expand Down Expand Up @@ -242,20 +243,21 @@ class NotificationFetcher @Inject constructor(
}

private suspend fun fetchMarker(account: AccountEntity): Marker? {
return try {
val allMarkers = mastodonApi.markersWithAuth(
account.authHeader,
account.domain,
listOf("notifications"),
)
val notificationMarker = allMarkers["notifications"]
Timber.d("Fetched marker for %s: %s", account.fullName, notificationMarker)
notificationMarker
} catch (e: Exception) {
currentCoroutineContext().ensureActive()
Timber.e(e, "Failed to fetch marker")
null
}
return mastodonApi.markersWithAuth(
account.authHeader,
account.domain,
listOf("notifications"),
).mapBoth(
{
val notificationMarker = it.body["notifications"]
Timber.d("Fetched marker for %s: %s", account.fullName, notificationMarker)
notificationMarker
},
{
Timber.e("Failed to fetch marker: %s", it)
null
},
)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ interface MastodonApi {
@Header("Authorization") auth: String,
@Header(DOMAIN_HEADER) domain: String,
@Query("timeline[]") timelines: List<String>,
): Map<String, Marker>
): ApiResult<Map<String, Marker>>

@FormUrlEncoded
@POST("api/v1/markers")
Expand Down

0 comments on commit ac7c09e

Please sign in to comment.