1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-22 13:06:58 +00:00

fix marking first item in dm thread as read

This commit is contained in:
Austin Huang 2021-07-17 10:36:45 -04:00
parent 8717c8587e
commit 70570560d7
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F

View File

@ -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<Resource<Any?>>