Skip to content

Commit

Permalink
[AND-3] Ensure unread badge is not shown for threads.
Browse files Browse the repository at this point in the history
  • Loading branch information
PetarVelikov committed Dec 12, 2024
1 parent d1a542f commit 1158c5c
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,28 +555,30 @@ public class MessageListController(
}
}
.onFirst { channelUserRead ->
val unreadMessages = if (channelUserRead.unreadMessages == 0) {
emptyList()
// Don't show the label if no unread messages in the channel, or the controller is started for a thread
val unreadLabel = if (isStartedForThread || channelUserRead.unreadMessages == 0) {
null
} else {
(channelState.value?.messages?.value ?: emptyList())
val unreadMessages = (channelState.value?.messages?.value ?: emptyList())
.fold(emptyList<Message>()) { acc, message ->
when {
channelUserRead.lastReadMessageId == message.id -> emptyList()
else -> acc + message
}
}
channelUserRead.lastReadMessageId
?.takeUnless { unreadMessages.isEmpty() }
?.takeUnless { unreadMessages.lastOrNull()?.id == it }
?.let { lastReadMessageId ->
UnreadLabel(
unreadCount = channelUserRead.unreadMessages,
lastReadMessageId = lastReadMessageId,
buttonVisibility = shouldShowButton &&
unreadMessages.any { !it.isDeleted() },
)
}
}
unreadLabelState.value = channelUserRead.lastReadMessageId
?.takeUnless { unreadMessages.isEmpty() }
?.takeUnless { unreadMessages.lastOrNull()?.id == it }
?.let { lastReadMessageId ->
UnreadLabel(
unreadCount = channelUserRead.unreadMessages,
lastReadMessageId = lastReadMessageId,
buttonVisibility = shouldShowButton &&
unreadMessages.any { !it.isDeleted() },
)
}
unreadLabelState.value = unreadLabel
}.launchIn(scope)
}

Expand Down

0 comments on commit 1158c5c

Please sign in to comment.