Skip to content

Commit

Permalink
Merge pull request #2413 from Dominaezzz/suspend_functions
Browse files Browse the repository at this point in the history
Convert Group to suspend functions
  • Loading branch information
bmarty authored Nov 19, 2020
2 parents ca0da2c + 1359c6b commit 3ec25f3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package org.matrix.android.sdk.api.session.group

import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.util.Cancelable

/**
* This interface defines methods to interact within a group.
*/
Expand All @@ -28,8 +25,7 @@ interface Group {
/**
* This methods allows you to refresh data about this group. It will be reflected on the GroupSummary.
* The SDK also takes care of refreshing group data every hour.
* @param callback : the matrix callback to be notified of success or failure
* @return a Cancelable to be able to cancel requests.
*/
fun fetchGroupData(callback: MatrixCallback<Unit>): Cancelable
suspend fun fetchGroupData()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,13 @@

package org.matrix.android.sdk.internal.session.group

import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.group.Group
import org.matrix.android.sdk.api.util.Cancelable
import org.matrix.android.sdk.internal.task.TaskExecutor
import org.matrix.android.sdk.internal.task.configureWith

internal class DefaultGroup(override val groupId: String,
private val taskExecutor: TaskExecutor,
private val getGroupDataTask: GetGroupDataTask) : Group {

override fun fetchGroupData(callback: MatrixCallback<Unit>): Cancelable {
override suspend fun fetchGroupData() {
val params = GetGroupDataTask.Params.FetchWithIds(listOf(groupId))
return getGroupDataTask.configureWith(params) {
this.callback = callback
}.executeBy(taskExecutor)
getGroupDataTask.execute(params)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@ package org.matrix.android.sdk.internal.session.group

import org.matrix.android.sdk.api.session.group.Group
import org.matrix.android.sdk.internal.session.SessionScope
import org.matrix.android.sdk.internal.task.TaskExecutor
import javax.inject.Inject

internal interface GroupFactory {
fun create(groupId: String): Group
}

@SessionScope
internal class DefaultGroupFactory @Inject constructor(private val getGroupDataTask: GetGroupDataTask,
private val taskExecutor: TaskExecutor) :
internal class DefaultGroupFactory @Inject constructor(private val getGroupDataTask: GetGroupDataTask) :
GroupFactory {

override fun create(groupId: String): Group {
return DefaultGroup(
groupId = groupId,
taskExecutor = taskExecutor,
getGroupDataTask = getGroupDataTask
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package im.vector.app.features.grouplist

import androidx.lifecycle.viewModelScope
import arrow.core.Option
import com.airbnb.mvrx.FragmentViewModelContext
import com.airbnb.mvrx.MvRxViewModelFactory
Expand All @@ -28,7 +29,7 @@ import im.vector.app.core.platform.VectorViewModel
import im.vector.app.core.resources.StringProvider
import io.reactivex.Observable
import io.reactivex.functions.BiFunction
import org.matrix.android.sdk.api.NoOpMatrixCallback
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.group.groupSummaryQueryParams
Expand Down Expand Up @@ -95,7 +96,9 @@ class GroupListViewModel @AssistedInject constructor(@Assisted initialState: Gro
private fun handleSelectGroup(action: GroupListAction.SelectGroup) = withState { state ->
if (state.selectedGroup?.groupId != action.groupSummary.groupId) {
// We take care of refreshing group data when selecting to be sure we get all the rooms and users
session.getGroup(action.groupSummary.groupId)?.fetchGroupData(NoOpMatrixCallback())
viewModelScope.launch {
session.getGroup(action.groupSummary.groupId)?.fetchGroupData()
}
setState { copy(selectedGroup = action.groupSummary) }
}
}
Expand Down

0 comments on commit 3ec25f3

Please sign in to comment.