mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 01:15:54 +03:00
Merge pull request #3080 from Dominaezzz/suspend_functions_10
Convert MembershipService to suspend functions
This commit is contained in:
commit
67c2b58f85
12 changed files with 107 additions and 154 deletions
|
@ -21,6 +21,7 @@ import io.reactivex.Completable
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import kotlinx.coroutines.rx2.rxCompletable
|
import kotlinx.coroutines.rx2.rxCompletable
|
||||||
|
import kotlinx.coroutines.rx2.rxSingle
|
||||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||||
import org.matrix.android.sdk.api.session.events.model.Event
|
import org.matrix.android.sdk.api.session.events.model.Event
|
||||||
import org.matrix.android.sdk.api.session.identity.ThreePid
|
import org.matrix.android.sdk.api.session.identity.ThreePid
|
||||||
|
@ -90,13 +91,13 @@ class RxRoom(private val room: Room) {
|
||||||
return room.getMyReadReceiptLive().asObservable()
|
return room.getMyReadReceiptLive().asObservable()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadRoomMembersIfNeeded(): Single<Unit> = singleBuilder {
|
fun loadRoomMembersIfNeeded(): Single<Unit> = rxSingle {
|
||||||
room.loadRoomMembersIfNeeded(it)
|
room.loadRoomMembersIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun joinRoom(reason: String? = null,
|
fun joinRoom(reason: String? = null,
|
||||||
viaServers: List<String> = emptyList()): Single<Unit> = singleBuilder {
|
viaServers: List<String> = emptyList()): Single<Unit> = rxSingle {
|
||||||
room.join(reason, viaServers, it)
|
room.join(reason, viaServers)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun liveEventReadReceipts(eventId: String): Observable<List<ReadReceipt>> {
|
fun liveEventReadReceipts(eventId: String): Observable<List<ReadReceipt>> {
|
||||||
|
@ -114,12 +115,12 @@ class RxRoom(private val room: Room) {
|
||||||
return room.getLiveRoomNotificationState().asObservable()
|
return room.getLiveRoomNotificationState().asObservable()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun invite(userId: String, reason: String? = null): Completable = completableBuilder<Unit> {
|
fun invite(userId: String, reason: String? = null): Completable = rxCompletable {
|
||||||
room.invite(userId, reason, it)
|
room.invite(userId, reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun invite3pid(threePid: ThreePid): Completable = completableBuilder<Unit> {
|
fun invite3pid(threePid: ThreePid): Completable = rxCompletable {
|
||||||
room.invite3pid(threePid, it)
|
room.invite3pid(threePid)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateTopic(topic: String): Completable = rxCompletable {
|
fun updateTopic(topic: String): Completable = rxCompletable {
|
||||||
|
|
|
@ -112,8 +112,8 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
|
||||||
bobRoomSummariesLive.observeForever(newRoomObserver)
|
bobRoomSummariesLive.observeForever(newRoomObserver)
|
||||||
}
|
}
|
||||||
|
|
||||||
mTestHelper.doSync<Unit> {
|
mTestHelper.runBlockingTest {
|
||||||
aliceRoom.invite(bobSession.myUserId, callback = it)
|
aliceRoom.invite(bobSession.myUserId)
|
||||||
}
|
}
|
||||||
|
|
||||||
mTestHelper.await(lock1)
|
mTestHelper.await(lock1)
|
||||||
|
@ -172,8 +172,8 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
|
||||||
fun createSamAccountAndInviteToTheRoom(room: Room): Session {
|
fun createSamAccountAndInviteToTheRoom(room: Room): Session {
|
||||||
val samSession = mTestHelper.createAccount(TestConstants.USER_SAM, defaultSessionParams)
|
val samSession = mTestHelper.createAccount(TestConstants.USER_SAM, defaultSessionParams)
|
||||||
|
|
||||||
mTestHelper.doSync<Unit> {
|
mTestHelper.runBlockingTest {
|
||||||
room.invite(samSession.myUserId, null, it)
|
room.invite(samSession.myUserId, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
mTestHelper.doSync<Unit> {
|
mTestHelper.doSync<Unit> {
|
||||||
|
@ -410,7 +410,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
|
||||||
val sessions = mutableListOf(aliceSession)
|
val sessions = mutableListOf(aliceSession)
|
||||||
for (index in 1 until numberOfMembers) {
|
for (index in 1 until numberOfMembers) {
|
||||||
val session = mTestHelper.createAccount("User_$index", defaultSessionParams)
|
val session = mTestHelper.createAccount("User_$index", defaultSessionParams)
|
||||||
mTestHelper.doSync<Unit>(timeout = 600_000) { room.invite(session.myUserId, null, it) }
|
mTestHelper.runBlockingTest(timeout = 600_000) { room.invite(session.myUserId, null) }
|
||||||
println("TEST -> " + session.myUserId + " invited")
|
println("TEST -> " + session.myUserId + " invited")
|
||||||
mTestHelper.doSync<Unit> { session.joinRoom(room.roomId, null, emptyList(), it) }
|
mTestHelper.doSync<Unit> { session.joinRoom(room.roomId, null, emptyList(), it) }
|
||||||
println("TEST -> " + session.myUserId + " joined")
|
println("TEST -> " + session.myUserId + " joined")
|
||||||
|
|
|
@ -367,8 +367,8 @@ class KeyShareTests : InstrumentedTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let alice invite bob
|
// Let alice invite bob
|
||||||
mTestHelper.doSync<Unit> {
|
mTestHelper.runBlockingTest {
|
||||||
roomAlicePov.invite(bobSession.myUserId, null, it)
|
roomAlicePov.invite(bobSession.myUserId, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
mTestHelper.doSync<Unit> {
|
mTestHelper.doSync<Unit> {
|
||||||
|
|
|
@ -17,10 +17,8 @@
|
||||||
package org.matrix.android.sdk.api.session.room.members
|
package org.matrix.android.sdk.api.session.room.members
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import org.matrix.android.sdk.api.MatrixCallback
|
|
||||||
import org.matrix.android.sdk.api.session.identity.ThreePid
|
import org.matrix.android.sdk.api.session.identity.ThreePid
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
||||||
import org.matrix.android.sdk.api.util.Cancelable
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface defines methods to handling membership. It's implemented at the room level.
|
* This interface defines methods to handling membership. It's implemented at the room level.
|
||||||
|
@ -29,9 +27,8 @@ interface MembershipService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This methods load all room members if it was done yet.
|
* This methods load all room members if it was done yet.
|
||||||
* @return a [Cancelable]
|
|
||||||
*/
|
*/
|
||||||
fun loadRoomMembersIfNeeded(matrixCallback: MatrixCallback<Unit>): Cancelable
|
suspend fun loadRoomMembersIfNeeded()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the roomMember with userId or null.
|
* Return the roomMember with userId or null.
|
||||||
|
@ -60,47 +57,35 @@ interface MembershipService {
|
||||||
/**
|
/**
|
||||||
* Invite a user in the room
|
* Invite a user in the room
|
||||||
*/
|
*/
|
||||||
fun invite(userId: String,
|
suspend fun invite(userId: String, reason: String? = null)
|
||||||
reason: String? = null,
|
|
||||||
callback: MatrixCallback<Unit>): Cancelable
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invite a user with email or phone number in the room
|
* Invite a user with email or phone number in the room
|
||||||
*/
|
*/
|
||||||
fun invite3pid(threePid: ThreePid,
|
suspend fun invite3pid(threePid: ThreePid)
|
||||||
callback: MatrixCallback<Unit>): Cancelable
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ban a user from the room
|
* Ban a user from the room
|
||||||
*/
|
*/
|
||||||
fun ban(userId: String,
|
suspend fun ban(userId: String, reason: String? = null)
|
||||||
reason: String? = null,
|
|
||||||
callback: MatrixCallback<Unit>): Cancelable
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unban a user from the room
|
* Unban a user from the room
|
||||||
*/
|
*/
|
||||||
fun unban(userId: String,
|
suspend fun unban(userId: String, reason: String? = null)
|
||||||
reason: String? = null,
|
|
||||||
callback: MatrixCallback<Unit>): Cancelable
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kick a user from the room
|
* Kick a user from the room
|
||||||
*/
|
*/
|
||||||
fun kick(userId: String,
|
suspend fun kick(userId: String, reason: String? = null)
|
||||||
reason: String? = null,
|
|
||||||
callback: MatrixCallback<Unit>): Cancelable
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Join the room, or accept an invitation.
|
* Join the room, or accept an invitation.
|
||||||
*/
|
*/
|
||||||
fun join(reason: String? = null,
|
suspend fun join(reason: String? = null, viaServers: List<String> = emptyList())
|
||||||
viaServers: List<String> = emptyList(),
|
|
||||||
callback: MatrixCallback<Unit>): Cancelable
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Leave the room, or reject an invitation.
|
* Leave the room, or reject an invitation.
|
||||||
*/
|
*/
|
||||||
fun leave(reason: String? = null,
|
suspend fun leave(reason: String? = null)
|
||||||
callback: MatrixCallback<Unit>): Cancelable
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,11 @@ import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import org.matrix.android.sdk.api.MatrixCallback
|
|
||||||
import org.matrix.android.sdk.api.session.identity.ThreePid
|
import org.matrix.android.sdk.api.session.identity.ThreePid
|
||||||
import org.matrix.android.sdk.api.session.room.members.MembershipService
|
import org.matrix.android.sdk.api.session.room.members.MembershipService
|
||||||
import org.matrix.android.sdk.api.session.room.members.RoomMemberQueryParams
|
import org.matrix.android.sdk.api.session.room.members.RoomMemberQueryParams
|
||||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
||||||
import org.matrix.android.sdk.api.util.Cancelable
|
|
||||||
import org.matrix.android.sdk.internal.database.mapper.asDomain
|
import org.matrix.android.sdk.internal.database.mapper.asDomain
|
||||||
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntity
|
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntity
|
||||||
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntityFields
|
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntityFields
|
||||||
|
@ -39,8 +37,6 @@ import org.matrix.android.sdk.internal.session.room.membership.joining.InviteTas
|
||||||
import org.matrix.android.sdk.internal.session.room.membership.joining.JoinRoomTask
|
import org.matrix.android.sdk.internal.session.room.membership.joining.JoinRoomTask
|
||||||
import org.matrix.android.sdk.internal.session.room.membership.leaving.LeaveRoomTask
|
import org.matrix.android.sdk.internal.session.room.membership.leaving.LeaveRoomTask
|
||||||
import org.matrix.android.sdk.internal.session.room.membership.threepid.InviteThreePidTask
|
import org.matrix.android.sdk.internal.session.room.membership.threepid.InviteThreePidTask
|
||||||
import org.matrix.android.sdk.internal.task.TaskExecutor
|
|
||||||
import org.matrix.android.sdk.internal.task.configureWith
|
|
||||||
import org.matrix.android.sdk.internal.util.fetchCopied
|
import org.matrix.android.sdk.internal.util.fetchCopied
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import io.realm.RealmQuery
|
import io.realm.RealmQuery
|
||||||
|
@ -48,7 +44,6 @@ import io.realm.RealmQuery
|
||||||
internal class DefaultMembershipService @AssistedInject constructor(
|
internal class DefaultMembershipService @AssistedInject constructor(
|
||||||
@Assisted private val roomId: String,
|
@Assisted private val roomId: String,
|
||||||
@SessionDatabase private val monarchy: Monarchy,
|
@SessionDatabase private val monarchy: Monarchy,
|
||||||
private val taskExecutor: TaskExecutor,
|
|
||||||
private val loadRoomMembersTask: LoadRoomMembersTask,
|
private val loadRoomMembersTask: LoadRoomMembersTask,
|
||||||
private val inviteTask: InviteTask,
|
private val inviteTask: InviteTask,
|
||||||
private val inviteThreePidTask: InviteThreePidTask,
|
private val inviteThreePidTask: InviteThreePidTask,
|
||||||
|
@ -64,13 +59,9 @@ internal class DefaultMembershipService @AssistedInject constructor(
|
||||||
fun create(roomId: String): DefaultMembershipService
|
fun create(roomId: String): DefaultMembershipService
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadRoomMembersIfNeeded(matrixCallback: MatrixCallback<Unit>): Cancelable {
|
override suspend fun loadRoomMembersIfNeeded() {
|
||||||
val params = LoadRoomMembersTask.Params(roomId, Membership.LEAVE)
|
val params = LoadRoomMembersTask.Params(roomId, Membership.LEAVE)
|
||||||
return loadRoomMembersTask
|
loadRoomMembersTask.execute(params)
|
||||||
.configureWith(params) {
|
|
||||||
this.callback = matrixCallback
|
|
||||||
}
|
|
||||||
.executeBy(taskExecutor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getRoomMember(userId: String): RoomMemberSummary? {
|
override fun getRoomMember(userId: String): RoomMemberSummary? {
|
||||||
|
@ -120,66 +111,38 @@ internal class DefaultMembershipService @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun ban(userId: String, reason: String?, callback: MatrixCallback<Unit>): Cancelable {
|
override suspend fun ban(userId: String, reason: String?) {
|
||||||
val params = MembershipAdminTask.Params(MembershipAdminTask.Type.BAN, roomId, userId, reason)
|
val params = MembershipAdminTask.Params(MembershipAdminTask.Type.BAN, roomId, userId, reason)
|
||||||
return membershipAdminTask
|
membershipAdminTask.execute(params)
|
||||||
.configureWith(params) {
|
|
||||||
this.callback = callback
|
|
||||||
}
|
|
||||||
.executeBy(taskExecutor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun unban(userId: String, reason: String?, callback: MatrixCallback<Unit>): Cancelable {
|
override suspend fun unban(userId: String, reason: String?) {
|
||||||
val params = MembershipAdminTask.Params(MembershipAdminTask.Type.UNBAN, roomId, userId, reason)
|
val params = MembershipAdminTask.Params(MembershipAdminTask.Type.UNBAN, roomId, userId, reason)
|
||||||
return membershipAdminTask
|
membershipAdminTask.execute(params)
|
||||||
.configureWith(params) {
|
|
||||||
this.callback = callback
|
|
||||||
}
|
|
||||||
.executeBy(taskExecutor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun kick(userId: String, reason: String?, callback: MatrixCallback<Unit>): Cancelable {
|
override suspend fun kick(userId: String, reason: String?) {
|
||||||
val params = MembershipAdminTask.Params(MembershipAdminTask.Type.KICK, roomId, userId, reason)
|
val params = MembershipAdminTask.Params(MembershipAdminTask.Type.KICK, roomId, userId, reason)
|
||||||
return membershipAdminTask
|
membershipAdminTask.execute(params)
|
||||||
.configureWith(params) {
|
|
||||||
this.callback = callback
|
|
||||||
}
|
|
||||||
.executeBy(taskExecutor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun invite(userId: String, reason: String?, callback: MatrixCallback<Unit>): Cancelable {
|
override suspend fun invite(userId: String, reason: String?) {
|
||||||
val params = InviteTask.Params(roomId, userId, reason)
|
val params = InviteTask.Params(roomId, userId, reason)
|
||||||
return inviteTask
|
inviteTask.execute(params)
|
||||||
.configureWith(params) {
|
|
||||||
this.callback = callback
|
|
||||||
}
|
|
||||||
.executeBy(taskExecutor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun invite3pid(threePid: ThreePid, callback: MatrixCallback<Unit>): Cancelable {
|
override suspend fun invite3pid(threePid: ThreePid) {
|
||||||
val params = InviteThreePidTask.Params(roomId, threePid)
|
val params = InviteThreePidTask.Params(roomId, threePid)
|
||||||
return inviteThreePidTask
|
return inviteThreePidTask.execute(params)
|
||||||
.configureWith(params) {
|
|
||||||
this.callback = callback
|
|
||||||
}
|
|
||||||
.executeBy(taskExecutor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun join(reason: String?, viaServers: List<String>, callback: MatrixCallback<Unit>): Cancelable {
|
override suspend fun join(reason: String?, viaServers: List<String>) {
|
||||||
val params = JoinRoomTask.Params(roomId, reason, viaServers)
|
val params = JoinRoomTask.Params(roomId, reason, viaServers)
|
||||||
return joinTask
|
joinTask.execute(params)
|
||||||
.configureWith(params) {
|
|
||||||
this.callback = callback
|
|
||||||
}
|
|
||||||
.executeBy(taskExecutor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun leave(reason: String?, callback: MatrixCallback<Unit>): Cancelable {
|
override suspend fun leave(reason: String?) {
|
||||||
val params = LeaveRoomTask.Params(roomId, reason)
|
val params = LeaveRoomTask.Params(roomId, reason)
|
||||||
return leaveRoomTask
|
leaveRoomTask.execute(params)
|
||||||
.configureWith(params) {
|
|
||||||
this.callback = callback
|
|
||||||
}
|
|
||||||
.executeBy(taskExecutor)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -945,14 +945,14 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleInviteSlashCommand(invite: ParsedCommand.Invite) {
|
private fun handleInviteSlashCommand(invite: ParsedCommand.Invite) {
|
||||||
launchSlashCommandFlow {
|
launchSlashCommandFlowSuspendable {
|
||||||
room.invite(invite.userId, invite.reason, it)
|
room.invite(invite.userId, invite.reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleInvite3pidSlashCommand(invite: ParsedCommand.Invite3Pid) {
|
private fun handleInvite3pidSlashCommand(invite: ParsedCommand.Invite3Pid) {
|
||||||
launchSlashCommandFlow {
|
launchSlashCommandFlowSuspendable {
|
||||||
room.invite3pid(invite.threePid, it)
|
room.invite3pid(invite.threePid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -976,20 +976,20 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleKickSlashCommand(kick: ParsedCommand.KickUser) {
|
private fun handleKickSlashCommand(kick: ParsedCommand.KickUser) {
|
||||||
launchSlashCommandFlow {
|
launchSlashCommandFlowSuspendable {
|
||||||
room.kick(kick.userId, kick.reason, it)
|
room.kick(kick.userId, kick.reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleBanSlashCommand(ban: ParsedCommand.BanUser) {
|
private fun handleBanSlashCommand(ban: ParsedCommand.BanUser) {
|
||||||
launchSlashCommandFlow {
|
launchSlashCommandFlowSuspendable {
|
||||||
room.ban(ban.userId, ban.reason, it)
|
room.ban(ban.userId, ban.reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleUnbanSlashCommand(unban: ParsedCommand.UnbanUser) {
|
private fun handleUnbanSlashCommand(unban: ParsedCommand.UnbanUser) {
|
||||||
launchSlashCommandFlow {
|
launchSlashCommandFlowSuspendable {
|
||||||
room.unban(unban.userId, unban.reason, it)
|
room.unban(unban.userId, unban.reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1093,11 +1093,21 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleRejectInvite() {
|
private fun handleRejectInvite() {
|
||||||
room.leave(null, NoOpMatrixCallback())
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
|
room.leave(null)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleAcceptInvite() {
|
private fun handleAcceptInvite() {
|
||||||
room.join(callback = NoOpMatrixCallback())
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
|
room.join()
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleEditAction(action: RoomDetailAction.EnterEditMode) {
|
private fun handleEditAction(action: RoomDetailAction.EnterEditMode) {
|
||||||
|
|
|
@ -26,7 +26,6 @@ import im.vector.app.core.utils.DataSource
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.MatrixCallback
|
|
||||||
import org.matrix.android.sdk.api.NoOpMatrixCallback
|
import org.matrix.android.sdk.api.NoOpMatrixCallback
|
||||||
import org.matrix.android.sdk.api.extensions.orFalse
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
|
@ -127,17 +126,17 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
||||||
return@withState
|
return@withState
|
||||||
}
|
}
|
||||||
|
|
||||||
session.getRoom(roomId)?.join(callback = object : MatrixCallback<Unit> {
|
val room = session.getRoom(roomId) ?: return@withState
|
||||||
override fun onSuccess(data: Unit) {
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
|
room.join()
|
||||||
// We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data.
|
// We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data.
|
||||||
// Instead, we wait for the room to be joined
|
// Instead, we wait for the room to be joined
|
||||||
}
|
} catch (failure: Throwable) {
|
||||||
|
|
||||||
override fun onFailure(failure: Throwable) {
|
|
||||||
// Notify the user
|
// Notify the user
|
||||||
_viewEvents.post(RoomListViewEvents.Failure(failure))
|
_viewEvents.post(RoomListViewEvents.Failure(failure))
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleRejectInvitation(action: RoomListAction.RejectInvitation) = withState { state ->
|
private fun handleRejectInvitation(action: RoomListAction.RejectInvitation) = withState { state ->
|
||||||
|
@ -149,19 +148,19 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
||||||
return@withState
|
return@withState
|
||||||
}
|
}
|
||||||
|
|
||||||
session.getRoom(roomId)?.leave(null, object : MatrixCallback<Unit> {
|
val room = session.getRoom(roomId) ?: return@withState
|
||||||
override fun onSuccess(data: Unit) {
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
|
room.leave(null)
|
||||||
// We do not update the rejectingRoomsIds here, because, the room is not rejected yet regarding the sync data.
|
// We do not update the rejectingRoomsIds here, because, the room is not rejected yet regarding the sync data.
|
||||||
// Instead, we wait for the room to be rejected
|
// Instead, we wait for the room to be rejected
|
||||||
// Known bug: if the user is invited again (after rejecting the first invitation), the loading will be displayed instead of the buttons.
|
// Known bug: if the user is invited again (after rejecting the first invitation), the loading will be displayed instead of the buttons.
|
||||||
// If we update the state, the button will be displayed again, so it's not ideal...
|
// If we update the state, the button will be displayed again, so it's not ideal...
|
||||||
}
|
} catch (failure: Throwable) {
|
||||||
|
|
||||||
override fun onFailure(failure: Throwable) {
|
|
||||||
// Notify the user
|
// Notify the user
|
||||||
_viewEvents.post(RoomListViewEvents.Failure(failure))
|
_viewEvents.post(RoomListViewEvents.Failure(failure))
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleMarkAllRoomsRead() = withState { state ->
|
private fun handleMarkAllRoomsRead() = withState { state ->
|
||||||
|
@ -220,15 +219,12 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
||||||
|
|
||||||
private fun handleLeaveRoom(action: RoomListAction.LeaveRoom) {
|
private fun handleLeaveRoom(action: RoomListAction.LeaveRoom) {
|
||||||
_viewEvents.post(RoomListViewEvents.Loading(null))
|
_viewEvents.post(RoomListViewEvents.Loading(null))
|
||||||
session.getRoom(action.roomId)?.leave(null, object : MatrixCallback<Unit> {
|
val room = session.getRoom(action.roomId) ?: return
|
||||||
override fun onSuccess(data: Unit) {
|
viewModelScope.launch {
|
||||||
_viewEvents.post(RoomListViewEvents.Done)
|
val value = runCatching { room.leave(null) }
|
||||||
}
|
.fold({ RoomListViewEvents.Done }, { RoomListViewEvents.Failure(it) })
|
||||||
|
_viewEvents.post(value)
|
||||||
override fun onFailure(failure: Throwable) {
|
}
|
||||||
_viewEvents.post(RoomListViewEvents.Failure(failure))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeMembershipChanges() {
|
private fun observeMembershipChanges() {
|
||||||
|
|
|
@ -76,15 +76,23 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
private fun handleJoinRoom(roomId: String) {
|
private fun handleJoinRoom(roomId: String) {
|
||||||
activeSessionHolder.getSafeActiveSession()?.let { session ->
|
activeSessionHolder.getSafeActiveSession()?.let { session ->
|
||||||
session.getRoom(roomId)
|
val room = session.getRoom(roomId)
|
||||||
?.join(callback = NoOpMatrixCallback())
|
if (room != null) {
|
||||||
|
GlobalScope.launch {
|
||||||
|
room.join()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleRejectRoom(roomId: String) {
|
private fun handleRejectRoom(roomId: String) {
|
||||||
activeSessionHolder.getSafeActiveSession()?.let { session ->
|
activeSessionHolder.getSafeActiveSession()?.let { session ->
|
||||||
session.getRoom(roomId)
|
val room = session.getRoom(roomId)
|
||||||
?.leave(callback = NoOpMatrixCallback())
|
if (room != null) {
|
||||||
|
GlobalScope.launch {
|
||||||
|
room.leave()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,6 @@ import org.matrix.android.sdk.api.session.room.powerlevels.Role
|
||||||
import org.matrix.android.sdk.api.util.MatrixItem
|
import org.matrix.android.sdk.api.util.MatrixItem
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import org.matrix.android.sdk.api.util.toOptional
|
import org.matrix.android.sdk.api.util.toOptional
|
||||||
import org.matrix.android.sdk.internal.util.awaitCallback
|
|
||||||
import org.matrix.android.sdk.rx.rx
|
import org.matrix.android.sdk.rx.rx
|
||||||
import org.matrix.android.sdk.rx.unwrap
|
import org.matrix.android.sdk.rx.unwrap
|
||||||
|
|
||||||
|
@ -197,9 +196,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
_viewEvents.post(RoomMemberProfileViewEvents.Loading())
|
_viewEvents.post(RoomMemberProfileViewEvents.Loading())
|
||||||
awaitCallback<Unit> {
|
room.invite(initialState.userId)
|
||||||
room.invite(initialState.userId, callback = it)
|
|
||||||
}
|
|
||||||
_viewEvents.post(RoomMemberProfileViewEvents.OnInviteActionSuccess)
|
_viewEvents.post(RoomMemberProfileViewEvents.OnInviteActionSuccess)
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
_viewEvents.post(RoomMemberProfileViewEvents.Failure(failure))
|
_viewEvents.post(RoomMemberProfileViewEvents.Failure(failure))
|
||||||
|
@ -214,9 +211,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
_viewEvents.post(RoomMemberProfileViewEvents.Loading())
|
_viewEvents.post(RoomMemberProfileViewEvents.Loading())
|
||||||
awaitCallback<Unit> {
|
room.kick(initialState.userId, action.reason)
|
||||||
room.kick(initialState.userId, action.reason, it)
|
|
||||||
}
|
|
||||||
_viewEvents.post(RoomMemberProfileViewEvents.OnKickActionSuccess)
|
_viewEvents.post(RoomMemberProfileViewEvents.OnKickActionSuccess)
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
_viewEvents.post(RoomMemberProfileViewEvents.Failure(failure))
|
_viewEvents.post(RoomMemberProfileViewEvents.Failure(failure))
|
||||||
|
@ -232,12 +227,10 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
_viewEvents.post(RoomMemberProfileViewEvents.Loading())
|
_viewEvents.post(RoomMemberProfileViewEvents.Loading())
|
||||||
awaitCallback<Unit> {
|
if (membership == Membership.BAN) {
|
||||||
if (membership == Membership.BAN) {
|
room.unban(initialState.userId, action.reason)
|
||||||
room.unban(initialState.userId, action.reason, it)
|
} else {
|
||||||
} else {
|
room.ban(initialState.userId, action.reason)
|
||||||
room.ban(initialState.userId, action.reason, it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_viewEvents.post(RoomMemberProfileViewEvents.OnBanActionSuccess)
|
_viewEvents.post(RoomMemberProfileViewEvents.OnBanActionSuccess)
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
|
|
|
@ -32,7 +32,6 @@ import im.vector.app.features.home.ShortcutCreator
|
||||||
import im.vector.app.features.powerlevel.PowerLevelsObservableFactory
|
import im.vector.app.features.powerlevel.PowerLevelsObservableFactory
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.MatrixCallback
|
|
||||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||||
|
@ -169,15 +168,14 @@ class RoomProfileViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
private fun handleLeaveRoom() {
|
private fun handleLeaveRoom() {
|
||||||
_viewEvents.post(RoomProfileViewEvents.Loading(stringProvider.getString(R.string.room_profile_leaving_room)))
|
_viewEvents.post(RoomProfileViewEvents.Loading(stringProvider.getString(R.string.room_profile_leaving_room)))
|
||||||
room.leave(null, object : MatrixCallback<Unit> {
|
viewModelScope.launch {
|
||||||
override fun onSuccess(data: Unit) {
|
try {
|
||||||
|
room.leave(null)
|
||||||
// Do nothing, we will be closing the room automatically when it will get back from sync
|
// Do nothing, we will be closing the room automatically when it will get back from sync
|
||||||
}
|
} catch (failure: Throwable) {
|
||||||
|
|
||||||
override fun onFailure(failure: Throwable) {
|
|
||||||
_viewEvents.post(RoomProfileViewEvents.Failure(failure))
|
_viewEvents.post(RoomProfileViewEvents.Failure(failure))
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleShareRoomProfile() {
|
private fun handleShareRoomProfile() {
|
||||||
|
|
|
@ -39,7 +39,6 @@ import org.matrix.android.sdk.api.session.room.model.Membership
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
|
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
||||||
import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
|
import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
|
||||||
import org.matrix.android.sdk.internal.util.awaitCallback
|
|
||||||
import org.matrix.android.sdk.rx.rx
|
import org.matrix.android.sdk.rx.rx
|
||||||
import org.matrix.android.sdk.rx.unwrap
|
import org.matrix.android.sdk.rx.unwrap
|
||||||
|
|
||||||
|
@ -124,9 +123,7 @@ class RoomBannedMemberListViewModel @AssistedInject constructor(@Assisted initia
|
||||||
}
|
}
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
awaitCallback<Unit> {
|
room.unban(roomMemberSummary.userId, null)
|
||||||
room.unban(roomMemberSummary.userId, null, it)
|
|
||||||
}
|
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
_viewEvents.post(RoomBannedMemberListViewEvents.ToastError(stringProvider.getString(R.string.failed_to_unban)))
|
_viewEvents.post(RoomBannedMemberListViewEvents.ToastError(stringProvider.getString(R.string.failed_to_unban)))
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -387,7 +387,9 @@ class WidgetPostAPIHandler @AssistedInject constructor(@Assisted private val roo
|
||||||
if (member != null && member.membership == Membership.JOIN) {
|
if (member != null && member.membership == Membership.JOIN) {
|
||||||
widgetPostAPIMediator.sendSuccess(eventData)
|
widgetPostAPIMediator.sendSuccess(eventData)
|
||||||
} else {
|
} else {
|
||||||
room.invite(userId = userId, callback = createWidgetAPICallback(widgetPostAPIMediator, eventData))
|
launchWidgetAPIAction(widgetPostAPIMediator, eventData) {
|
||||||
|
room.invite(userId = userId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue