Really reenable editing messages, don't just do half a job.
This commit is contained in:
@@ -77,7 +77,17 @@ void ChatBarMessageContentModel::connectCache(ChatBarCache *oldCache)
|
||||
oldCache->disconnect(this);
|
||||
}
|
||||
|
||||
connect(m_room->cacheForType(m_type), &ChatBarCache::relationIdChanged, this, &ChatBarMessageContentModel::updateReplyModel);
|
||||
connect(m_room->cacheForType(m_type), &ChatBarCache::relationIdChanged, this, [this]() {
|
||||
if (!m_room || m_type == ChatBarType::None) {
|
||||
return;
|
||||
}
|
||||
const auto currentCache = m_room->cacheForType(m_type);
|
||||
if (currentCache->isReplying()) {
|
||||
updateReplyModel();
|
||||
} else if (currentCache->isEditing()) {
|
||||
initializeFromCache();
|
||||
}
|
||||
});
|
||||
connect(m_room->cacheForType(m_type), &ChatBarCache::attachmentPathChanged, this, [this]() {
|
||||
if (m_room->cacheForType(m_type)->attachmentPath().length() > 0) {
|
||||
addAttachment(QUrl(m_room->cacheForType(m_type)->attachmentPath()));
|
||||
@@ -114,7 +124,8 @@ void ChatBarMessageContentModel::initializeFromCache()
|
||||
|
||||
clearModel();
|
||||
|
||||
const auto textSections = m_room->cacheForType(m_type)->text().split(u"\n\n"_s);
|
||||
const auto currentCache = m_room->cacheForType(m_type);
|
||||
const auto textSections = (m_type == ChatBarType::Room ? currentCache->text() : currentCache->relationMessage()).split(u"\n\n"_s);
|
||||
if (textSections.length() == 1 && textSections[0].isEmpty()) {
|
||||
initializeModel();
|
||||
return;
|
||||
@@ -334,6 +345,11 @@ bool ChatBarMessageContentModel::hasRichFormatting() const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ChatBarMessageContentModel::hasAttachment() const
|
||||
{
|
||||
return hasComponentType({MessageComponentType::File, MessageComponentType::Audio, MessageComponentType::Image, MessageComponentType::Video});
|
||||
}
|
||||
|
||||
void ChatBarMessageContentModel::addAttachment(const QUrl &path)
|
||||
{
|
||||
if (m_type == ChatBarType::None || !m_room) {
|
||||
@@ -360,6 +376,7 @@ void ChatBarMessageContentModel::addAttachment(const QUrl &path)
|
||||
it->display = path.fileName();
|
||||
Q_EMIT dataChanged(index(std::distance(m_components.begin(), it)), index(std::distance(m_components.begin(), it)), {DisplayRole});
|
||||
m_room->cacheForType(m_type)->setAttachmentPath(path.toString());
|
||||
Q_EMIT hasAttachmentChanged();
|
||||
}
|
||||
|
||||
ChatBarMessageContentModel::ComponentIt
|
||||
@@ -477,6 +494,7 @@ void ChatBarMessageContentModel::removeAttachment()
|
||||
if (m_room) {
|
||||
m_room->cacheForType(m_type)->setAttachmentPath({});
|
||||
}
|
||||
Q_EMIT hasAttachmentChanged();
|
||||
}
|
||||
|
||||
bool ChatBarMessageContentModel::sendMessageWithEnter() const
|
||||
|
||||
@@ -67,6 +67,11 @@ class ChatBarMessageContentModel : public MessageContentModel
|
||||
*/
|
||||
Q_PROPERTY(bool hasRichFormatting READ hasRichFormatting NOTIFY hasRichFormattingChanged)
|
||||
|
||||
/**
|
||||
* @brief Whether the model has an attachment..
|
||||
*/
|
||||
Q_PROPERTY(bool hasAttachment READ hasAttachment NOTIFY hasAttachmentChanged)
|
||||
|
||||
/**
|
||||
* @brief The UserListModel to be used for room completions.
|
||||
*/
|
||||
@@ -89,6 +94,7 @@ public:
|
||||
Q_INVOKABLE void insertComponentAtCursor(MessageComponentType::Type type);
|
||||
|
||||
bool hasRichFormatting() const;
|
||||
bool hasAttachment() const;
|
||||
Q_INVOKABLE void addAttachment(const QUrl &path);
|
||||
|
||||
Q_INVOKABLE void removeComponent(int row, bool removeLast = false);
|
||||
@@ -104,6 +110,7 @@ Q_SIGNALS:
|
||||
void typeChanged(ChatBarType::Type oldType, ChatBarType::Type newType);
|
||||
void focusRowChanged();
|
||||
void hasRichFormattingChanged();
|
||||
void hasAttachmentChanged();
|
||||
void sendMessageWithEnterChanged();
|
||||
|
||||
private:
|
||||
|
||||
@@ -244,7 +244,7 @@ QHash<int, QByteArray> MessageContentModel::roleNamesStatic()
|
||||
return roles;
|
||||
}
|
||||
|
||||
bool MessageContentModel::hasComponentType(MessageComponentType::Type type)
|
||||
bool MessageContentModel::hasComponentType(MessageComponentType::Type type) const
|
||||
{
|
||||
return std::find_if(m_components.cbegin(),
|
||||
m_components.cend(),
|
||||
@@ -254,7 +254,7 @@ bool MessageContentModel::hasComponentType(MessageComponentType::Type type)
|
||||
!= m_components.cend();
|
||||
}
|
||||
|
||||
bool MessageContentModel::hasComponentType(QList<MessageComponentType::Type> types)
|
||||
bool MessageContentModel::hasComponentType(QList<MessageComponentType::Type> types) const
|
||||
{
|
||||
for (const auto &type : types) {
|
||||
if (hasComponentType(type)) {
|
||||
|
||||
@@ -164,8 +164,8 @@ protected:
|
||||
using ComponentIt = QList<MessageComponent>::iterator;
|
||||
|
||||
QList<MessageComponent> m_components;
|
||||
bool hasComponentType(MessageComponentType::Type type);
|
||||
bool hasComponentType(QList<MessageComponentType::Type> types);
|
||||
bool hasComponentType(MessageComponentType::Type type) const;
|
||||
bool hasComponentType(QList<MessageComponentType::Type> types) const;
|
||||
void forEachComponentOfType(MessageComponentType::Type type, std::function<ComponentIt(ComponentIt)> function);
|
||||
void forEachComponentOfType(QList<MessageComponentType::Type> types, std::function<ComponentIt(ComponentIt)> function);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user