mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Convert TagsService to suspend functions
Signed-off-by: Dominic Fischer <dominicfischer7@gmail.com>
This commit is contained in:
parent
8dff0b2c5d
commit
4dff9316c2
@ -16,9 +16,6 @@
|
||||
|
||||
package org.matrix.android.sdk.api.session.room.tags
|
||||
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
import org.matrix.android.sdk.api.util.Cancelable
|
||||
|
||||
/**
|
||||
* This interface defines methods to handle tags of a room. It's implemented at the room level.
|
||||
*/
|
||||
@ -26,10 +23,10 @@ interface TagsService {
|
||||
/**
|
||||
* Add a tag to a room
|
||||
*/
|
||||
fun addTag(tag: String, order: Double?, callback: MatrixCallback<Unit>): Cancelable
|
||||
suspend fun addTag(tag: String, order: Double?)
|
||||
|
||||
/**
|
||||
* Remove tag from a room
|
||||
*/
|
||||
fun deleteTag(tag: String, callback: MatrixCallback<Unit>): Cancelable
|
||||
suspend fun deleteTag(tag: String)
|
||||
}
|
||||
|
@ -18,15 +18,10 @@ package org.matrix.android.sdk.internal.session.room.tags
|
||||
|
||||
import com.squareup.inject.assisted.Assisted
|
||||
import com.squareup.inject.assisted.AssistedInject
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
import org.matrix.android.sdk.api.session.room.tags.TagsService
|
||||
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 DefaultTagsService @AssistedInject constructor(
|
||||
@Assisted private val roomId: String,
|
||||
private val taskExecutor: TaskExecutor,
|
||||
private val addTagToRoomTask: AddTagToRoomTask,
|
||||
private val deleteTagFromRoomTask: DeleteTagFromRoomTask
|
||||
) : TagsService {
|
||||
@ -36,21 +31,13 @@ internal class DefaultTagsService @AssistedInject constructor(
|
||||
fun create(roomId: String): TagsService
|
||||
}
|
||||
|
||||
override fun addTag(tag: String, order: Double?, callback: MatrixCallback<Unit>): Cancelable {
|
||||
override suspend fun addTag(tag: String, order: Double?) {
|
||||
val params = AddTagToRoomTask.Params(roomId, tag, order)
|
||||
return addTagToRoomTask
|
||||
.configureWith(params) {
|
||||
this.callback = callback
|
||||
}
|
||||
.executeBy(taskExecutor)
|
||||
addTagToRoomTask.execute(params)
|
||||
}
|
||||
|
||||
override fun deleteTag(tag: String, callback: MatrixCallback<Unit>): Cancelable {
|
||||
override suspend fun deleteTag(tag: String) {
|
||||
val params = DeleteTagFromRoomTask.Params(roomId, tag)
|
||||
return deleteTagFromRoomTask
|
||||
.configureWith(params) {
|
||||
this.callback = callback
|
||||
}
|
||||
.executeBy(taskExecutor)
|
||||
deleteTagFromRoomTask.execute(params)
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import org.matrix.android.sdk.api.session.room.model.tag.RoomTag
|
||||
import org.matrix.android.sdk.internal.util.awaitCallback
|
||||
import org.matrix.android.sdk.rx.rx
|
||||
import timber.log.Timber
|
||||
import java.lang.Exception
|
||||
@ -191,17 +190,13 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
||||
action.tag.otherTag()
|
||||
?.takeIf { room.roomSummary()?.hasTag(it).orFalse() }
|
||||
?.let { tagToRemove ->
|
||||
awaitCallback<Unit> { room.deleteTag(tagToRemove, it) }
|
||||
room.deleteTag(tagToRemove)
|
||||
}
|
||||
|
||||
// Set the tag. We do not handle the order for the moment
|
||||
awaitCallback<Unit> {
|
||||
room.addTag(action.tag, 0.5, it)
|
||||
}
|
||||
room.addTag(action.tag, 0.5)
|
||||
} else {
|
||||
awaitCallback<Unit> {
|
||||
room.deleteTag(action.tag, it)
|
||||
}
|
||||
room.deleteTag(action.tag)
|
||||
}
|
||||
} catch (failure: Throwable) {
|
||||
_viewEvents.post(RoomListViewEvents.Failure(failure))
|
||||
|
Loading…
Reference in New Issue
Block a user