Set liked flag on first load

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-10-18 23:05:59 +05:30
parent 1021604889
commit 0336af0624
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80

View file

@ -62,6 +62,8 @@ class LobstersViewModel @ViewModelInject constructor(
private fun getMorePostsInternal(firstLoad: Boolean) {
viewModelScope.launch(coroutineExceptionHandler) {
val newPosts = lobstersApi.getHottestPosts(apiPage)
.map { it.apply { if (savedPostsDao.isLiked(shortId)) isLiked = true } }
.toList()
if (firstLoad) {
_posts.value = newPosts
postsDao.deleteAllPosts()