This commit is contained in:
@@ -172,20 +172,28 @@ class NotificationsSheetFragment : BottomSheetDialogFragment() {
|
||||
|
||||
val mibClient = MibActivityHistoryClient()
|
||||
mibSessions.forEach { (loginId, session) ->
|
||||
val cachedIds = allNotifications
|
||||
.filter { it.bank == "MIB" && it.loginId == loginId }
|
||||
.map { it.id }.toSet()
|
||||
val result = withContext(Dispatchers.IO) {
|
||||
mibClient.fetchUntilEnough(session, loginId)
|
||||
mibClient.fetchActivity(session, loginId, 1, 100)
|
||||
}
|
||||
if (result.items.isNotEmpty() && isAdded) {
|
||||
if (isAdded) {
|
||||
val readIds = NotificationsCache.getMibReadIds(requireContext())
|
||||
val resolved = result.items.map { it.copy(isRead = it.id in readIds) }
|
||||
allNotifications.removeAll { it.bank == "MIB" && it.loginId == loginId }
|
||||
allNotifications.addAll(resolved)
|
||||
allNotifications.sortByDescending { it.timestampMs }
|
||||
val hasOverlap = cachedIds.isNotEmpty() && result.items.any { it.id in cachedIds }
|
||||
val newItems = result.items
|
||||
.filter { it.id !in cachedIds }
|
||||
.map { it.copy(isRead = it.id in readIds) }
|
||||
if (newItems.isNotEmpty()) {
|
||||
allNotifications.addAll(newItems)
|
||||
allNotifications.sortByDescending { it.timestampMs }
|
||||
val allForLogin = allNotifications.filter { it.bank == "MIB" && it.loginId == loginId }
|
||||
NotificationsCache.saveMib(requireContext(), loginId, allForLogin)
|
||||
refreshAdapters()
|
||||
broadcastUnread()
|
||||
}
|
||||
mibNextStart[loginId] = result.nextStart
|
||||
mibDone[loginId] = result.nextStart > result.totalCount
|
||||
NotificationsCache.saveMib(requireContext(), loginId, result.items)
|
||||
refreshAdapters()
|
||||
broadcastUnread()
|
||||
mibDone[loginId] = hasOverlap || result.nextStart > result.totalCount
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,19 +229,28 @@ class NotificationsSheetFragment : BottomSheetDialogFragment() {
|
||||
val mibClient = MibActivityHistoryClient()
|
||||
mibSessions.forEach { (loginId, session) ->
|
||||
if (mibDone[loginId] == true) return@forEach
|
||||
val start = mibNextStart[loginId] ?: 1
|
||||
val result = withContext(Dispatchers.IO) {
|
||||
mibClient.fetchActivity(session, loginId, start, start + 99)
|
||||
}
|
||||
if (result.items.isNotEmpty() && isAdded) {
|
||||
while (mibDone[loginId] != true && isAdded) {
|
||||
val start = mibNextStart[loginId] ?: 101
|
||||
val cachedIds = allNotifications
|
||||
.filter { it.bank == "MIB" && it.loginId == loginId }
|
||||
.map { it.id }.toSet()
|
||||
val result = withContext(Dispatchers.IO) {
|
||||
mibClient.fetchActivity(session, loginId, start, start + 99)
|
||||
}
|
||||
if (result.rawCount == 0) break
|
||||
val readIds = NotificationsCache.getMibReadIds(requireContext())
|
||||
val resolved = result.items.map { it.copy(isRead = it.id in readIds) }
|
||||
allNotifications.addAll(resolved.filter { n -> allNotifications.none { it.id == n.id } })
|
||||
allNotifications.sortByDescending { it.timestampMs }
|
||||
val newItems = result.items
|
||||
.filter { it.id !in cachedIds }
|
||||
.map { it.copy(isRead = it.id in readIds) }
|
||||
if (newItems.isNotEmpty()) {
|
||||
allNotifications.addAll(newItems)
|
||||
allNotifications.sortByDescending { it.timestampMs }
|
||||
val allForLogin = allNotifications.filter { it.bank == "MIB" && it.loginId == loginId }
|
||||
NotificationsCache.saveMib(requireContext(), loginId, allForLogin)
|
||||
}
|
||||
mibNextStart[loginId] = result.nextStart
|
||||
mibDone[loginId] = result.nextStart > result.totalCount
|
||||
val allForLogin = allNotifications.filter { it.bank == "MIB" && it.loginId == loginId }
|
||||
NotificationsCache.saveMib(requireContext(), loginId, allForLogin)
|
||||
if (newItems.isNotEmpty()) break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user