fix(core): streak expiration

Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>
This commit is contained in:
rhunk
2025-08-06 09:51:45 +02:00
parent 3951d30f2b
commit 2f808685e8
3 changed files with 18 additions and 3 deletions

View File

@@ -26,6 +26,8 @@ data class FriendFeedEntry(
var friendLinkType: Int? = null, var friendLinkType: Int? = null,
var bitmojiAvatarId: String? = null, var bitmojiAvatarId: String? = null,
var bitmojiSelfieId: String? = null, var bitmojiSelfieId: String? = null,
var streakCount: Int? = null,
var streakExpirationTimestampMs: Long? = null,
) : DatabaseObject { ) : DatabaseObject {
@SuppressLint("Range") @SuppressLint("Range")
override fun write(cursor: Cursor) { override fun write(cursor: Cursor) {
@@ -47,6 +49,9 @@ data class FriendFeedEntry(
friendLinkType = getIntOrNull("friendLinkType") friendLinkType = getIntOrNull("friendLinkType")
bitmojiAvatarId = getStringOrNull("bitmojiAvatarId") bitmojiAvatarId = getStringOrNull("bitmojiAvatarId")
bitmojiSelfieId = getStringOrNull("bitmojiSelfieId") bitmojiSelfieId = getStringOrNull("bitmojiSelfieId")
streakCount = getIntOrNull("streak_count")
streakExpirationTimestampMs = getLongOrNull("streak_expiration_timestamp_ms")
} }
} }
} }

View File

@@ -337,6 +337,11 @@ class SnapEnhance {
} }
private fun syncRemote() { private fun syncRemote() {
val myUserId = appContext.database.myUserId
val streakEntries = appContext.database.getFeedEntries(Int.MAX_VALUE, whereClause = "streak_count IS NOT NULL AND streak_count > 0").associate {
(it.friendUserId ?: it.participants?.firstOrNull { it != myUserId }) to it
}.filter { it.key != null }
appContext.bridgeClient.sync(object : SyncCallback.Stub() { appContext.bridgeClient.sync(object : SyncCallback.Stub() {
override fun syncFriend(uuid: String): String? { override fun syncFriend(uuid: String): String? {
return appContext.database.getFriendInfo(uuid)?.let { return appContext.database.getFriendInfo(uuid)?.let {
@@ -352,7 +357,12 @@ class SnapEnhance {
expirationTimestamp = it.streakExpirationTimestamp, expirationTimestamp = it.streakExpirationTimestamp,
length = it.streakLength length = it.streakLength
) )
} else null } else streakEntries[it.userId]?.let {
FriendStreaks(
expirationTimestamp = it.streakExpirationTimestampMs ?: return@let null,
length = it.streakCount ?: return@let null
)
}
).toSerialized() ).toSerialized()
} }
} }

View File

@@ -283,11 +283,11 @@ class DatabaseAccess(
} ?: emptyList() } ?: emptyList()
} }
fun getFeedEntries(limit: Int): List<FriendFeedEntry> { fun getFeedEntries(limit: Int, whereClause: String? = null): List<FriendFeedEntry> {
val entries = mutableListOf<FriendFeedEntry>() val entries = mutableListOf<FriendFeedEntry>()
return useDatabase(DatabaseType.ARROYO)?.performOperation { return useDatabase(DatabaseType.ARROYO)?.performOperation {
safeRawQuery( safeRawQuery(
"SELECT * FROM feed_entry ORDER BY last_updated_timestamp DESC LIMIT ?", "SELECT * FROM feed_entry ${whereClause?.let { "WHERE $it" }.orEmpty()} ORDER BY last_updated_timestamp DESC LIMIT ?",
arrayOf(limit.toString()) arrayOf(limit.toString())
)?.use { query -> )?.use { query ->
while (query.moveToNext()) { while (query.moveToNext()) {