Revert "Fix unread state using last seen timestamp."
This reverts commit a5e30bc818
.
This commit is contained in:
parent
cf7f614296
commit
181c0e8a60
2 changed files with 10 additions and 15 deletions
|
@ -830,7 +830,7 @@ class ConversationFragment :
|
|||
.doOnSuccess { state ->
|
||||
adapter.setMessageRequestIsAccepted(state.meta.messageRequestData.isMessageRequestAccepted)
|
||||
SignalLocalMetrics.ConversationOpen.onDataLoaded()
|
||||
conversationItemDecorations.setFirstUnreadState(state.meta.lastSeen)
|
||||
conversationItemDecorations.setFirstUnreadCount(state.meta.unreadCount)
|
||||
colorizer.onGroupMembershipChanged(state.meta.groupMemberAcis)
|
||||
}
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
|
|
@ -94,15 +94,15 @@ class ConversationItemDecorations(hasWallpaper: Boolean = false, private val sch
|
|||
}
|
||||
|
||||
/** Must be called before first setting of [currentItems] */
|
||||
fun setFirstUnreadState(lastSeenTimestamp: Long) {
|
||||
if (unreadState == UnreadState.None && lastSeenTimestamp > 0) {
|
||||
unreadState = UnreadState.InitialUnreadState(lastSeenTimestamp = lastSeenTimestamp)
|
||||
fun setFirstUnreadCount(unreadCount: Int) {
|
||||
if (unreadState == UnreadState.None && unreadCount > 0) {
|
||||
unreadState = UnreadState.InitialUnreadState(unreadCount)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If [unreadState] is [UnreadState.InitialUnreadState] we need to determine the first unread timestamp based on
|
||||
* last seen timestamp.
|
||||
* initial unread count.
|
||||
*
|
||||
* Once in [UnreadState.CompleteUnreadState], need to update the unread count based on new incoming messages since
|
||||
* the first unread timestamp. If an outgoing message is found in this range the unread state is cleared completely,
|
||||
|
@ -112,15 +112,10 @@ class ConversationItemDecorations(hasWallpaper: Boolean = false, private val sch
|
|||
val state: UnreadState = unreadState
|
||||
|
||||
if (state is UnreadState.InitialUnreadState) {
|
||||
val firstUnread = items
|
||||
.filterIsInstance<ConversationMessageElement>()
|
||||
.lastOrNull { it.timestamp() > state.lastSeenTimestamp }
|
||||
|
||||
if (firstUnread != null) {
|
||||
unreadState = UnreadState.CompleteUnreadState(
|
||||
unreadCount = items.indexOf(firstUnread as ConversationElement?) + 1,
|
||||
firstUnreadTimestamp = firstUnread.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)
|
||||
}
|
||||
} else if (state is UnreadState.CompleteUnreadState) {
|
||||
var newUnreadCount = 0
|
||||
|
@ -275,7 +270,7 @@ class ConversationItemDecorations(hasWallpaper: Boolean = false, private val sch
|
|||
object None : UnreadState()
|
||||
|
||||
/** On first load of data, there is at least 1 unread message but we don't know the 'position' in the list yet */
|
||||
data class InitialUnreadState(val lastSeenTimestamp: Long) : UnreadState()
|
||||
data class InitialUnreadState(val unreadCount: Int) : UnreadState()
|
||||
|
||||
/** We have at least one unread and know the timestamp of the first unread message and thus 'position' for the header */
|
||||
data class CompleteUnreadState(val unreadCount: Int, val firstUnreadTimestamp: Long? = null) : UnreadState()
|
||||
|
|
Loading…
Add table
Reference in a new issue