Browse Source

fix marking first item in dm thread as read

renovate/androidx.fragment-fragment-ktx-1.x
Austin Huang 3 years ago
parent
commit
70570560d7
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 10
      app/src/main/java/awais/instagrabber/viewmodels/DirectThreadViewModel.kt

10
app/src/main/java/awais/instagrabber/viewmodels/DirectThreadViewModel.kt

@ -169,22 +169,20 @@ class DirectThreadViewModel(
val items = thread.items val items = thread.items
if (items.isNullOrEmpty()) return successEventResObjectLiveData if (items.isNullOrEmpty()) return successEventResObjectLiveData
val directItem = items.firstOrNull { (_, userId) -> userId != currentUser.pk } ?: 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
val lastSeenAt = thread.lastSeenAt ?: return threadManager.markAsSeen(directItem, viewModelScope)
val seenAt = lastSeenAt[currentUser.pk] ?: return threadManager.markAsSeen(directItem, viewModelScope)
try { try {
val timestamp = seenAt.timestamp ?: return successEventResObjectLiveData
val timestamp = seenAt.timestamp ?: return threadManager.markAsSeen(directItem, viewModelScope)
val itemIdMatches = seenAt.itemId == directItem.itemId val itemIdMatches = seenAt.itemId == directItem.itemId
val timestampMatches = timestamp.toLong() >= directItem.getTimestamp() val timestampMatches = timestamp.toLong() >= directItem.getTimestamp()
if (itemIdMatches || timestampMatches) { if (itemIdMatches || timestampMatches) {
return successEventResObjectLiveData return successEventResObjectLiveData
} }
return threadManager.markAsSeen(directItem, viewModelScope)
} catch (ignored: Exception) { } catch (ignored: Exception) {
return successEventResObjectLiveData return successEventResObjectLiveData
} }
} }
return threadManager.markAsSeen(directItem, viewModelScope)
}
private val successEventResObjectLiveData: MutableLiveData<Resource<Any?>> private val successEventResObjectLiveData: MutableLiveData<Resource<Any?>>
get() { get() {

Loading…
Cancel
Save