Implement message editing

The UI still looks ugly, but I have no good idea atm.

fixes #134
This commit is contained in:
Nicolas Werner 2021-02-01 02:22:53 +01:00
parent 00fd4eecec
commit 9b7d33e847
9 changed files with 90 additions and 15 deletions

View file

@ -268,7 +268,18 @@ InputBar::message(QString msg, MarkdownOverride useMarkdown)
text.format = "org.matrix.custom.html";
}
if (!room->reply().isEmpty()) {
if (!room->edit().isEmpty()) {
if (!room->reply().isEmpty()) {
text.relations.relations.push_back(
{mtx::common::RelationType::InReplyTo, room->reply().toStdString()});
room->resetReply();
}
text.relations.relations.push_back(
{mtx::common::RelationType::Replace, room->edit().toStdString()});
room->resetEdit();
} else if (!room->reply().isEmpty()) {
auto related = room->relatedInfo(room->reply());
QString body;
@ -321,6 +332,11 @@ InputBar::emote(QString msg)
{mtx::common::RelationType::InReplyTo, room->reply().toStdString()});
room->resetReply();
}
if (!room->edit().isEmpty()) {
emote.relations.relations.push_back(
{mtx::common::RelationType::Replace, room->edit().toStdString()});
room->resetEdit();
}
room->sendMessageEvent(emote, mtx::events::EventType::RoomMessage);
}
@ -352,6 +368,11 @@ InputBar::image(const QString &filename,
{mtx::common::RelationType::InReplyTo, room->reply().toStdString()});
room->resetReply();
}
if (!room->edit().isEmpty()) {
image.relations.relations.push_back(
{mtx::common::RelationType::Replace, room->edit().toStdString()});
room->resetEdit();
}
room->sendMessageEvent(image, mtx::events::EventType::RoomMessage);
}
@ -378,6 +399,11 @@ InputBar::file(const QString &filename,
{mtx::common::RelationType::InReplyTo, room->reply().toStdString()});
room->resetReply();
}
if (!room->edit().isEmpty()) {
file.relations.relations.push_back(
{mtx::common::RelationType::Replace, room->edit().toStdString()});
room->resetEdit();
}
room->sendMessageEvent(file, mtx::events::EventType::RoomMessage);
}
@ -405,6 +431,11 @@ InputBar::audio(const QString &filename,
{mtx::common::RelationType::InReplyTo, room->reply().toStdString()});
room->resetReply();
}
if (!room->edit().isEmpty()) {
audio.relations.relations.push_back(
{mtx::common::RelationType::Replace, room->edit().toStdString()});
room->resetEdit();
}
room->sendMessageEvent(audio, mtx::events::EventType::RoomMessage);
}
@ -431,6 +462,11 @@ InputBar::video(const QString &filename,
{mtx::common::RelationType::InReplyTo, room->reply().toStdString()});
room->resetReply();
}
if (!room->edit().isEmpty()) {
video.relations.relations.push_back(
{mtx::common::RelationType::Replace, room->edit().toStdString()});
room->resetEdit();
}
room->sendMessageEvent(video, mtx::events::EventType::RoomMessage);
}
@ -524,6 +560,8 @@ InputBar::showPreview(const QMimeData &source, QString path, const QStringList &
[this](const QByteArray data, const QString &mime, const QString &fn) {
setUploading(true);
setText("");
auto payload = std::string(data.data(), data.size());
std::optional<mtx::crypto::EncryptedFile> encryptedFile;
if (cache::isRoomEncrypted(room->roomId().toStdString())) {