mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
Merge pull request #6865 from bxdxnn/feat/myroomnick
Add `/myroomnick` slash command to change your display name in the current room
This commit is contained in:
+7
@@ -212,4 +212,11 @@ interface JoinedRoom : BaseRoom {
|
|||||||
* @return Result indicating success or failure.
|
* @return Result indicating success or failure.
|
||||||
*/
|
*/
|
||||||
suspend fun sendLiveLocation(geoUri: String): Result<Unit>
|
suspend fun sendLiveLocation(geoUri: String): Result<Unit>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the display name of the current user within this room.
|
||||||
|
* This is different from the global setDisplayName which updates
|
||||||
|
* the user's display name across all of their rooms.
|
||||||
|
*/
|
||||||
|
suspend fun setOwnMemberDisplayName(displayName: String): Result<Unit>
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -548,6 +548,12 @@ class JoinedRustRoom(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun setOwnMemberDisplayName(displayName: String): Result<Unit> = withContext(roomDispatcher) {
|
||||||
|
runCatchingExceptions {
|
||||||
|
innerRoom.setOwnMemberDisplayName(displayName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun close() = destroy()
|
override fun close() = destroy()
|
||||||
|
|
||||||
override fun destroy() {
|
override fun destroy() {
|
||||||
|
|||||||
+5
@@ -92,6 +92,7 @@ class FakeJoinedRoom(
|
|||||||
private val startLiveLocationShareResult: (Long) -> Result<EventId> = { lambdaError() },
|
private val startLiveLocationShareResult: (Long) -> Result<EventId> = { lambdaError() },
|
||||||
private val stopLiveLocationShareResult: () -> Result<Unit> = { lambdaError() },
|
private val stopLiveLocationShareResult: () -> Result<Unit> = { lambdaError() },
|
||||||
private val sendLiveLocationResult: (String) -> Result<Unit> = { lambdaError() },
|
private val sendLiveLocationResult: (String) -> Result<Unit> = { lambdaError() },
|
||||||
|
private val setOwnMemberDisplayNameResult: (String) -> Result<Unit> = { lambdaError() },
|
||||||
) : JoinedRoom, BaseRoom by baseRoom {
|
) : JoinedRoom, BaseRoom by baseRoom {
|
||||||
private val sendQueueUpdates = MutableSharedFlow<SendQueueUpdate>(extraBufferCapacity = 10)
|
private val sendQueueUpdates = MutableSharedFlow<SendQueueUpdate>(extraBufferCapacity = 10)
|
||||||
|
|
||||||
@@ -255,6 +256,10 @@ class FakeJoinedRoom(
|
|||||||
sendLiveLocationResult(geoUri)
|
sendLiveLocationResult(geoUri)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun setOwnMemberDisplayName(displayName: String): Result<Unit> = simulateLongTask {
|
||||||
|
setOwnMemberDisplayNameResult(displayName)
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun simulateSendMediaProgress(progressCallback: ProgressCallback?) {
|
private suspend fun simulateSendMediaProgress(progressCallback: ProgressCallback?) {
|
||||||
progressCallbackValues.forEach { (current, total) ->
|
progressCallbackValues.forEach { (current, total) ->
|
||||||
progressCallback?.onProgress(current, total)
|
progressCallback?.onProgress(current, total)
|
||||||
|
|||||||
+1
-1
@@ -109,7 +109,7 @@ enum class Command(
|
|||||||
parameters = "<display-name>",
|
parameters = "<display-name>",
|
||||||
description = R.string.slash_command_description_nick_for_room,
|
description = R.string.slash_command_description_nick_for_room,
|
||||||
isAllowedInThread = false,
|
isAllowedInThread = false,
|
||||||
isSupported = false,
|
isSupported = true,
|
||||||
),
|
),
|
||||||
ROOM_AVATAR(
|
ROOM_AVATAR(
|
||||||
command = "/roomavatar",
|
command = "/roomavatar",
|
||||||
|
|||||||
+3
-3
@@ -47,7 +47,7 @@ class CommandExecutor(
|
|||||||
is SlashCommand.ChangeAvatar -> changeAvatar()
|
is SlashCommand.ChangeAvatar -> changeAvatar()
|
||||||
is SlashCommand.ChangeAvatarForRoom -> changeAvatarForRoom()
|
is SlashCommand.ChangeAvatarForRoom -> changeAvatarForRoom()
|
||||||
is SlashCommand.ChangeDisplayName -> changeDisplayName(slashCommand)
|
is SlashCommand.ChangeDisplayName -> changeDisplayName(slashCommand)
|
||||||
is SlashCommand.ChangeDisplayNameForRoom -> changeDisplayNameForRoom()
|
is SlashCommand.ChangeDisplayNameForRoom -> changeDisplayNameForRoom(slashCommand)
|
||||||
is SlashCommand.ChangeRoomAvatar -> changeRoomAvatar()
|
is SlashCommand.ChangeRoomAvatar -> changeRoomAvatar()
|
||||||
is SlashCommand.ChangeRoomName -> changeRoomName(slashCommand)
|
is SlashCommand.ChangeRoomName -> changeRoomName(slashCommand)
|
||||||
is SlashCommand.ChangeTopic -> changeTopic(slashCommand)
|
is SlashCommand.ChangeTopic -> changeTopic(slashCommand)
|
||||||
@@ -171,8 +171,8 @@ class CommandExecutor(
|
|||||||
return Result.failure(Exception("Not yet implemented"))
|
return Result.failure(Exception("Not yet implemented"))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun changeDisplayNameForRoom(): Result<Unit> {
|
private suspend fun changeDisplayNameForRoom(slashCommand: SlashCommand.ChangeDisplayNameForRoom): Result<Unit> {
|
||||||
return Result.failure(Exception("Not yet implemented"))
|
return joinedRoom.setOwnMemberDisplayName(slashCommand.displayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun changeDisplayName(slashCommand: SlashCommand.ChangeDisplayName): Result<Unit> {
|
private suspend fun changeDisplayName(slashCommand: SlashCommand.ChangeDisplayName): Result<Unit> {
|
||||||
|
|||||||
+12
-5
@@ -14,7 +14,6 @@ import io.element.android.libraries.matrix.api.timeline.MsgType
|
|||||||
import io.element.android.libraries.matrix.test.AN_AVATAR_URL
|
import io.element.android.libraries.matrix.test.AN_AVATAR_URL
|
||||||
import io.element.android.libraries.matrix.test.A_MESSAGE
|
import io.element.android.libraries.matrix.test.A_MESSAGE
|
||||||
import io.element.android.libraries.matrix.test.A_USER_ID
|
import io.element.android.libraries.matrix.test.A_USER_ID
|
||||||
import io.element.android.libraries.matrix.test.A_USER_NAME
|
|
||||||
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||||
import io.element.android.libraries.matrix.test.room.FakeBaseRoom
|
import io.element.android.libraries.matrix.test.room.FakeBaseRoom
|
||||||
import io.element.android.libraries.matrix.test.room.FakeJoinedRoom
|
import io.element.android.libraries.matrix.test.room.FakeJoinedRoom
|
||||||
@@ -185,10 +184,18 @@ class CommandExecutorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `change display name for room is not supported`() = runTest {
|
fun `change display name for room delegates to joined room`() = runTest {
|
||||||
val sut = createCommandExecutor()
|
var capturedDisplayName: String? = null
|
||||||
val res = sut.proceedAdmin(SlashCommand.ChangeDisplayNameForRoom(A_USER_NAME))
|
val joinedRoom = FakeJoinedRoom(
|
||||||
assertThat(res.isFailure).isTrue()
|
setOwnMemberDisplayNameResult = { displayName ->
|
||||||
|
capturedDisplayName = displayName
|
||||||
|
Result.success(Unit)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
val sut = createCommandExecutor(joinedRoom = joinedRoom)
|
||||||
|
val res = sut.proceedAdmin(SlashCommand.ChangeDisplayNameForRoom("room nick"))
|
||||||
|
assertThat(res.isSuccess).isTrue()
|
||||||
|
assertThat(capturedDisplayName).isEqualTo("room nick")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user