Rename val

This commit is contained in:
Benoit Marty 2022-04-14 15:50:58 +02:00
parent a712ffee68
commit 8da5016767
1 changed files with 42 additions and 42 deletions

View File

@ -195,7 +195,7 @@ class MessageComposerViewModel @AssistedInject constructor(
} }
when (state.sendMode) { when (state.sendMode) {
is SendMode.Regular -> { is SendMode.Regular -> {
when (val slashCommandResult = commandParser.parseSlashCommand( when (val parsedCommand = commandParser.parseSlashCommand(
textMessage = action.text, textMessage = action.text,
isInThreadTimeline = state.isInThreadTimeline())) { isInThreadTimeline = state.isInThreadTimeline())) {
is ParsedCommand.ErrorNotACommand -> { is ParsedCommand.ErrorNotACommand -> {
@ -213,93 +213,93 @@ class MessageComposerViewModel @AssistedInject constructor(
popDraft() popDraft()
} }
is ParsedCommand.ErrorSyntax -> { is ParsedCommand.ErrorSyntax -> {
_viewEvents.post(MessageComposerViewEvents.SlashCommandError(slashCommandResult.command)) _viewEvents.post(MessageComposerViewEvents.SlashCommandError(parsedCommand.command))
} }
is ParsedCommand.ErrorEmptySlashCommand -> { is ParsedCommand.ErrorEmptySlashCommand -> {
_viewEvents.post(MessageComposerViewEvents.SlashCommandUnknown("/")) _viewEvents.post(MessageComposerViewEvents.SlashCommandUnknown("/"))
} }
is ParsedCommand.ErrorUnknownSlashCommand -> { is ParsedCommand.ErrorUnknownSlashCommand -> {
_viewEvents.post(MessageComposerViewEvents.SlashCommandUnknown(slashCommandResult.slashCommand)) _viewEvents.post(MessageComposerViewEvents.SlashCommandUnknown(parsedCommand.slashCommand))
} }
is ParsedCommand.ErrorCommandNotSupportedInThreads -> { is ParsedCommand.ErrorCommandNotSupportedInThreads -> {
_viewEvents.post(MessageComposerViewEvents.SlashCommandNotSupportedInThreads(slashCommandResult.command)) _viewEvents.post(MessageComposerViewEvents.SlashCommandNotSupportedInThreads(parsedCommand.command))
} }
is ParsedCommand.SendPlainText -> { is ParsedCommand.SendPlainText -> {
// Send the text message to the room, without markdown // Send the text message to the room, without markdown
if (state.rootThreadEventId != null) { if (state.rootThreadEventId != null) {
room.replyInThread( room.replyInThread(
rootThreadEventId = state.rootThreadEventId, rootThreadEventId = state.rootThreadEventId,
replyInThreadText = slashCommandResult.message, replyInThreadText = parsedCommand.message,
autoMarkdown = false) autoMarkdown = false)
} else { } else {
room.sendTextMessage(slashCommandResult.message, autoMarkdown = false) room.sendTextMessage(parsedCommand.message, autoMarkdown = false)
} }
_viewEvents.post(MessageComposerViewEvents.MessageSent) _viewEvents.post(MessageComposerViewEvents.MessageSent)
popDraft() popDraft()
} }
is ParsedCommand.ChangeRoomName -> { is ParsedCommand.ChangeRoomName -> {
handleChangeRoomNameSlashCommand(slashCommandResult) handleChangeRoomNameSlashCommand(parsedCommand)
} }
is ParsedCommand.Invite -> { is ParsedCommand.Invite -> {
handleInviteSlashCommand(slashCommandResult) handleInviteSlashCommand(parsedCommand)
} }
is ParsedCommand.Invite3Pid -> { is ParsedCommand.Invite3Pid -> {
handleInvite3pidSlashCommand(slashCommandResult) handleInvite3pidSlashCommand(parsedCommand)
} }
is ParsedCommand.SetUserPowerLevel -> { is ParsedCommand.SetUserPowerLevel -> {
handleSetUserPowerLevel(slashCommandResult) handleSetUserPowerLevel(parsedCommand)
} }
is ParsedCommand.ClearScalarToken -> { is ParsedCommand.ClearScalarToken -> {
// TODO // TODO
_viewEvents.post(MessageComposerViewEvents.SlashCommandNotImplemented) _viewEvents.post(MessageComposerViewEvents.SlashCommandNotImplemented)
} }
is ParsedCommand.SetMarkdown -> { is ParsedCommand.SetMarkdown -> {
vectorPreferences.setMarkdownEnabled(slashCommandResult.enable) vectorPreferences.setMarkdownEnabled(parsedCommand.enable)
_viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk( _viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk(
if (slashCommandResult.enable) R.string.markdown_has_been_enabled else R.string.markdown_has_been_disabled)) if (parsedCommand.enable) R.string.markdown_has_been_enabled else R.string.markdown_has_been_disabled))
popDraft() popDraft()
} }
is ParsedCommand.BanUser -> { is ParsedCommand.BanUser -> {
handleBanSlashCommand(slashCommandResult) handleBanSlashCommand(parsedCommand)
} }
is ParsedCommand.UnbanUser -> { is ParsedCommand.UnbanUser -> {
handleUnbanSlashCommand(slashCommandResult) handleUnbanSlashCommand(parsedCommand)
} }
is ParsedCommand.IgnoreUser -> { is ParsedCommand.IgnoreUser -> {
handleIgnoreSlashCommand(slashCommandResult) handleIgnoreSlashCommand(parsedCommand)
} }
is ParsedCommand.UnignoreUser -> { is ParsedCommand.UnignoreUser -> {
handleUnignoreSlashCommand(slashCommandResult) handleUnignoreSlashCommand(parsedCommand)
} }
is ParsedCommand.RemoveUser -> { is ParsedCommand.RemoveUser -> {
handleRemoveSlashCommand(slashCommandResult) handleRemoveSlashCommand(parsedCommand)
} }
is ParsedCommand.JoinRoom -> { is ParsedCommand.JoinRoom -> {
handleJoinToAnotherRoomSlashCommand(slashCommandResult) handleJoinToAnotherRoomSlashCommand(parsedCommand)
popDraft() popDraft()
} }
is ParsedCommand.PartRoom -> { is ParsedCommand.PartRoom -> {
handlePartSlashCommand(slashCommandResult) handlePartSlashCommand(parsedCommand)
} }
is ParsedCommand.SendEmote -> { is ParsedCommand.SendEmote -> {
if (state.rootThreadEventId != null) { if (state.rootThreadEventId != null) {
room.replyInThread( room.replyInThread(
rootThreadEventId = state.rootThreadEventId, rootThreadEventId = state.rootThreadEventId,
replyInThreadText = slashCommandResult.message, replyInThreadText = parsedCommand.message,
msgType = MessageType.MSGTYPE_EMOTE, msgType = MessageType.MSGTYPE_EMOTE,
autoMarkdown = action.autoMarkdown) autoMarkdown = action.autoMarkdown)
} else { } else {
room.sendTextMessage(slashCommandResult.message, msgType = MessageType.MSGTYPE_EMOTE, autoMarkdown = action.autoMarkdown) room.sendTextMessage(parsedCommand.message, msgType = MessageType.MSGTYPE_EMOTE, autoMarkdown = action.autoMarkdown)
} }
_viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk()) _viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk())
popDraft() popDraft()
} }
is ParsedCommand.SendRainbow -> { is ParsedCommand.SendRainbow -> {
val message = slashCommandResult.message.toString() val message = parsedCommand.message.toString()
if (state.rootThreadEventId != null) { if (state.rootThreadEventId != null) {
room.replyInThread( room.replyInThread(
rootThreadEventId = state.rootThreadEventId, rootThreadEventId = state.rootThreadEventId,
replyInThreadText = slashCommandResult.message, replyInThreadText = parsedCommand.message,
formattedText = rainbowGenerator.generate(message)) formattedText = rainbowGenerator.generate(message))
} else { } else {
room.sendFormattedTextMessage(message, rainbowGenerator.generate(message)) room.sendFormattedTextMessage(message, rainbowGenerator.generate(message))
@ -308,11 +308,11 @@ class MessageComposerViewModel @AssistedInject constructor(
popDraft() popDraft()
} }
is ParsedCommand.SendRainbowEmote -> { is ParsedCommand.SendRainbowEmote -> {
val message = slashCommandResult.message.toString() val message = parsedCommand.message.toString()
if (state.rootThreadEventId != null) { if (state.rootThreadEventId != null) {
room.replyInThread( room.replyInThread(
rootThreadEventId = state.rootThreadEventId, rootThreadEventId = state.rootThreadEventId,
replyInThreadText = slashCommandResult.message, replyInThreadText = parsedCommand.message,
msgType = MessageType.MSGTYPE_EMOTE, msgType = MessageType.MSGTYPE_EMOTE,
formattedText = rainbowGenerator.generate(message)) formattedText = rainbowGenerator.generate(message))
} else { } else {
@ -323,8 +323,8 @@ class MessageComposerViewModel @AssistedInject constructor(
popDraft() popDraft()
} }
is ParsedCommand.SendSpoiler -> { is ParsedCommand.SendSpoiler -> {
val text = "[${stringProvider.getString(R.string.spoiler)}](${slashCommandResult.message})" val text = "[${stringProvider.getString(R.string.spoiler)}](${parsedCommand.message})"
val formattedText = "<span data-mx-spoiler>${slashCommandResult.message}</span>" val formattedText = "<span data-mx-spoiler>${parsedCommand.message}</span>"
if (state.rootThreadEventId != null) { if (state.rootThreadEventId != null) {
room.replyInThread( room.replyInThread(
rootThreadEventId = state.rootThreadEventId, rootThreadEventId = state.rootThreadEventId,
@ -339,38 +339,38 @@ class MessageComposerViewModel @AssistedInject constructor(
popDraft() popDraft()
} }
is ParsedCommand.SendShrug -> { is ParsedCommand.SendShrug -> {
sendPrefixedMessage("¯\\_(ツ)_/¯", slashCommandResult.message, state.rootThreadEventId) sendPrefixedMessage("¯\\_(ツ)_/¯", parsedCommand.message, state.rootThreadEventId)
_viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk()) _viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk())
popDraft() popDraft()
} }
is ParsedCommand.SendLenny -> { is ParsedCommand.SendLenny -> {
sendPrefixedMessage("( ͡° ͜ʖ ͡°)", slashCommandResult.message, state.rootThreadEventId) sendPrefixedMessage("( ͡° ͜ʖ ͡°)", parsedCommand.message, state.rootThreadEventId)
_viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk()) _viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk())
popDraft() popDraft()
} }
is ParsedCommand.SendChatEffect -> { is ParsedCommand.SendChatEffect -> {
sendChatEffect(slashCommandResult) sendChatEffect(parsedCommand)
_viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk()) _viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk())
popDraft() popDraft()
} }
is ParsedCommand.ChangeTopic -> { is ParsedCommand.ChangeTopic -> {
handleChangeTopicSlashCommand(slashCommandResult) handleChangeTopicSlashCommand(parsedCommand)
} }
is ParsedCommand.ChangeDisplayName -> { is ParsedCommand.ChangeDisplayName -> {
handleChangeDisplayNameSlashCommand(slashCommandResult) handleChangeDisplayNameSlashCommand(parsedCommand)
} }
is ParsedCommand.ChangeDisplayNameForRoom -> { is ParsedCommand.ChangeDisplayNameForRoom -> {
handleChangeDisplayNameForRoomSlashCommand(slashCommandResult) handleChangeDisplayNameForRoomSlashCommand(parsedCommand)
} }
is ParsedCommand.ChangeRoomAvatar -> { is ParsedCommand.ChangeRoomAvatar -> {
handleChangeRoomAvatarSlashCommand(slashCommandResult) handleChangeRoomAvatarSlashCommand(parsedCommand)
} }
is ParsedCommand.ChangeAvatarForRoom -> { is ParsedCommand.ChangeAvatarForRoom -> {
handleChangeAvatarForRoomSlashCommand(slashCommandResult) handleChangeAvatarForRoomSlashCommand(parsedCommand)
} }
is ParsedCommand.ShowUser -> { is ParsedCommand.ShowUser -> {
_viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk()) _viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk())
handleWhoisSlashCommand(slashCommandResult) handleWhoisSlashCommand(parsedCommand)
popDraft() popDraft()
} }
is ParsedCommand.DiscardSession -> { is ParsedCommand.DiscardSession -> {
@ -391,8 +391,8 @@ class MessageComposerViewModel @AssistedInject constructor(
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
try { try {
val params = CreateSpaceParams().apply { val params = CreateSpaceParams().apply {
name = slashCommandResult.name name = parsedCommand.name
invitedUserIds.addAll(slashCommandResult.invitees) invitedUserIds.addAll(parsedCommand.invitees)
} }
val spaceId = session.spaceService().createSpace(params) val spaceId = session.spaceService().createSpace(params)
session.spaceService().getSpace(spaceId) session.spaceService().getSpace(spaceId)
@ -414,7 +414,7 @@ class MessageComposerViewModel @AssistedInject constructor(
_viewEvents.post(MessageComposerViewEvents.SlashCommandLoading) _viewEvents.post(MessageComposerViewEvents.SlashCommandLoading)
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
try { try {
session.spaceService().getSpace(slashCommandResult.spaceId) session.spaceService().getSpace(parsedCommand.spaceId)
?.addChildren( ?.addChildren(
room.roomId, room.roomId,
null, null,
@ -433,7 +433,7 @@ class MessageComposerViewModel @AssistedInject constructor(
_viewEvents.post(MessageComposerViewEvents.SlashCommandLoading) _viewEvents.post(MessageComposerViewEvents.SlashCommandLoading)
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
try { try {
session.spaceService().joinSpace(slashCommandResult.spaceIdOrAlias) session.spaceService().joinSpace(parsedCommand.spaceIdOrAlias)
popDraft() popDraft()
_viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk()) _viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk())
} catch (failure: Throwable) { } catch (failure: Throwable) {
@ -445,7 +445,7 @@ class MessageComposerViewModel @AssistedInject constructor(
is ParsedCommand.LeaveRoom -> { is ParsedCommand.LeaveRoom -> {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
try { try {
session.leaveRoom(slashCommandResult.roomId) session.leaveRoom(parsedCommand.roomId)
popDraft() popDraft()
_viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk()) _viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk())
} catch (failure: Throwable) { } catch (failure: Throwable) {
@ -457,7 +457,7 @@ class MessageComposerViewModel @AssistedInject constructor(
is ParsedCommand.UpgradeRoom -> { is ParsedCommand.UpgradeRoom -> {
_viewEvents.post( _viewEvents.post(
MessageComposerViewEvents.ShowRoomUpgradeDialog( MessageComposerViewEvents.ShowRoomUpgradeDialog(
slashCommandResult.newVersion, parsedCommand.newVersion,
room.roomSummary()?.isPublic ?: false room.roomSummary()?.isPublic ?: false
) )
) )