Add /myroomnick slash command

This commit is contained in:
bxdxnn
2026-05-26 07:36:57 +00:00
parent f447560665
commit 51aa8208e0
8 changed files with 92 additions and 16 deletions
@@ -109,7 +109,7 @@ enum class Command(
parameters = "<display-name>",
description = R.string.slash_command_description_nick_for_room,
isAllowedInThread = false,
isSupported = false,
isSupported = true,
),
ROOM_AVATAR(
command = "/roomavatar",
@@ -47,7 +47,7 @@ class CommandExecutor(
is SlashCommand.ChangeAvatar -> changeAvatar()
is SlashCommand.ChangeAvatarForRoom -> changeAvatarForRoom()
is SlashCommand.ChangeDisplayName -> changeDisplayName(slashCommand)
is SlashCommand.ChangeDisplayNameForRoom -> changeDisplayNameForRoom()
is SlashCommand.ChangeDisplayNameForRoom -> changeDisplayNameForRoom(slashCommand)
is SlashCommand.ChangeRoomAvatar -> changeRoomAvatar()
is SlashCommand.ChangeRoomName -> changeRoomName(slashCommand)
is SlashCommand.ChangeTopic -> changeTopic(slashCommand)
@@ -171,8 +171,8 @@ class CommandExecutor(
return Result.failure(Exception("Not yet implemented"))
}
private fun changeDisplayNameForRoom(): Result<Unit> {
return Result.failure(Exception("Not yet implemented"))
private suspend fun changeDisplayNameForRoom(slashCommand: SlashCommand.ChangeDisplayNameForRoom): Result<Unit> {
return joinedRoom.setOwnMemberDisplayName(slashCommand.displayName)
}
private suspend fun changeDisplayName(slashCommand: SlashCommand.ChangeDisplayName): Result<Unit> {
@@ -185,10 +185,18 @@ class CommandExecutorTest {
}
@Test
fun `change display name for room is not supported`() = runTest {
val sut = createCommandExecutor()
val res = sut.proceedAdmin(SlashCommand.ChangeDisplayNameForRoom(A_USER_NAME))
assertThat(res.isFailure).isTrue()
fun `change display name for room delegates to joined room`() = runTest {
var capturedDisplayName: String? = null
val joinedRoom = FakeJoinedRoom(
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