mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-22 12:08:34 +00:00
Fix unread state using last seen timestamp.
This commit is contained in:
@@ -786,7 +786,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.setFirstUnreadCount(state.meta.unreadCount)
|
conversationItemDecorations.setFirstUnreadState(state.meta.lastSeen)
|
||||||
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 setFirstUnreadCount(unreadCount: Int) {
|
fun setFirstUnreadState(lastSeenTimestamp: Long) {
|
||||||
if (unreadState == UnreadState.None && unreadCount > 0) {
|
if (unreadState == UnreadState.None && lastSeenTimestamp > 0) {
|
||||||
unreadState = UnreadState.InitialUnreadState(unreadCount)
|
unreadState = UnreadState.InitialUnreadState(lastSeenTimestamp = lastSeenTimestamp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
* initial unread count.
|
* last seen timestamp.
|
||||||
*
|
*
|
||||||
* 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,10 +112,15 @@ 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[(state.unreadCount - 1).coerceIn(items.indices)]
|
val firstUnread = items
|
||||||
val timestamp = (firstUnread as? ConversationMessageElement)?.timestamp()
|
.filterIsInstance<ConversationMessageElement>()
|
||||||
if (timestamp != null) {
|
.lastOrNull { it.timestamp() > state.lastSeenTimestamp }
|
||||||
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
|
||||||
@@ -270,7 +275,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 unreadCount: Int) : UnreadState()
|
data class InitialUnreadState(val lastSeenTimestamp: Long) : 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()
|
||||||
|
|||||||
Reference in New Issue
Block a user