fix: 去抖合并后更新横幅数字

问题:多条消息同时到达,第一条横幅显示1,后续被去抖暂存。
1s后合并处理emit NewTaskArrived(count=3),但MainActivity
只监听MqttMessageReceived更新横幅,不监听NewTaskArrived。

修复:MainActivity同时监听NewTaskArrived,去抖合并后更新横幅。

时序:消息1→横幅"1条" → 消息2,3暂存 → 1s后合并→横幅更新"3条"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
dongliang
2026-04-29 20:44:50 +09:30
parent 31630b247f
commit 602f0ccce6

View File

@@ -80,12 +80,23 @@ class MainActivity : AppCompatActivity() {
private fun observeMqttMessages() { private fun observeMqttMessages() {
activityScope.launch { activityScope.launch {
eventBus.events.collect { event -> eventBus.events.collect { event ->
if (event is AppEvent.MqttMessageReceived && event.type == 1) { when (event) {
notificationManager.onNewTaskMessage(event.rawJson) is AppEvent.MqttMessageReceived -> {
val count = notificationManager.pendingCount if (event.type == 1) {
if (count > 0) { notificationManager.onNewTaskMessage(event.rawJson)
notificationBanner.show(count) val count = notificationManager.pendingCount
if (count > 0) {
notificationBanner.show(count)
}
}
} }
// 去抖合并完成后 → 更新横幅数字
is AppEvent.NewTaskArrived -> {
if (event.count > 0) {
notificationBanner.show(event.count)
}
}
else -> {}
} }
} }
} }