mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Add /snow command
This commit is contained in:
parent
6957768567
commit
487ef870f9
7 changed files with 20 additions and 6 deletions
|
@ -45,7 +45,8 @@ enum class Command(val command: String, val parameters: String, @StringRes val d
|
|||
SHRUG("/shrug", "<message>", R.string.command_description_shrug),
|
||||
PLAIN("/plain", "<message>", R.string.command_description_plain),
|
||||
DISCARD_SESSION("/discardsession", "", R.string.command_description_discard_session),
|
||||
CONFETTI("/confetti", "<message>", R.string.command_confetti);
|
||||
CONFETTI("/confetti", "<message>", R.string.command_confetti),
|
||||
SNOW("/snow", "<message>", R.string.command_snow);
|
||||
|
||||
val length
|
||||
get() = command.length + 1
|
||||
|
|
|
@ -18,6 +18,7 @@ package im.vector.app.features.command
|
|||
|
||||
import im.vector.app.core.extensions.isEmail
|
||||
import im.vector.app.core.extensions.isMsisdn
|
||||
import im.vector.app.features.home.room.detail.ChatEffect
|
||||
import org.matrix.android.sdk.api.MatrixPatterns
|
||||
import org.matrix.android.sdk.api.session.identity.ThreePid
|
||||
import timber.log.Timber
|
||||
|
@ -293,7 +294,11 @@ object CommandParser {
|
|||
}
|
||||
Command.CONFETTI.command -> {
|
||||
val message = textMessage.substring(Command.CONFETTI.command.length).trim()
|
||||
ParsedCommand.Confetti(message)
|
||||
ParsedCommand.SendChatEffect(ChatEffect.CONFETTI, message)
|
||||
}
|
||||
Command.SNOW.command -> {
|
||||
val message = textMessage.substring(Command.SNOW.command.length).trim()
|
||||
ParsedCommand.SendChatEffect(ChatEffect.SNOW, message)
|
||||
}
|
||||
else -> {
|
||||
// Unknown command
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package im.vector.app.features.command
|
||||
|
||||
import im.vector.app.features.home.room.detail.ChatEffect
|
||||
import org.matrix.android.sdk.api.session.identity.ThreePid
|
||||
|
||||
/**
|
||||
|
@ -55,5 +56,5 @@ sealed class ParsedCommand {
|
|||
class SendShrug(val message: CharSequence) : ParsedCommand()
|
||||
class SendPoll(val question: String, val options: List<String>) : ParsedCommand()
|
||||
object DiscardSession : ParsedCommand()
|
||||
class Confetti(val message: String) : ParsedCommand()
|
||||
class SendChatEffect(val chatEffect: ChatEffect, val message: String) : ParsedCommand()
|
||||
}
|
||||
|
|
|
@ -29,6 +29,13 @@ enum class ChatEffect {
|
|||
SNOW
|
||||
}
|
||||
|
||||
fun ChatEffect.toMessageType(): String {
|
||||
return when (this) {
|
||||
ChatEffect.CONFETTI -> MessageType.MSGTYPE_CONFETTI
|
||||
ChatEffect.SNOW -> MessageType.MSGTYPE_SNOW
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple chat effect manager helper class
|
||||
* Used by the view model to know if an event that become visible should trigger a chat effect.
|
||||
|
|
|
@ -56,7 +56,6 @@ import androidx.recyclerview.widget.ItemTouchHelper
|
|||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.transition.TransitionManager
|
||||
import butterknife.BindView
|
||||
import com.airbnb.epoxy.EpoxyModel
|
||||
import com.airbnb.epoxy.OnModelBuildFinishedListener
|
||||
import com.airbnb.epoxy.addGlidePreloader
|
||||
|
|
|
@ -715,8 +715,8 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
_viewEvents.post(RoomDetailViewEvents.SlashCommandHandled())
|
||||
popDraft()
|
||||
}
|
||||
is ParsedCommand.Confetti -> {
|
||||
room.sendTextMessage(slashCommandResult.message, MessageType.MSGTYPE_CONFETTI)
|
||||
is ParsedCommand.SendChatEffect -> {
|
||||
room.sendTextMessage(slashCommandResult.message, slashCommandResult.chatEffect.toMessageType())
|
||||
_viewEvents.post(RoomDetailViewEvents.SlashCommandHandled())
|
||||
popDraft()
|
||||
}
|
||||
|
|
|
@ -2571,6 +2571,7 @@
|
|||
</plurals>
|
||||
|
||||
<string name="command_confetti">Sends the given message with confetti</string>
|
||||
<string name="command_snow">Sends the given message with snow</string>
|
||||
|
||||
<string name="unencrypted">Unencrypted</string>
|
||||
<string name="encrypted_unverified">Encrypted by an unverified device</string>
|
||||
|
|
Loading…
Reference in a new issue