Protected against crash with unread counter that exceeds thread size.

This commit is contained in:
Cody Henthorne 2023-07-28 16:09:26 -04:00
parent cdce802b32
commit a54df29542
2 changed files with 4 additions and 2 deletions

View file

@ -109,10 +109,11 @@ class ConversationItemDecorations(hasWallpaper: Boolean = false, private val sch
* which causes the unread divider to be removed.
*/
private fun updateUnreadState(items: List<ConversationElement?>) {
val state = unreadState
val state: UnreadState = unreadState
if (state is UnreadState.InitialUnreadState) {
val timestamp = (items[state.unreadCount - 1] as? ConversationMessageElement)?.timestamp()
val firstUnread = items[(state.unreadCount - 1).coerceIn(items.indices)]
val timestamp = (firstUnread as? ConversationMessageElement)?.timestamp()
if (timestamp != null) {
unreadState = UnreadState.CompleteUnreadState(unreadCount = state.unreadCount, firstUnreadTimestamp = timestamp)
}

View file

@ -3285,6 +3285,7 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
}
threadIds.forEach {
threads.updateReadState(it)
threads.update(
threadId = it,
unarchive = false,