Merge branch 'forward_message_feature' of https://github.com/Jedi18/nheko into Jedi18-forward_message_feature
This commit is contained in:
commit
8236f6ba72
11 changed files with 334 additions and 35 deletions
|
|
@ -31,8 +31,6 @@
|
|||
#include "ui/NhekoCursorShape.h"
|
||||
#include "ui/NhekoDropArea.h"
|
||||
|
||||
#include <iostream> //only for debugging
|
||||
|
||||
Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents)
|
||||
Q_DECLARE_METATYPE(std::vector<DeviceInfo>)
|
||||
|
||||
|
|
@ -329,6 +327,10 @@ TimelineViewManager::addRoom(const QString &room_id)
|
|||
&TimelineModel::newEncryptedImage,
|
||||
imgProvider,
|
||||
&MxcImageProvider::addEncryptionInfo);
|
||||
connect(newRoom.data(),
|
||||
&TimelineModel::forwardToRoom,
|
||||
this,
|
||||
&TimelineViewManager::forwardMessageToRoom);
|
||||
models.insert(room_id, std::move(newRoom));
|
||||
}
|
||||
}
|
||||
|
|
@ -616,3 +618,80 @@ TimelineViewManager::focusTimeline()
|
|||
{
|
||||
getWidget()->setFocus();
|
||||
}
|
||||
|
||||
void
|
||||
TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEvents *e,
|
||||
QString roomId)
|
||||
{
|
||||
auto room = models.find(roomId);
|
||||
auto content = mtx::accessors::url(*e);
|
||||
std::optional<mtx::crypto::EncryptedFile> encryptionInfo = mtx::accessors::file(*e);
|
||||
|
||||
if (encryptionInfo) {
|
||||
http::client()->download(
|
||||
content,
|
||||
[this, roomId, e, encryptionInfo](const std::string &res,
|
||||
const std::string &content_type,
|
||||
const std::string &originalFilename,
|
||||
mtx::http::RequestErr err) {
|
||||
if (err)
|
||||
return;
|
||||
|
||||
auto data = mtx::crypto::to_string(
|
||||
mtx::crypto::decrypt_file(res, encryptionInfo.value()));
|
||||
|
||||
http::client()->upload(
|
||||
data,
|
||||
content_type,
|
||||
originalFilename,
|
||||
[this, roomId, e](const mtx::responses::ContentURI &res,
|
||||
mtx::http::RequestErr err) mutable {
|
||||
if (err) {
|
||||
nhlog::net()->warn("failed to upload media: {} {} ({})",
|
||||
err->matrix_error.error,
|
||||
to_string(err->matrix_error.errcode),
|
||||
static_cast<int>(err->status_code));
|
||||
return;
|
||||
}
|
||||
|
||||
std::visit(
|
||||
[this, roomId, url = res.content_uri](auto ev) {
|
||||
if constexpr (mtx::events::message_content_to_type<
|
||||
decltype(ev.content)> ==
|
||||
mtx::events::EventType::RoomMessage) {
|
||||
if constexpr (messageWithFileAndUrl(ev)) {
|
||||
ev.content.relations.relations
|
||||
.clear();
|
||||
ev.content.file.reset();
|
||||
ev.content.url = url;
|
||||
}
|
||||
|
||||
auto room = models.find(roomId);
|
||||
removeReplyFallback(ev);
|
||||
ev.content.relations.relations.clear();
|
||||
room.value()->sendMessageEvent(
|
||||
ev.content,
|
||||
mtx::events::EventType::RoomMessage);
|
||||
}
|
||||
},
|
||||
*e);
|
||||
});
|
||||
|
||||
return;
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
std::visit(
|
||||
[room](auto e) {
|
||||
if constexpr (mtx::events::message_content_to_type<decltype(e.content)> ==
|
||||
mtx::events::EventType::RoomMessage) {
|
||||
e.content.relations.relations.clear();
|
||||
removeReplyFallback(e);
|
||||
room.value()->sendMessageEvent(e.content,
|
||||
mtx::events::EventType::RoomMessage);
|
||||
}
|
||||
},
|
||||
*e);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue