updateMarkersWithAuth(): Require DOMAIN header (#3660)
Otherwise markers are updated for the wrong account. Fixes https://github.com/tuskyapp/Tusky/issues/3658
This commit is contained in:
parent
92ba53a8c3
commit
158f9b83fb
2 changed files with 9 additions and 3 deletions
|
@ -115,6 +115,7 @@ class NotificationFetcher @Inject constructor(
|
||||||
private fun fetchNewNotifications(account: AccountEntity): List<Notification> {
|
private fun fetchNewNotifications(account: AccountEntity): List<Notification> {
|
||||||
val authHeader = String.format("Bearer %s", account.accessToken)
|
val authHeader = String.format("Bearer %s", account.accessToken)
|
||||||
|
|
||||||
|
Log.d(TAG, "getting notification marker for ${account.fullName}")
|
||||||
val minId = when (val marker = fetchMarker(authHeader, account)) {
|
val minId = when (val marker = fetchMarker(authHeader, account)) {
|
||||||
null -> account.lastNotificationId.takeIf { it != "0" }
|
null -> account.lastNotificationId.takeIf { it != "0" }
|
||||||
else -> if (account.lastNotificationId.isLessThan(marker.lastReadId)) marker.lastReadId else account.lastNotificationId
|
else -> if (account.lastNotificationId.isLessThan(marker.lastReadId)) marker.lastReadId else account.lastNotificationId
|
||||||
|
@ -132,8 +133,12 @@ class NotificationFetcher @Inject constructor(
|
||||||
// in the marker.
|
// in the marker.
|
||||||
notifications.firstOrNull()?.let {
|
notifications.firstOrNull()?.let {
|
||||||
val newMarkerId = notifications.first().id
|
val newMarkerId = notifications.first().id
|
||||||
Log.d(TAG, "updating notification marker to: $newMarkerId")
|
Log.d(TAG, "updating notification marker for ${account.fullName} to: $newMarkerId")
|
||||||
mastodonApi.updateMarkersWithAuth(authHeader, notificationsLastReadId = newMarkerId)
|
mastodonApi.updateMarkersWithAuth(
|
||||||
|
auth = authHeader,
|
||||||
|
domain = account.domain,
|
||||||
|
notificationsLastReadId = newMarkerId
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return notifications
|
return notifications
|
||||||
|
@ -147,7 +152,7 @@ class NotificationFetcher @Inject constructor(
|
||||||
listOf("notifications")
|
listOf("notifications")
|
||||||
).blockingGet()
|
).blockingGet()
|
||||||
val notificationMarker = allMarkers["notifications"]
|
val notificationMarker = allMarkers["notifications"]
|
||||||
Log.d(TAG, "Fetched marker: $notificationMarker")
|
Log.d(TAG, "Fetched marker for ${account.fullName}: $notificationMarker")
|
||||||
notificationMarker
|
notificationMarker
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Failed to fetch marker", e)
|
Log.e(TAG, "Failed to fetch marker", e)
|
||||||
|
|
|
@ -156,6 +156,7 @@ interface MastodonApi {
|
||||||
@POST("api/v1/markers")
|
@POST("api/v1/markers")
|
||||||
fun updateMarkersWithAuth(
|
fun updateMarkersWithAuth(
|
||||||
@Header("Authorization") auth: String,
|
@Header("Authorization") auth: String,
|
||||||
|
@Header(DOMAIN_HEADER) domain: String,
|
||||||
@Field("home[last_read_id]") homeLastReadId: String? = null,
|
@Field("home[last_read_id]") homeLastReadId: String? = null,
|
||||||
@Field("notifications[last_read_id]") notificationsLastReadId: String? = null
|
@Field("notifications[last_read_id]") notificationsLastReadId: String? = null
|
||||||
): NetworkResult<Unit>
|
): NetworkResult<Unit>
|
||||||
|
|
Loading…
Reference in a new issue