Skip to content

Commit

Permalink
Make the coroutine block cover the entire function
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarvis Lin committed Feb 15, 2024
1 parent 050cc68 commit 2b40d4c
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.MutableSharedFlow
import org.greenrobot.eventbus.EventBus
import org.wordpress.android.datasets.NotificationsTable
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.store.CommentsStore
import org.wordpress.android.fluxc.store.SiteStore
import org.wordpress.android.models.Note
Expand Down Expand Up @@ -77,15 +78,16 @@ class NotificationsListViewModel @Inject constructor(
}
}

fun likeComment(note: Note, liked: Boolean) {
val site = siteStore.getSiteBySiteId(note.siteId.toLong()) ?: return
fun likeComment(note: Note, liked: Boolean) = launch {
val site = siteStore.getSiteBySiteId(note.siteId.toLong()) ?: SiteModel().apply {
siteId = note.siteId.toLong()
setIsWPCom(true)
}
note.setLikedComment(liked)
_updatedNote.postValue(note)
launch {
val result = commentStore.likeComment(site, note.commentId, null, liked)
if (result.isError.not()) {
NotificationsTable.saveNote(note)
}
val result = commentStore.likeComment(site, note.commentId, null, liked)
if (result.isError.not()) {
NotificationsTable.saveNote(note)
}
}

Expand Down

0 comments on commit 2b40d4c

Please sign in to comment.