fix: maybe fix the last seen issues

This commit is contained in:
0x330a 2023-07-10 15:53:00 +10:00
parent 9cdacf7244
commit 230b1acdf2
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
4 changed files with 10 additions and 12 deletions

View File

@ -512,7 +512,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
if (cursor != null) { if (cursor != null) {
val messageTimestamp = messageToScrollTimestamp.getAndSet(-1) val messageTimestamp = messageToScrollTimestamp.getAndSet(-1)
val author = messageToScrollAuthor.getAndSet(null) val author = messageToScrollAuthor.getAndSet(null)
var initialUnreadCount = 0 val initialUnreadCount: Int
// Update the unreadCount value to be loaded from the database since we got a new message // Update the unreadCount value to be loaded from the database since we got a new message
if (firstLoad.get() || oldCount != newCount) { if (firstLoad.get() || oldCount != newCount) {
@ -525,7 +525,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
} }
if (author != null && messageTimestamp >= 0) { if (author != null && messageTimestamp >= 0) {
jumpToMessage(author, messageTimestamp, true, null) jumpToMessage(author, messageTimestamp, firstLoad.get(), null)
} }
else if (firstLoad.getAndSet(false)) { else if (firstLoad.getAndSet(false)) {
scrollToFirstUnreadMessageIfNeeded(true) scrollToFirstUnreadMessageIfNeeded(true)
@ -734,7 +734,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
} }
} }
private fun scrollToFirstUnreadMessageIfNeeded(isFirstLoad: Boolean = false, shouldHighlight: Boolean = false): Int? { private fun scrollToFirstUnreadMessageIfNeeded(isFirstLoad: Boolean = false, shouldHighlight: Boolean = false): Int {
val lastSeenTimestamp = threadDb.getLastSeenAndHasSent(viewModel.threadId).first() val lastSeenTimestamp = threadDb.getLastSeenAndHasSent(viewModel.threadId).first()
val lastSeenItemPosition = adapter.findLastSeenItemPosition(lastSeenTimestamp) ?: return -1 val lastSeenItemPosition = adapter.findLastSeenItemPosition(lastSeenTimestamp) ?: return -1

View File

@ -31,12 +31,13 @@ import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.dependencies.DatabaseComponent import org.thoughtcrime.securesms.dependencies.DatabaseComponent
import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.mms.GlideRequests
import org.thoughtcrime.securesms.preferences.PrivacySettingsActivity import org.thoughtcrime.securesms.preferences.PrivacySettingsActivity
import java.util.concurrent.atomic.AtomicLong
import kotlin.math.min import kotlin.math.min
class ConversationAdapter( class ConversationAdapter(
context: Context, context: Context,
cursor: Cursor, cursor: Cursor,
private val originalLastSeen: Long, originalLastSeen: Long,
private val isReversed: Boolean, private val isReversed: Boolean,
private val onItemPress: (MessageRecord, Int, VisibleMessageView, MotionEvent) -> Unit, private val onItemPress: (MessageRecord, Int, VisibleMessageView, MotionEvent) -> Unit,
private val onItemSwipeToReply: (MessageRecord, Int) -> Unit, private val onItemSwipeToReply: (MessageRecord, Int) -> Unit,
@ -55,6 +56,8 @@ class ConversationAdapter(
private val updateQueue = Channel<String>(1024, onBufferOverflow = BufferOverflow.DROP_OLDEST) private val updateQueue = Channel<String>(1024, onBufferOverflow = BufferOverflow.DROP_OLDEST)
private val contactCache = SparseArray<Contact>(100) private val contactCache = SparseArray<Contact>(100)
private val contactLoadedCache = SparseBooleanArray(100) private val contactLoadedCache = SparseBooleanArray(100)
private val lastSeen = AtomicLong(originalLastSeen)
init { init {
lifecycleCoroutineScope.launch(IO) { lifecycleCoroutineScope.launch(IO) {
while (isActive) { while (isActive) {
@ -131,7 +134,7 @@ class ConversationAdapter(
searchQuery, searchQuery,
contact, contact,
senderId, senderId,
originalLastSeen, lastSeen.get(),
visibleMessageViewDelegate, visibleMessageViewDelegate,
onAttachmentNeedsDownload onAttachmentNeedsDownload
) )

View File

@ -127,7 +127,7 @@ class VisibleMessageView : LinearLayout {
searchQuery: String?, searchQuery: String?,
contact: Contact?, contact: Contact?,
senderSessionID: String, senderSessionID: String,
originalLastSeen: Long, lastSeen: Long,
delegate: VisibleMessageViewDelegate?, delegate: VisibleMessageViewDelegate?,
onAttachmentNeedsDownload: (Long, Long) -> Unit onAttachmentNeedsDownload: (Long, Long) -> Unit
) { ) {
@ -195,7 +195,7 @@ class VisibleMessageView : LinearLayout {
if (thread.isOpenGroupRecipient) ContactContext.OPEN_GROUP else ContactContext.REGULAR if (thread.isOpenGroupRecipient) ContactContext.OPEN_GROUP else ContactContext.REGULAR
binding.senderNameTextView.text = contact?.displayName(contactContext) ?: senderSessionID binding.senderNameTextView.text = contact?.displayName(contactContext) ?: senderSessionID
// Unread marker // Unread marker
binding.unreadMarkerContainer.isVisible = message.timestamp > originalLastSeen && (previous == null || previous.timestamp <= originalLastSeen) binding.unreadMarkerContainer.isVisible = lastSeen != -1L && message.timestamp > lastSeen && (previous == null || previous.timestamp <= lastSeen) && !message.isOutgoing
// Date break // Date break
val showDateBreak = isStartOfMessageCluster || snIsSelected val showDateBreak = isStartOfMessageCluster || snIsSelected
binding.dateBreakTextView.text = if (showDateBreak) DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), message.timestamp) else null binding.dateBreakTextView.text = if (showDateBreak) DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), message.timestamp) else null

View File

@ -132,11 +132,6 @@ object ConfigurationMessageUtilities {
if (storage.isPinned(ownThreadId)) ConfigBase.PRIORITY_PINNED else ConfigBase.PRIORITY_VISIBLE if (storage.isPinned(ownThreadId)) ConfigBase.PRIORITY_PINNED else ConfigBase.PRIORITY_VISIBLE
else ConfigBase.PRIORITY_HIDDEN else ConfigBase.PRIORITY_HIDDEN
) )
if (ownThreadId != null) {
// have NTS thread
val ntsPinned = storage.isPinned(ownThreadId)
profile.setNtsPriority(if (ntsPinned) 1 else 0) // TODO: implement the pinning priority here in future
}
val dump = profile.dump() val dump = profile.dump()
profile.free() profile.free()
return dump return dump