From 70570560d7cc483ec5f098da0fe360cb3b980397 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sat, 17 Jul 2021 10:36:45 -0400 Subject: [PATCH] fix marking first item in dm thread as read --- .../viewmodels/DirectThreadViewModel.kt | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/viewmodels/DirectThreadViewModel.kt b/app/src/main/java/awais/instagrabber/viewmodels/DirectThreadViewModel.kt index 479ce01b..2776b1fe 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/DirectThreadViewModel.kt +++ b/app/src/main/java/awais/instagrabber/viewmodels/DirectThreadViewModel.kt @@ -169,21 +169,19 @@ class DirectThreadViewModel( val items = thread.items if (items.isNullOrEmpty()) return successEventResObjectLiveData val directItem = items.firstOrNull { (_, userId) -> userId != currentUser.pk } ?: return successEventResObjectLiveData - val lastSeenAt = thread.lastSeenAt - if (lastSeenAt != null) { - val seenAt = lastSeenAt[currentUser.pk] ?: return successEventResObjectLiveData - try { - val timestamp = seenAt.timestamp ?: return successEventResObjectLiveData - val itemIdMatches = seenAt.itemId == directItem.itemId - val timestampMatches = timestamp.toLong() >= directItem.getTimestamp() - if (itemIdMatches || timestampMatches) { - return successEventResObjectLiveData - } - } catch (ignored: Exception) { + val lastSeenAt = thread.lastSeenAt ?: return threadManager.markAsSeen(directItem, viewModelScope) + val seenAt = lastSeenAt[currentUser.pk] ?: return threadManager.markAsSeen(directItem, viewModelScope) + try { + val timestamp = seenAt.timestamp ?: return threadManager.markAsSeen(directItem, viewModelScope) + val itemIdMatches = seenAt.itemId == directItem.itemId + val timestampMatches = timestamp.toLong() >= directItem.getTimestamp() + if (itemIdMatches || timestampMatches) { return successEventResObjectLiveData } + return threadManager.markAsSeen(directItem, viewModelScope) + } catch (ignored: Exception) { + return successEventResObjectLiveData } - return threadManager.markAsSeen(directItem, viewModelScope) } private val successEventResObjectLiveData: MutableLiveData>