1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-14 02:37:30 +00:00

do not mark as seen more than once

This commit is contained in:
Austin Huang 2021-07-08 20:40:59 -04:00
parent c82080acf4
commit 525cf37907
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F

View File

@ -473,7 +473,9 @@ class StoryFragmentViewModel : ViewModel() {
fun markAsSeen(storyMedia: StoryMedia): LiveData<Resource<Story?>> { fun markAsSeen(storyMedia: StoryMedia): LiveData<Resource<Story?>> {
val data = MutableLiveData<Resource<Story?>>() val data = MutableLiveData<Resource<Story?>>()
data.postValue(loading(null)) data.postValue(loading(null))
viewModelScope.launch(Dispatchers.IO) { val oldStory = currentStory.value!!
if (oldStory.seen != null && oldStory.seen >= storyMedia.takenAt) data.postValue(success(null))
else viewModelScope.launch(Dispatchers.IO) {
try { try {
storiesRepository.seen( storiesRepository.seen(
csrfToken!!, csrfToken!!,
@ -483,7 +485,6 @@ class StoryFragmentViewModel : ViewModel() {
storyMedia.takenAt, storyMedia.takenAt,
System.currentTimeMillis() / 1000 System.currentTimeMillis() / 1000
) )
val oldStory = currentStory.value!!
val newStory = oldStory.copy(seen = storyMedia.takenAt) val newStory = oldStory.copy(seen = storyMedia.takenAt)
data.postValue(success(newStory)) data.postValue(success(newStory))
} catch (e: Exception) { } catch (e: Exception) {