Fix some nitpicks

This commit is contained in:
Loren Burkholder 2023-03-01 17:04:17 -05:00
parent c27407bfab
commit ec8820ac64
2 changed files with 57 additions and 52 deletions

View file

@ -253,8 +253,6 @@ InputBar::updateTextContentProperties(const QString &t)
// check for invalid commands // check for invalid commands
auto commandName = getCommandAndArgs().first; auto commandName = getCommandAndArgs().first;
bool hasInvalidCommand{};
if (!commandName.isNull() && '/' + commandName != text()) {
static const QStringList validCommands{QStringLiteral("me"), static const QStringList validCommands{QStringLiteral("me"),
QStringLiteral("react"), QStringLiteral("react"),
QStringLiteral("join"), QStringLiteral("join"),
@ -286,17 +284,20 @@ InputBar::updateTextContentProperties(const QString &t)
QStringLiteral("goto"), QStringLiteral("goto"),
QStringLiteral("converttodm"), QStringLiteral("converttodm"),
QStringLiteral("converttoroom")}; QStringLiteral("converttoroom")};
hasInvalidCommand = !validCommands.contains(commandName); bool hasInvalidCommand = !commandName.isNull() && '/' + commandName != text() && !validCommands.contains(commandName);
} else
hasInvalidCommand = false;
bool signalsChanged{false};
if (containsInvalidCommand_ != hasInvalidCommand) { if (containsInvalidCommand_ != hasInvalidCommand) {
containsInvalidCommand_ = hasInvalidCommand; containsInvalidCommand_ = hasInvalidCommand;
emit containsInvalidCommandChanged(); signalsChanged = true;
} }
if (currentCommand_ != commandName) { if (currentCommand_ != commandName) {
currentCommand_ = commandName; currentCommand_ = commandName;
signalsChanged = true;
}
if (signalsChanged) {
emit currentCommandChanged(); emit currentCommandChanged();
emit containsInvalidCommandChanged();
} }
} }
@ -390,10 +391,11 @@ InputBar::send()
auto wasEdit = !room->edit().isEmpty(); auto wasEdit = !room->edit().isEmpty();
if (auto [commandName, args] = getCommandAndArgs(); commandName.isNull()) if (auto [commandName, args] = getCommandAndArgs(); commandName.isEmpty())
message(text()); message(text());
else else
command(commandName, args); if (!command(commandName, args))
message(text());
if (!wasEdit) { if (!wasEdit) {
history_.push_front(QLatin1String("")); history_.push_front(QLatin1String(""));
@ -758,16 +760,17 @@ InputBar::video(const QString &filename,
QPair<QString, QString> QPair<QString, QString>
InputBar::getCommandAndArgs() const InputBar::getCommandAndArgs() const
{ {
if (!text().startsWith('/')) const auto currentText = text();
return {{}, text()}; if (!currentText.startsWith('/'))
return {{}, currentText};
int command_end = text().indexOf(QRegularExpression(QStringLiteral("\\s"))); int command_end = currentText.indexOf(QRegularExpression(QStringLiteral("\\s")));
if (command_end == -1) if (command_end == -1)
command_end = text().size(); command_end = currentText.size();
auto name = text().mid(1, command_end - 1); auto name = currentText.mid(1, command_end - 1);
auto args = text().mid(command_end + 1); auto args = currentText.mid(command_end + 1);
if (name.isEmpty() || name == QLatin1String("/")) { if (name.isEmpty() || name == QLatin1String("/")) {
return {{}, text()}; return {{}, currentText};
} else { } else {
return {name, args}; return {name, args};
} }
@ -798,7 +801,7 @@ InputBar::sticker(CombinedImagePackModel *model, int row)
room->sendMessageEvent(sticker, mtx::events::EventType::Sticker); room->sendMessageEvent(sticker, mtx::events::EventType::Sticker);
} }
void bool
InputBar::command(const QString &command, QString args) InputBar::command(const QString &command, QString args)
{ {
if (command == QLatin1String("me")) { if (command == QLatin1String("me")) {
@ -886,16 +889,16 @@ InputBar::command(const QString &command, QString args)
// 1 - Going directly to a given event ID // 1 - Going directly to a given event ID
if (args[0] == '$') { if (args[0] == '$') {
room->showEvent(args); room->showEvent(args);
return; return true;
} }
// 2 - Going directly to a given message index // 2 - Going directly to a given message index
if (args[0] >= '0' && args[0] <= '9') { if (args[0] >= '0' && args[0] <= '9') {
room->showEvent(args); room->showEvent(args);
return; return true;
} }
// 3 - Matrix URI handler, as if you clicked the URI // 3 - Matrix URI handler, as if you clicked the URI
if (ChatPage::instance()->handleMatrixUri(args)) { if (ChatPage::instance()->handleMatrixUri(args)) {
return; return true;
} }
nhlog::net()->error("Could not resolve goto: {}", args.toStdString()); nhlog::net()->error("Could not resolve goto: {}", args.toStdString());
} else if (command == QLatin1String("converttodm")) { } else if (command == QLatin1String("converttodm")) {
@ -904,8 +907,10 @@ InputBar::command(const QString &command, QString args)
} else if (command == QLatin1String("converttoroom")) { } else if (command == QLatin1String("converttoroom")) {
utils::removeDirectFromRoom(this->room->roomId()); utils::removeDirectFromRoom(this->room->roomId());
} else { } else {
message("/" + command + " " + args); return false;
} }
return true;
} }
MediaUpload::MediaUpload(std::unique_ptr<QIODevice> source_, MediaUpload::MediaUpload(std::unique_ptr<QIODevice> source_,

View file

@ -238,7 +238,7 @@ private:
void emote(const QString &body, bool rainbowify); void emote(const QString &body, bool rainbowify);
void notice(const QString &body, bool rainbowify); void notice(const QString &body, bool rainbowify);
void confetti(const QString &body, bool rainbowify); void confetti(const QString &body, bool rainbowify);
void command(const QString &name, QString args); bool command(const QString &name, QString args);
void image(const QString &filename, void image(const QString &filename,
const std::optional<mtx::crypto::EncryptedFile> &file, const std::optional<mtx::crypto::EncryptedFile> &file,
const QString &url, const QString &url,