Change API MatrixClient.joinRoom(roomId: RoomId): Result<RoomId> to MatrixClient.joinRoom(roomId: RoomId): Result<Unit>
This commit is contained in:
parent
f81f459b84
commit
025c6294c2
9 changed files with 22 additions and 20 deletions
|
|
@ -102,12 +102,14 @@ class AcceptDeclineInvitePresenter @Inject constructor(
|
||||||
|
|
||||||
private fun CoroutineScope.acceptInvite(roomId: RoomId, acceptedAction: MutableState<AsyncAction<RoomId>>) = launch {
|
private fun CoroutineScope.acceptInvite(roomId: RoomId, acceptedAction: MutableState<AsyncAction<RoomId>>) = launch {
|
||||||
acceptedAction.runUpdatingState {
|
acceptedAction.runUpdatingState {
|
||||||
client.joinRoom(roomId).onSuccess {
|
client.joinRoom(roomId)
|
||||||
notificationDrawerManager.clearMembershipNotificationForRoom(client.sessionId, roomId, doRender = true)
|
.onSuccess {
|
||||||
client.getRoom(roomId)?.use { room ->
|
notificationDrawerManager.clearMembershipNotificationForRoom(client.sessionId, roomId, doRender = true)
|
||||||
analyticsService.capture(room.toAnalyticsJoinedRoom(JoinedRoom.Trigger.Invite))
|
client.getRoom(roomId)?.use { room ->
|
||||||
|
analyticsService.capture(room.toAnalyticsJoinedRoom(JoinedRoom.Trigger.Invite))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
.map { roomId }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ class AcceptDeclineInvitePresenterTest {
|
||||||
@Test
|
@Test
|
||||||
fun `present - accepting invite error flow`() = runTest {
|
fun `present - accepting invite error flow`() = runTest {
|
||||||
val joinRoomFailure = lambdaRecorder { roomId: RoomId ->
|
val joinRoomFailure = lambdaRecorder { roomId: RoomId ->
|
||||||
Result.failure<RoomId>(RuntimeException("Failed to join room $roomId"))
|
Result.failure<Unit>(RuntimeException("Failed to join room $roomId"))
|
||||||
}
|
}
|
||||||
val client = FakeMatrixClient().apply {
|
val client = FakeMatrixClient().apply {
|
||||||
joinRoomLambda = joinRoomFailure
|
joinRoomLambda = joinRoomFailure
|
||||||
|
|
@ -197,8 +197,8 @@ class AcceptDeclineInvitePresenterTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `present - accepting invite success flow`() = runTest {
|
fun `present - accepting invite success flow`() = runTest {
|
||||||
val joinRoomSuccess = lambdaRecorder { roomId: RoomId ->
|
val joinRoomSuccess = lambdaRecorder { _: RoomId ->
|
||||||
Result.success(roomId)
|
Result.success(Unit)
|
||||||
}
|
}
|
||||||
val client = FakeMatrixClient().apply {
|
val client = FakeMatrixClient().apply {
|
||||||
joinRoomLambda = joinRoomSuccess
|
joinRoomLambda = joinRoomSuccess
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,7 @@ class RoomDirectoryPresenter @Inject constructor(
|
||||||
private fun CoroutineScope.joinRoom(state: MutableState<AsyncAction<RoomId>>, roomId: RoomId) = launch {
|
private fun CoroutineScope.joinRoom(state: MutableState<AsyncAction<RoomId>>, roomId: RoomId) = launch {
|
||||||
state.runUpdatingState {
|
state.runUpdatingState {
|
||||||
joinRoom(roomId)
|
joinRoom(roomId)
|
||||||
|
.map { roomId }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
interface JoinRoom {
|
interface JoinRoom {
|
||||||
suspend operator fun invoke(roomId: RoomId): Result<RoomId>
|
suspend operator fun invoke(roomId: RoomId): Result<Unit>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ContributesBinding(SessionScope::class)
|
@ContributesBinding(SessionScope::class)
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import io.element.android.features.roomdirectory.impl.root.di.JoinRoom
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
|
|
||||||
class FakeJoinRoom(
|
class FakeJoinRoom(
|
||||||
var lambda: (RoomId) -> Result<RoomId> = { Result.success(it) }
|
var lambda: (RoomId) -> Result<Unit> = { Result.success(Unit) }
|
||||||
) : JoinRoom {
|
) : JoinRoom {
|
||||||
override suspend fun invoke(roomId: RoomId) = lambda(roomId)
|
override suspend fun invoke(roomId: RoomId) = lambda(roomId)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,11 +138,11 @@ import org.junit.Test
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `present - emit join room event`() = runTest {
|
fun `present - emit join room event`() = runTest {
|
||||||
val joinRoomSuccess = lambdaRecorder { roomId: RoomId ->
|
val joinRoomSuccess = lambdaRecorder { _: RoomId ->
|
||||||
Result.success(roomId)
|
Result.success(Unit)
|
||||||
}
|
}
|
||||||
val joinRoomFailure = lambdaRecorder { roomId: RoomId ->
|
val joinRoomFailure = lambdaRecorder { roomId: RoomId ->
|
||||||
Result.failure<RoomId>(RuntimeException("Failed to join room $roomId"))
|
Result.failure<Unit>(RuntimeException("Failed to join room $roomId"))
|
||||||
}
|
}
|
||||||
val fakeJoinRoom = FakeJoinRoom(joinRoomSuccess)
|
val fakeJoinRoom = FakeJoinRoom(joinRoomSuccess)
|
||||||
val presenter = createRoomDirectoryPresenter(joinRoom = fakeJoinRoom)
|
val presenter = createRoomDirectoryPresenter(joinRoom = fakeJoinRoom)
|
||||||
|
|
@ -171,7 +171,7 @@ import org.junit.Test
|
||||||
roomDirectoryService: RoomDirectoryService = FakeRoomDirectoryService(
|
roomDirectoryService: RoomDirectoryService = FakeRoomDirectoryService(
|
||||||
createRoomDirectoryListFactory = { FakeRoomDirectoryList() }
|
createRoomDirectoryListFactory = { FakeRoomDirectoryList() }
|
||||||
),
|
),
|
||||||
joinRoom: JoinRoom = FakeJoinRoom { Result.success(it) },
|
joinRoom: JoinRoom = FakeJoinRoom { Result.success(Unit) },
|
||||||
): RoomDirectoryPresenter {
|
): RoomDirectoryPresenter {
|
||||||
return RoomDirectoryPresenter(
|
return RoomDirectoryPresenter(
|
||||||
dispatchers = testCoroutineDispatchers(),
|
dispatchers = testCoroutineDispatchers(),
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ interface MatrixClient : Closeable {
|
||||||
suspend fun setDisplayName(displayName: String): Result<Unit>
|
suspend fun setDisplayName(displayName: String): Result<Unit>
|
||||||
suspend fun uploadAvatar(mimeType: String, data: ByteArray): Result<Unit>
|
suspend fun uploadAvatar(mimeType: String, data: ByteArray): Result<Unit>
|
||||||
suspend fun removeAvatar(): Result<Unit>
|
suspend fun removeAvatar(): Result<Unit>
|
||||||
suspend fun joinRoom(roomId: RoomId): Result<RoomId>
|
suspend fun joinRoom(roomId: RoomId): Result<Unit>
|
||||||
fun syncService(): SyncService
|
fun syncService(): SyncService
|
||||||
fun sessionVerificationService(): SessionVerificationService
|
fun sessionVerificationService(): SessionVerificationService
|
||||||
fun pushersService(): PushersService
|
fun pushersService(): PushersService
|
||||||
|
|
|
||||||
|
|
@ -440,7 +440,7 @@ class RustMatrixClient(
|
||||||
runCatching { client.removeAvatar() }
|
runCatching { client.removeAvatar() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun joinRoom(roomId: RoomId): Result<RoomId> = withContext(sessionDispatcher) {
|
override suspend fun joinRoom(roomId: RoomId): Result<Unit> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
client.joinRoomById(roomId.value).destroy()
|
client.joinRoomById(roomId.value).destroy()
|
||||||
try {
|
try {
|
||||||
|
|
@ -448,7 +448,6 @@ class RustMatrixClient(
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "Timeout waiting for the room to be available in the room list")
|
Timber.e(e, "Timeout waiting for the room to be available in the room list")
|
||||||
}
|
}
|
||||||
roomId
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,8 +103,8 @@ class FakeMatrixClient(
|
||||||
private var setDisplayNameResult: Result<Unit> = Result.success(Unit)
|
private var setDisplayNameResult: Result<Unit> = Result.success(Unit)
|
||||||
private var uploadAvatarResult: Result<Unit> = Result.success(Unit)
|
private var uploadAvatarResult: Result<Unit> = Result.success(Unit)
|
||||||
private var removeAvatarResult: Result<Unit> = Result.success(Unit)
|
private var removeAvatarResult: Result<Unit> = Result.success(Unit)
|
||||||
var joinRoomLambda: (RoomId) -> Result<RoomId> = {
|
var joinRoomLambda: (RoomId) -> Result<Unit> = {
|
||||||
Result.success(it)
|
Result.success(Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
var getRoomInfoFlowLambda = { _: RoomId ->
|
var getRoomInfoFlowLambda = { _: RoomId ->
|
||||||
|
|
@ -197,7 +197,7 @@ class FakeMatrixClient(
|
||||||
return removeAvatarResult
|
return removeAvatarResult
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun joinRoom(roomId: RoomId): Result<RoomId> = joinRoomLambda(roomId)
|
override suspend fun joinRoom(roomId: RoomId): Result<Unit> = joinRoomLambda(roomId)
|
||||||
|
|
||||||
override fun sessionVerificationService(): SessionVerificationService = sessionVerificationService
|
override fun sessionVerificationService(): SessionVerificationService = sessionVerificationService
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue