Protected against crash with unread counter that exceeds thread size.
This commit is contained in:
parent
cdce802b32
commit
a54df29542
2 changed files with 4 additions and 2 deletions
|
@ -109,10 +109,11 @@ class ConversationItemDecorations(hasWallpaper: Boolean = false, private val sch
|
||||||
* which causes the unread divider to be removed.
|
* which causes the unread divider to be removed.
|
||||||
*/
|
*/
|
||||||
private fun updateUnreadState(items: List<ConversationElement?>) {
|
private fun updateUnreadState(items: List<ConversationElement?>) {
|
||||||
val state = unreadState
|
val state: UnreadState = unreadState
|
||||||
|
|
||||||
if (state is UnreadState.InitialUnreadState) {
|
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) {
|
if (timestamp != null) {
|
||||||
unreadState = UnreadState.CompleteUnreadState(unreadCount = state.unreadCount, firstUnreadTimestamp = timestamp)
|
unreadState = UnreadState.CompleteUnreadState(unreadCount = state.unreadCount, firstUnreadTimestamp = timestamp)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3285,6 +3285,7 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
|
||||||
}
|
}
|
||||||
|
|
||||||
threadIds.forEach {
|
threadIds.forEach {
|
||||||
|
threads.updateReadState(it)
|
||||||
threads.update(
|
threads.update(
|
||||||
threadId = it,
|
threadId = it,
|
||||||
unarchive = false,
|
unarchive = false,
|
||||||
|
|
Loading…
Add table
Reference in a new issue