Remove poll command.
This commit is contained in:
parent
f9f4317d68
commit
ac299d8c06
@ -84,10 +84,10 @@ interface SendService {
|
||||
/**
|
||||
* Send a poll to the room.
|
||||
* @param question the question
|
||||
* @param options list of (label, value)
|
||||
* @param options list of options
|
||||
* @return a [Cancelable]
|
||||
*/
|
||||
fun sendPoll(question: String, options: List<OptionItem>): Cancelable
|
||||
fun sendPoll(question: String, options: List<String>): Cancelable
|
||||
|
||||
/**
|
||||
* Method to send a poll response.
|
||||
|
@ -98,7 +98,7 @@ internal class DefaultSendService @AssistedInject constructor(
|
||||
.let { sendEvent(it) }
|
||||
}
|
||||
|
||||
override fun sendPoll(question: String, options: List<OptionItem>): Cancelable {
|
||||
override fun sendPoll(question: String, options: List<String>): Cancelable {
|
||||
return localEchoEventFactory.createPollEvent(roomId, question, options)
|
||||
.also { createLocalEcho(it) }
|
||||
.let { sendEvent(it) }
|
||||
|
@ -39,12 +39,16 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageFileContent
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageFormat
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageImageContent
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageOptionsContent
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessagePollResponseContent
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageTextContent
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageType
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageVideoContent
|
||||
import org.matrix.android.sdk.api.session.room.model.message.OPTION_TYPE_POLL
|
||||
import org.matrix.android.sdk.api.session.room.model.message.OptionItem
|
||||
import org.matrix.android.sdk.api.session.room.model.message.PollAnswer
|
||||
import org.matrix.android.sdk.api.session.room.model.message.PollCreationInfo
|
||||
import org.matrix.android.sdk.api.session.room.model.message.PollQuestion
|
||||
import org.matrix.android.sdk.api.session.room.model.message.ThumbnailInfo
|
||||
import org.matrix.android.sdk.api.session.room.model.message.VideoInfo
|
||||
import org.matrix.android.sdk.api.session.room.model.relation.ReactionContent
|
||||
@ -138,24 +142,29 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||
|
||||
fun createPollEvent(roomId: String,
|
||||
question: String,
|
||||
options: List<OptionItem>): Event {
|
||||
val compatLabel = buildString {
|
||||
append("[Poll] ")
|
||||
append(question)
|
||||
options.forEach {
|
||||
append("\n")
|
||||
append(it.value)
|
||||
}
|
||||
}
|
||||
return createMessageEvent(
|
||||
roomId,
|
||||
MessageOptionsContent(
|
||||
body = compatLabel,
|
||||
label = question,
|
||||
optionType = OPTION_TYPE_POLL,
|
||||
options = options.toList()
|
||||
options: List<String>): Event {
|
||||
val content = MessagePollContent(
|
||||
pollCreationInfo = PollCreationInfo(
|
||||
question = PollQuestion(
|
||||
question = question
|
||||
),
|
||||
answers = options.mapIndexed { index, option ->
|
||||
PollAnswer(
|
||||
id = index.toString(),
|
||||
answer = option
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
val localId = LocalEcho.createLocalEchoId()
|
||||
return Event(
|
||||
roomId = roomId,
|
||||
originServerTs = dummyOriginServerTs(),
|
||||
senderId = userId,
|
||||
eventId = localId,
|
||||
type = EventType.POLL_START,
|
||||
content = content.toContent(),
|
||||
unsignedData = UnsignedData(age = null, transactionId = localId))
|
||||
}
|
||||
|
||||
fun createReplaceTextOfReply(roomId: String,
|
||||
|
@ -47,7 +47,6 @@ enum class Command(val command: String, val parameters: String, @StringRes val d
|
||||
RAINBOW_EMOTE("/rainbowme", "<message>", R.string.command_description_rainbow_emote, false),
|
||||
CLEAR_SCALAR_TOKEN("/clear_scalar_token", "", R.string.command_description_clear_scalar_token, false),
|
||||
SPOILER("/spoiler", "<message>", R.string.command_description_spoiler, false),
|
||||
POLL("/poll", "Question | Option 1 | Option 2 ...", R.string.command_description_poll, false),
|
||||
SHRUG("/shrug", "<message>", R.string.command_description_shrug, false),
|
||||
LENNY("/lenny", "<message>", R.string.command_description_lenny, false),
|
||||
PLAIN("/plain", "<message>", R.string.command_description_plain, false),
|
||||
|
@ -345,15 +345,6 @@ object CommandParser {
|
||||
|
||||
ParsedCommand.SendLenny(message)
|
||||
}
|
||||
Command.POLL.command -> {
|
||||
val rawCommand = textMessage.substring(Command.POLL.command.length).trim()
|
||||
val split = rawCommand.split("|").map { it.trim() }
|
||||
if (split.size > 2) {
|
||||
ParsedCommand.SendPoll(split[0], split.subList(1, split.size))
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.POLL)
|
||||
}
|
||||
}
|
||||
Command.DISCARD_SESSION.command -> {
|
||||
ParsedCommand.DiscardSession
|
||||
}
|
||||
|
@ -61,7 +61,6 @@ sealed class ParsedCommand {
|
||||
class SendSpoiler(val message: String) : ParsedCommand()
|
||||
class SendShrug(val message: CharSequence) : ParsedCommand()
|
||||
class SendLenny(val message: CharSequence) : ParsedCommand()
|
||||
class SendPoll(val question: String, val options: List<String>) : ParsedCommand()
|
||||
object DiscardSession : ParsedCommand()
|
||||
class ShowUser(val userId: String) : ParsedCommand()
|
||||
class SendChatEffect(val chatEffect: ChatEffect, val message: String) : ParsedCommand()
|
||||
|
@ -260,11 +260,6 @@ class TextComposerViewModel @AssistedInject constructor(
|
||||
_viewEvents.post(TextComposerViewEvents.SlashCommandResultOk())
|
||||
popDraft()
|
||||
}
|
||||
is ParsedCommand.SendPoll -> {
|
||||
room.sendPoll(slashCommandResult.question, slashCommandResult.options.mapIndexed { index, s -> OptionItem(s, "$index. $s") })
|
||||
_viewEvents.post(TextComposerViewEvents.SlashCommandResultOk())
|
||||
popDraft()
|
||||
}
|
||||
is ParsedCommand.ChangeTopic -> {
|
||||
handleChangeTopicSlashCommand(slashCommandResult)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user