Disable send message when there's nothing to actually send
Now there's a way to check if the message content model has any useful data inside of it. BUG: 516118 FIXED-IN: 26.04
This commit is contained in:
@@ -60,6 +60,9 @@ ChatBarMessageContentModel::ChatBarMessageContentModel(QObject *parent)
|
||||
initializeFromCache();
|
||||
});
|
||||
connect(m_markdownHelper, &ChatMarkdownHelper::unhandledBlockFormat, this, &ChatBarMessageContentModel::insertStyleAtCursor);
|
||||
connect(this, &ChatBarMessageContentModel::modelReset, this, &ChatBarMessageContentModel::hasAnyContentChanged);
|
||||
connect(this, &ChatBarMessageContentModel::rowsInserted, this, &ChatBarMessageContentModel::hasAnyContentChanged);
|
||||
connect(this, &ChatBarMessageContentModel::rowsRemoved, this, &ChatBarMessageContentModel::hasAnyContentChanged);
|
||||
|
||||
connectCache();
|
||||
connectKeyHelper();
|
||||
@@ -302,6 +305,7 @@ void ChatBarMessageContentModel::connectTextItem(ChatTextItemHelper *chattextite
|
||||
connect(chattextitemhelper, &ChatTextItemHelper::cleared, this, [this](ChatTextItemHelper *helper) {
|
||||
removeComponent(helper);
|
||||
});
|
||||
connect(chattextitemhelper, &ChatTextItemHelper::contentsChanged, this, &ChatBarMessageContentModel::hasAnyContentChanged);
|
||||
}
|
||||
|
||||
ChatTextItemHelper *ChatBarMessageContentModel::textItemForComponent(const MessageComponent &component) const
|
||||
@@ -664,6 +668,28 @@ void ChatBarMessageContentModel::postMessage()
|
||||
refocusCurrentComponent();
|
||||
}
|
||||
|
||||
bool ChatBarMessageContentModel::hasAnyContent() const
|
||||
{
|
||||
// Shouldn't really be possible, but is true.
|
||||
if (m_components.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If there's more than one component naturally there is content.
|
||||
if (m_components.size() > 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// There's usually at a minimum a TextComponent, we need to check if it's empty.
|
||||
if (const auto textItem = textItemForComponent(m_components.constFirst())) {
|
||||
if (textItem->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<QString> ChatBarMessageContentModel::getReplyEventId()
|
||||
{
|
||||
if (!m_room) {
|
||||
|
||||
Reference in New Issue
Block a user