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 ->
|
.doOnSuccess { state ->
|
||||||
adapter.setMessageRequestIsAccepted(state.meta.messageRequestData.isMessageRequestAccepted)
|
adapter.setMessageRequestIsAccepted(state.meta.messageRequestData.isMessageRequestAccepted)
|
||||||
SignalLocalMetrics.ConversationOpen.onDataLoaded()
|
SignalLocalMetrics.ConversationOpen.onDataLoaded()
|
||||||
conversationItemDecorations.setFirstUnreadState(state.meta.lastSeen)
|
conversationItemDecorations.setFirstUnreadCount(state.meta.unreadCount)
|
||||||
colorizer.onGroupMembershipChanged(state.meta.groupMemberAcis)
|
colorizer.onGroupMembershipChanged(state.meta.groupMemberAcis)
|
||||||
}
|
}
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
|
|
@ -94,15 +94,15 @@ class ConversationItemDecorations(hasWallpaper: Boolean = false, private val sch
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Must be called before first setting of [currentItems] */
|
/** Must be called before first setting of [currentItems] */
|
||||||
fun setFirstUnreadState(lastSeenTimestamp: Long) {
|
fun setFirstUnreadCount(unreadCount: Int) {
|
||||||
if (unreadState == UnreadState.None && lastSeenTimestamp > 0) {
|
if (unreadState == UnreadState.None && unreadCount > 0) {
|
||||||
unreadState = UnreadState.InitialUnreadState(lastSeenTimestamp = lastSeenTimestamp)
|
unreadState = UnreadState.InitialUnreadState(unreadCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If [unreadState] is [UnreadState.InitialUnreadState] we need to determine the first unread timestamp based on
|
* 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
|
* 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,
|
* 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
|
val state: UnreadState = unreadState
|
||||||
|
|
||||||
if (state is UnreadState.InitialUnreadState) {
|
if (state is UnreadState.InitialUnreadState) {
|
||||||
val firstUnread = items
|
val firstUnread = items[(state.unreadCount - 1).coerceIn(items.indices)]
|
||||||
.filterIsInstance<ConversationMessageElement>()
|
val timestamp = (firstUnread as? ConversationMessageElement)?.timestamp()
|
||||||
.lastOrNull { it.timestamp() > state.lastSeenTimestamp }
|
if (timestamp != null) {
|
||||||
|
unreadState = UnreadState.CompleteUnreadState(unreadCount = state.unreadCount, firstUnreadTimestamp = timestamp)
|
||||||
if (firstUnread != null) {
|
|
||||||
unreadState = UnreadState.CompleteUnreadState(
|
|
||||||
unreadCount = items.indexOf(firstUnread as ConversationElement?) + 1,
|
|
||||||
firstUnreadTimestamp = firstUnread.timestamp()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} else if (state is UnreadState.CompleteUnreadState) {
|
} else if (state is UnreadState.CompleteUnreadState) {
|
||||||
var newUnreadCount = 0
|
var newUnreadCount = 0
|
||||||
|
@ -275,7 +270,7 @@ class ConversationItemDecorations(hasWallpaper: Boolean = false, private val sch
|
||||||
object None : UnreadState()
|
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 */
|
/** 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 */
|
/** 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()
|
data class CompleteUnreadState(val unreadCount: Int, val firstUnreadTimestamp: Long? = null) : UnreadState()
|
||||||
|
|
Loading…
Add table
Reference in a new issue