Fetch all outstanding Mastodon notifications when creating Android notifications (#3700)

* Fetch all outstanding Mastodon notifications when creating Android notifications

Previous code fetched the oldest page of unfetched Mastodon notifications.

If you had more than a page of Mastodon notifications you'd get Android notifications for that page, then ~ 15 minutes later Android notifications for the next page, and so on.

This code fetches all the outstanding notifications at once.

If this results in more than 40 total notifications the list is still trimmed so that a maximum of 40 Android notifications is displayed.

Fixes https://github.com/tuskyapp/Tusky/issues/3648

* Build the list using buildList
This commit is contained in:
Nik Clayton 2023-06-01 19:31:30 +02:00 committed by GitHub
commit 01b3cb3a53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 34 deletions

View file

@ -146,15 +146,15 @@ interface MastodonApi {
): Response<Notification>
@GET("api/v1/markers")
fun markersWithAuth(
suspend fun markersWithAuth(
@Header("Authorization") auth: String,
@Header(DOMAIN_HEADER) domain: String,
@Query("timeline[]") timelines: List<String>
): Single<Map<String, Marker>>
): Map<String, Marker>
@FormUrlEncoded
@POST("api/v1/markers")
fun updateMarkersWithAuth(
suspend fun updateMarkersWithAuth(
@Header("Authorization") auth: String,
@Header(DOMAIN_HEADER) domain: String,
@Field("home[last_read_id]") homeLastReadId: String? = null,
@ -162,11 +162,12 @@ interface MastodonApi {
): NetworkResult<Unit>
@GET("api/v1/notifications")
fun notificationsWithAuth(
suspend fun notificationsWithAuth(
@Header("Authorization") auth: String,
@Header(DOMAIN_HEADER) domain: String,
/** Return results immediately newer than this ID */
@Query("min_id") minId: String?
): Single<List<Notification>>
): Response<List<Notification>>
@POST("api/v1/notifications/clear")
suspend fun clearNotifications(): Response<ResponseBody>