Input field fixes

* Message with multiple mentions are not broken in IRC. Fix #267
* Editing a message won't remove mentions anymore
This commit is contained in:
Carl Schwan
2021-02-22 19:09:56 +00:00
parent 1234132a05
commit bb3b3bc088
8 changed files with 57 additions and 18 deletions

View File

@@ -142,7 +142,6 @@ void ActionsHandler::joinRoom(const QString &alias)
joinRoomJob->errorString()));
});
Quotient::JoinRoomJob::connect(joinRoomJob, &JoinRoomJob::success, [this, joinRoomJob] {
qDebug() << "joined" << joinRoomJob->roomId();
Q_EMIT roomJoined(joinRoomJob->roomId());
});
}
@@ -159,15 +158,16 @@ void ActionsHandler::createRoom(const QString &name, const QString &topic)
}
void ActionsHandler::postMessage(const QString &text,
const QString &attachementPath, const QString &replyEventId, const QString &editEventId)
const QString &attachementPath, const QString &replyEventId, const QString &editEventId,
const QVariantMap &usernames)
{
QString rawText = text;
QString cleanedText = text;
for (const auto *user : m_room->users()) {
const auto displayName = user->displayname(m_room);
cleanedText = cleanedText.replace(displayName,
"[" + displayName + "](https://matrix.to/#/" + user->id() + ")");
for (auto it = usernames.constBegin(); it != usernames.constEnd(); it++) {
cleanedText = cleanedText.replace(it.key(),
"[" + it.key() + "](https://matrix.to/#/" + it.value().toString() + ")");
}
if (attachementPath.length() > 0) {
@@ -328,5 +328,5 @@ void ActionsHandler::postMessage(const QString &text,
cleanedText = cleanedText.remove(0, noticePrefix.length());
messageEventType = RoomMessageEvent::MsgType::Notice;
}
m_room->postMessage(cleanedText, messageEventType, replyEventId, editEventId);
m_room->postMessage(rawText, cleanedText, messageEventType, replyEventId, editEventId);
}

View File

@@ -72,7 +72,7 @@ public Q_SLOTS:
///
/// This also interprets commands if any.
void postMessage(const QString &text, const QString &attachementPath,
const QString &replyEventId, const QString &editEventId);
const QString &replyEventId, const QString &editEventId, const QVariantMap &usernames);
private:
Connection *m_connection = nullptr;

View File

@@ -46,6 +46,7 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const
roles[ShowSectionRole] = "showSection";
roles[ReactionRole] = "reaction";
roles[IsEditedRole] = "isEdited";
roles[FormattedBodyRole] = "formattedBody";
return roles;
}
@@ -334,6 +335,16 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
return m_currentRoom->eventToString(evt, Qt::RichText);
}
if (role == FormattedBodyRole) {
if (auto e = eventCast<const RoomMessageEvent>(&evt)) {
if (e->hasTextContent() && e->mimeType().name() != "text/plain") {
return static_cast<const Quotient::EventContent::TextContent *>(e->content())->body;
}
}
return {};
}
if (role == MessageRole) {
return m_currentRoom->eventToString(evt);
}

View File

@@ -32,6 +32,7 @@ public:
LongOperationRole,
AnnotationRole,
UserMarkerRole,
FormattedBodyRole,
ReplyRole,

View File

@@ -538,12 +538,12 @@ QString msgTypeToString(MessageEventType msgType)
}
}
void NeoChatRoom::postMessage(const QString &text, MessageEventType type, const QString &replyEventId, const QString &relateToEventId)
void NeoChatRoom::postMessage(const QString &rawText, const QString &text, MessageEventType type, const QString &replyEventId, const QString &relateToEventId)
{
const auto html = markdownToHTML(text);
QString cleanText(text);
cleanText.replace(QRegularExpression("\\[(.+)\\]\\(.+\\)"), "\\1");
postHtmlMessage(cleanText, html, type, replyEventId, relateToEventId);
postHtmlMessage(rawText, html, type, replyEventId, relateToEventId);
}
void NeoChatRoom::postHtmlMessage(const QString &text, const QString &html, MessageEventType type, const QString &replyEventId, const QString &relateToEventId)

View File

@@ -139,7 +139,9 @@ public Q_SLOTS:
void acceptInvitation();
void forget();
void sendTypingNotification(bool isTyping);
void postMessage(const QString &text, Quotient::MessageEventType type = Quotient::MessageEventType::Text, const QString &replyEventId = QString(), const QString &relateToEventId = QString());
/// @param rawText The text as it was typed.
/// @param cleanedText The text with link to the users.
void postMessage(const QString &rawText, const QString &cleanedText, Quotient::MessageEventType type = Quotient::MessageEventType::Text, const QString &replyEventId = QString(), const QString &relateToEventId = QString());
void postHtmlMessage(const QString &text, const QString &html, Quotient::MessageEventType type = Quotient::MessageEventType::Text, const QString &replyEventId = QString(), const QString &relateToEventId = QString());
void changeAvatar(const QUrl &localFile);
void addLocalAlias(const QString &alias);