|
|
|
@ -17,6 +17,7 @@ import androidx.compose.runtime.mutableStateOf
@@ -17,6 +17,7 @@ import androidx.compose.runtime.mutableStateOf
|
|
|
|
|
import androidx.compose.runtime.produceState |
|
|
|
|
import androidx.compose.runtime.remember |
|
|
|
|
import androidx.compose.runtime.rememberCoroutineScope |
|
|
|
|
import androidx.compose.runtime.saveable.rememberSaveable |
|
|
|
|
import androidx.compose.runtime.setValue |
|
|
|
|
import dagger.assisted.Assisted |
|
|
|
|
import dagger.assisted.AssistedInject |
|
|
|
@ -24,6 +25,7 @@ import im.vector.app.features.analytics.plan.JoinedRoom
@@ -24,6 +25,7 @@ import im.vector.app.features.analytics.plan.JoinedRoom
|
|
|
|
|
import io.element.android.features.invite.api.response.AcceptDeclineInviteEvents |
|
|
|
|
import io.element.android.features.invite.api.response.AcceptDeclineInviteState |
|
|
|
|
import io.element.android.features.invite.api.response.InviteData |
|
|
|
|
import io.element.android.features.joinroom.impl.di.CancelKnockRoom |
|
|
|
|
import io.element.android.features.joinroom.impl.di.KnockRoom |
|
|
|
|
import io.element.android.features.roomdirectory.api.RoomDescription |
|
|
|
|
import io.element.android.libraries.architecture.AsyncAction |
|
|
|
@ -46,6 +48,8 @@ import kotlinx.coroutines.CoroutineScope
@@ -46,6 +48,8 @@ import kotlinx.coroutines.CoroutineScope
|
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
import java.util.Optional |
|
|
|
|
|
|
|
|
|
private const val MAX_KNOCK_MESSAGE_LENGTH = 500 |
|
|
|
|
|
|
|
|
|
class JoinRoomPresenter @AssistedInject constructor( |
|
|
|
|
@Assisted private val roomId: RoomId, |
|
|
|
|
@Assisted private val roomIdOrAlias: RoomIdOrAlias, |
|
|
|
@ -55,6 +59,7 @@ class JoinRoomPresenter @AssistedInject constructor(
@@ -55,6 +59,7 @@ class JoinRoomPresenter @AssistedInject constructor(
|
|
|
|
|
private val matrixClient: MatrixClient, |
|
|
|
|
private val joinRoom: JoinRoom, |
|
|
|
|
private val knockRoom: KnockRoom, |
|
|
|
|
private val cancelKnockRoom: CancelKnockRoom, |
|
|
|
|
private val acceptDeclineInvitePresenter: Presenter<AcceptDeclineInviteState>, |
|
|
|
|
private val buildMeta: BuildMeta, |
|
|
|
|
) : Presenter<JoinRoomState> { |
|
|
|
@ -76,6 +81,7 @@ class JoinRoomPresenter @AssistedInject constructor(
@@ -76,6 +81,7 @@ class JoinRoomPresenter @AssistedInject constructor(
|
|
|
|
|
val joinAction: MutableState<AsyncAction<Unit>> = remember { mutableStateOf(AsyncAction.Uninitialized) } |
|
|
|
|
val knockAction: MutableState<AsyncAction<Unit>> = remember { mutableStateOf(AsyncAction.Uninitialized) } |
|
|
|
|
val cancelKnockAction: MutableState<AsyncAction<Unit>> = remember { mutableStateOf(AsyncAction.Uninitialized) } |
|
|
|
|
var knockMessage by rememberSaveable { mutableStateOf("") } |
|
|
|
|
val contentState by produceState<ContentState>( |
|
|
|
|
initialValue = ContentState.Loading(roomIdOrAlias), |
|
|
|
|
key1 = roomInfo, |
|
|
|
@ -111,7 +117,7 @@ class JoinRoomPresenter @AssistedInject constructor(
@@ -111,7 +117,7 @@ class JoinRoomPresenter @AssistedInject constructor(
|
|
|
|
|
fun handleEvents(event: JoinRoomEvents) { |
|
|
|
|
when (event) { |
|
|
|
|
JoinRoomEvents.JoinRoom -> coroutineScope.joinRoom(joinAction) |
|
|
|
|
is JoinRoomEvents.KnockRoom -> coroutineScope.knockRoom(knockAction, event.message) |
|
|
|
|
is JoinRoomEvents.KnockRoom -> coroutineScope.knockRoom(knockAction, knockMessage) |
|
|
|
|
JoinRoomEvents.AcceptInvite -> { |
|
|
|
|
val inviteData = contentState.toInviteData() ?: return |
|
|
|
|
acceptDeclineInviteState.eventSink( |
|
|
|
@ -133,6 +139,9 @@ class JoinRoomPresenter @AssistedInject constructor(
@@ -133,6 +139,9 @@ class JoinRoomPresenter @AssistedInject constructor(
|
|
|
|
|
joinAction.value = AsyncAction.Uninitialized |
|
|
|
|
cancelKnockAction.value = AsyncAction.Uninitialized |
|
|
|
|
} |
|
|
|
|
is JoinRoomEvents.UpdateKnockMessage -> { |
|
|
|
|
knockMessage = event.message.take(MAX_KNOCK_MESSAGE_LENGTH) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -143,6 +152,7 @@ class JoinRoomPresenter @AssistedInject constructor(
@@ -143,6 +152,7 @@ class JoinRoomPresenter @AssistedInject constructor(
|
|
|
|
|
knockAction = knockAction.value, |
|
|
|
|
cancelKnockAction = cancelKnockAction.value, |
|
|
|
|
applicationName = buildMeta.applicationName, |
|
|
|
|
knockMessage = knockMessage, |
|
|
|
|
eventSink = ::handleEvents |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
@ -159,7 +169,7 @@ class JoinRoomPresenter @AssistedInject constructor(
@@ -159,7 +169,7 @@ class JoinRoomPresenter @AssistedInject constructor(
|
|
|
|
|
|
|
|
|
|
private fun CoroutineScope.knockRoom(knockAction: MutableState<AsyncAction<Unit>>, message: String) = launch { |
|
|
|
|
knockAction.runUpdatingState { |
|
|
|
|
knockRoom(roomId) |
|
|
|
|
knockRoom(roomIdOrAlias, message, serverNames) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -167,15 +177,8 @@ class JoinRoomPresenter @AssistedInject constructor(
@@ -167,15 +177,8 @@ class JoinRoomPresenter @AssistedInject constructor(
|
|
|
|
|
if (requiresConfirmation) { |
|
|
|
|
cancelKnockAction.value = AsyncAction.ConfirmingNoParams |
|
|
|
|
} else { |
|
|
|
|
val room = matrixClient.getRoom(roomId) |
|
|
|
|
if (room == null) { |
|
|
|
|
cancelKnockAction.value = AsyncAction.Failure(RuntimeException()) |
|
|
|
|
} else { |
|
|
|
|
room.use { |
|
|
|
|
cancelKnockAction.runUpdatingState { |
|
|
|
|
room.leave() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
cancelKnockAction.runUpdatingState { |
|
|
|
|
cancelKnockRoom(roomId) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|