save last notification id to account

This commit is contained in:
Conny Duck 2024-04-12 16:22:33 +02:00
parent 5ac34f679a
commit 194c63350b
No known key found for this signature in database
2 changed files with 31 additions and 13 deletions

View File

@ -30,12 +30,13 @@ import com.keylesspalace.tusky.db.entity.NotificationDataEntity
import com.keylesspalace.tusky.db.entity.TimelineStatusEntity
import com.keylesspalace.tusky.entity.Notification
import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.util.isLessThan
import com.squareup.moshi.Moshi
import retrofit2.HttpException
@OptIn(ExperimentalPagingApi::class)
class NotificationsRemoteMediator(
accountManager: AccountManager,
private val accountManager: AccountManager,
private val api: MastodonApi,
private val db: AppDatabase,
private val moshi: Moshi,
@ -184,9 +185,26 @@ class NotificationsRemoteMediator(
)
)
}
notifications.firstOrNull()?.let { notification ->
saveNewestNotificationId(notification)
}
return overlappedNotifications
}
private fun saveNewestNotificationId(notification: Notification) {
val account = accountManager.activeAccount
// make sure the account we are currently working with is still active
if (account == activeAccount) {
val lastNotificationId: String = activeAccount.lastNotificationId
val newestNotificationId = notification.id
if (lastNotificationId.isLessThan(newestNotificationId)) {
Log.d(TAG, "saving newest noti id: $lastNotificationId for account ${account.id}")
account.lastNotificationId = newestNotificationId
accountManager.saveAccount(account)
}
}
}
companion object {
private const val TAG = "NotificationsRM"
}

View File

@ -156,14 +156,14 @@ internal class StatusNotificationViewHolder(
val readoutAloud: CharSequence // for screenreaders so they don't mispronounce timestamps like "17m" as 17 meters
val then = createdAt.time
val now = System.currentTimeMillis()
readout = getRelativeTimeSpanString(binding.statusMetaInfo.context, then, now)
readoutAloud = DateUtils.getRelativeTimeSpanString(
then,
now,
DateUtils.SECOND_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE
)
val now = System.currentTimeMillis()
readout = getRelativeTimeSpanString(binding.statusMetaInfo.context, then, now)
readoutAloud = DateUtils.getRelativeTimeSpanString(
then,
now,
DateUtils.SECOND_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE
)
binding.statusMetaInfo.text = readout
binding.statusMetaInfo.contentDescription = readoutAloud
@ -340,10 +340,10 @@ internal class StatusNotificationViewHolder(
binding.notificationContent.filters = NO_INPUT_FILTER
}
val emojifiedText = content.emojify(
emojis = emojis,
view = binding.notificationContent,
animate = animateEmojis
)
emojis = emojis,
view = binding.notificationContent,
animate = animateEmojis
)
setClickableText(
binding.notificationContent,
emojifiedText,