Merge pull request #640 from Inhishonor/emoji-sync

Add a dedicated emoji reaction sync progress bar
This commit is contained in:
octoshrimpy
2026-01-11 12:25:50 -05:00
committed by GitHub
8 changed files with 47 additions and 5 deletions
@@ -247,7 +247,7 @@ class EmojiReactionRepositoryImpl @Inject constructor(
}
}
override fun deleteAndReparseAllEmojiReactions(realm: Realm) {
override fun deleteAndReparseAllEmojiReactions(realm: Realm, onProgress: (SyncRepository.SyncProgress) -> Unit) {
val startTime = System.currentTimeMillis()
realm.delete(EmojiReaction::class.java)
@@ -271,6 +271,9 @@ class EmojiReactionRepositoryImpl @Inject constructor(
.sort("date", Sort.ASCENDING) // parse oldest to newest to handle reactions & removals properly
.findAll()
val max = allMessages?.count() ?: 0
var progress = 0
allMessages.forEach { message ->
val text = message.getText(false)
val parsedReaction = parseEmojiReaction(text)
@@ -286,6 +289,18 @@ class EmojiReactionRepositoryImpl @Inject constructor(
targetMessage,
realm,
)
progress++
// Update the progress every 25 messages, and then at completion
// that way we don't spam the UI
if (progress % 25 == 0 || progress == max) {
onProgress(
SyncRepository.SyncProgress.ParsingEmojis(
max = max,
progress = progress,
indeterminate = false
)
)
}
}
}
@@ -229,10 +229,14 @@ class SyncRepositoryImpl @Inject constructor(
}
}
syncProgress.onNext(SyncRepository.SyncProgress.Running(0, 0, true))
syncProgress.onNext(SyncRepository.SyncProgress.ParsingEmojis(0, 0, true))
// Now that we have all the messages, we can scan for emoji reactions
reactions.deleteAndReparseAllEmojiReactions(realm)
reactions.deleteAndReparseAllEmojiReactions(
realm,
onProgress = { progress ->
syncProgress.onNext(progress)
})
realm.insert(SyncLog())
}, {