Adapt to the new inherited variant

This commit is contained in:
Nicolas Werner 2023-04-11 00:11:46 +02:00
parent 7973fbce8c
commit 10b65b78fa
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
16 changed files with 99 additions and 106 deletions

View file

@ -602,7 +602,7 @@ if(USE_BUNDLED_MTXCLIENT)
FetchContent_Declare( FetchContent_Declare(
MatrixClient MatrixClient
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
GIT_TAG dd2bdbd104ae8f70f82da9ff7b4b60007fc105c3 GIT_TAG e136bc27b28d3bb5683735eb5a65d6ef2534ca3a
) )
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "") set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "") set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")

View file

@ -213,7 +213,7 @@ modules:
buildsystem: cmake-ninja buildsystem: cmake-ninja
name: mtxclient name: mtxclient
sources: sources:
- commit: dd2bdbd104ae8f70f82da9ff7b4b60007fc105c3 - commit: e136bc27b28d3bb5683735eb5a65d6ef2534ca3a
#tag: v0.9.2 #tag: v0.9.2
type: git type: git
url: https://github.com/Nheko-Reborn/mtxclient.git url: https://github.com/Nheko-Reborn/mtxclient.git

View file

@ -1284,9 +1284,8 @@ Cache::runMigrations()
else if (j["token"].get<std::string>() != oldMessages.prev_batch) else if (j["token"].get<std::string>() != oldMessages.prev_batch)
break; break;
mtx::events::collections::TimelineEvent te; oldMessages.events.push_back(
from_json(j["event"], te); j["event"].get<mtx::events::collections::TimelineEvents>());
oldMessages.events.push_back(te.data);
} }
// messages were stored in reverse order, so we // messages were stored in reverse order, so we
// need to reverse them // need to reverse them
@ -2398,15 +2397,13 @@ Cache::getTimelineMessages(lmdb::txn &txn, const std::string &room_id, uint64_t
if (!success) if (!success)
continue; continue;
mtx::events::collections::TimelineEvent te;
try { try {
from_json(nlohmann::json::parse(event), te); messages.timeline.events.push_back(
nlohmann::json::parse(event).get<mtx::events::collections::TimelineEvents>());
} catch (std::exception &e) { } catch (std::exception &e) {
nhlog::db()->error("Failed to parse message from cache {}", e.what()); nhlog::db()->error("Failed to parse message from cache {}", e.what());
continue; continue;
} }
messages.timeline.events.push_back(std::move(te.data));
} }
cursor.close(); cursor.close();
@ -2417,7 +2414,7 @@ Cache::getTimelineMessages(lmdb::txn &txn, const std::string &room_id, uint64_t
return messages; return messages;
} }
std::optional<mtx::events::collections::TimelineEvent> std::optional<mtx::events::collections::TimelineEvents>
Cache::getEvent(const std::string &room_id, std::string_view event_id) Cache::getEvent(const std::string &room_id, std::string_view event_id)
{ {
auto txn = ro_txn(env_); auto txn = ro_txn(env_);
@ -2428,24 +2425,21 @@ Cache::getEvent(const std::string &room_id, std::string_view event_id)
if (!success) if (!success)
return {}; return {};
mtx::events::collections::TimelineEvent te;
try { try {
from_json(nlohmann::json::parse(event), te); return nlohmann::json::parse(event).get<mtx::events::collections::TimelineEvents>();
} catch (std::exception &e) { } catch (std::exception &e) {
nhlog::db()->error("Failed to parse message from cache {}", e.what()); nhlog::db()->error("Failed to parse message from cache {}", e.what());
return std::nullopt; return std::nullopt;
} }
return te;
} }
void void
Cache::storeEvent(const std::string &room_id, Cache::storeEvent(const std::string &room_id,
const std::string &event_id, const std::string &event_id,
const mtx::events::collections::TimelineEvent &event) const mtx::events::collections::TimelineEvents &event)
{ {
auto txn = lmdb::txn::begin(env_); auto txn = lmdb::txn::begin(env_);
auto eventsDb = getEventsDb(txn, room_id); auto eventsDb = getEventsDb(txn, room_id);
auto event_json = mtx::accessors::serialize_event(event.data); auto event_json = mtx::accessors::serialize_event(event);
eventsDb.put(txn, event_id, event_json.dump()); eventsDb.put(txn, event_id, event_json.dump());
txn.commit(); txn.commit();
} }
@ -2453,17 +2447,17 @@ Cache::storeEvent(const std::string &room_id,
void void
Cache::replaceEvent(const std::string &room_id, Cache::replaceEvent(const std::string &room_id,
const std::string &event_id, const std::string &event_id,
const mtx::events::collections::TimelineEvent &event) const mtx::events::collections::TimelineEvents &event)
{ {
auto txn = lmdb::txn::begin(env_); auto txn = lmdb::txn::begin(env_);
auto eventsDb = getEventsDb(txn, room_id); auto eventsDb = getEventsDb(txn, room_id);
auto relationsDb = getRelationsDb(txn, room_id); auto relationsDb = getRelationsDb(txn, room_id);
auto event_json = mtx::accessors::serialize_event(event.data).dump(); auto event_json = mtx::accessors::serialize_event(event).dump();
{ {
eventsDb.del(txn, event_id); eventsDb.del(txn, event_id);
eventsDb.put(txn, event_id, event_json); eventsDb.put(txn, event_id, event_json);
for (const auto &relation : mtx::accessors::relations(event.data).relations) { for (const auto &relation : mtx::accessors::relations(event).relations) {
relationsDb.put(txn, relation.event_id, event_id); relationsDb.put(txn, relation.event_id, event_id);
} }
} }
@ -3430,19 +3424,19 @@ Cache::isRoomMember(const std::string &user_id, const std::string &room_id)
void void
Cache::savePendingMessage(const std::string &room_id, Cache::savePendingMessage(const std::string &room_id,
const mtx::events::collections::TimelineEvent &message) const mtx::events::collections::TimelineEvents &message)
{ {
auto txn = lmdb::txn::begin(env_); auto txn = lmdb::txn::begin(env_);
auto eventsDb = getEventsDb(txn, room_id); auto eventsDb = getEventsDb(txn, room_id);
mtx::responses::Timeline timeline; mtx::responses::Timeline timeline;
timeline.events.push_back(message.data); timeline.events.push_back(message);
saveTimelineMessages(txn, eventsDb, room_id, timeline); saveTimelineMessages(txn, eventsDb, room_id, timeline);
auto pending = getPendingMessagesDb(txn, room_id); auto pending = getPendingMessagesDb(txn, room_id);
int64_t now = QDateTime::currentMSecsSinceEpoch(); int64_t now = QDateTime::currentMSecsSinceEpoch();
pending.put(txn, lmdb::to_sv(now), mtx::accessors::event_id(message.data)); pending.put(txn, lmdb::to_sv(now), mtx::accessors::event_id(message));
txn.commit(); txn.commit();
} }
@ -3469,7 +3463,7 @@ Cache::pendingEvents(const std::string &room_id)
return related_ids; return related_ids;
} }
std::optional<mtx::events::collections::TimelineEvent> std::optional<mtx::events::collections::TimelineEvents>
Cache::firstPendingMessage(const std::string &room_id) Cache::firstPendingMessage(const std::string &room_id)
{ {
auto txn = lmdb::txn::begin(env_); auto txn = lmdb::txn::begin(env_);
@ -3487,8 +3481,8 @@ Cache::firstPendingMessage(const std::string &room_id)
} }
try { try {
mtx::events::collections::TimelineEvent te; mtx::events::collections::TimelineEvents te =
from_json(nlohmann::json::parse(event), te); nlohmann::json::parse(event).get<mtx::events::collections::TimelineEvents>();
pendingCursor.close(); pendingCursor.close();
return te; return te;
@ -3622,10 +3616,10 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
if (!success) if (!success)
continue; continue;
mtx::events::collections::TimelineEvent te;
try { try {
from_json(nlohmann::json::parse(std::string_view(oldEvent.data(), oldEvent.size())), auto te = nlohmann::json::parse(std::string_view(oldEvent.data(), oldEvent.size()))
te); .get<mtx::events::collections::TimelineEvents>();
// overwrite the content and add redation data // overwrite the content and add redation data
std::visit( std::visit(
[&redaction, &room_id, &txn, &eventsDb, this](auto &ev) { [&redaction, &room_id, &txn, &eventsDb, this](auto &ev) {
@ -3652,8 +3646,8 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
mtx::events::collections::StateEvents{redactedEvent}); mtx::events::collections::StateEvents{redactedEvent});
} }
}, },
te.data); te);
event = mtx::accessors::serialize_event(te.data); event = mtx::accessors::serialize_event(te);
event["content"].clear(); event["content"].clear();
} catch (std::exception &e) { } catch (std::exception &e) {

View file

@ -193,14 +193,14 @@ public:
uint64_t index = std::numeric_limits<uint64_t>::max(), uint64_t index = std::numeric_limits<uint64_t>::max(),
bool forward = false); bool forward = false);
std::optional<mtx::events::collections::TimelineEvent> std::optional<mtx::events::collections::TimelineEvents>
getEvent(const std::string &room_id, std::string_view event_id); getEvent(const std::string &room_id, std::string_view event_id);
void storeEvent(const std::string &room_id, void storeEvent(const std::string &room_id,
const std::string &event_id, const std::string &event_id,
const mtx::events::collections::TimelineEvent &event); const mtx::events::collections::TimelineEvents &event);
void replaceEvent(const std::string &room_id, void replaceEvent(const std::string &room_id,
const std::string &event_id, const std::string &event_id,
const mtx::events::collections::TimelineEvent &event); const mtx::events::collections::TimelineEvents &event);
std::vector<std::string> relatedEvents(const std::string &room_id, const std::string &event_id); std::vector<std::string> relatedEvents(const std::string &room_id, const std::string &event_id);
struct TimelineRange struct TimelineRange
@ -219,9 +219,9 @@ public:
std::string previousBatchToken(const std::string &room_id); std::string previousBatchToken(const std::string &room_id);
uint64_t saveOldMessages(const std::string &room_id, const mtx::responses::Messages &res); uint64_t saveOldMessages(const std::string &room_id, const mtx::responses::Messages &res);
void savePendingMessage(const std::string &room_id, void savePendingMessage(const std::string &room_id,
const mtx::events::collections::TimelineEvent &message); const mtx::events::collections::TimelineEvents &message);
std::vector<std::string> pendingEvents(const std::string &room_id); std::vector<std::string> pendingEvents(const std::string &room_id);
std::optional<mtx::events::collections::TimelineEvent> std::optional<mtx::events::collections::TimelineEvents>
firstPendingMessage(const std::string &room_id); firstPendingMessage(const std::string &room_id);
void removePendingStatus(const std::string &room_id, const std::string &txn_id); void removePendingStatus(const std::string &room_id, const std::string &txn_id);

View file

@ -270,7 +270,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent)
auto ctx = roomModel->pushrulesRoomContext(); auto ctx = roomModel->pushrulesRoomContext();
std::vector< std::vector<
std::pair<mtx::common::Relation, mtx::events::collections::TimelineEvent>> std::pair<mtx::common::Relation, mtx::events::collections::TimelineEvents>>
relatedEvents; relatedEvents;
for (const auto &event : room.timeline.events) { for (const auto &event : room.timeline.events) {
@ -286,9 +286,9 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent)
if (sender == http::client()->user_id().to_string()) if (sender == http::client()->user_id().to_string())
continue; continue;
mtx::events::collections::TimelineEvent te{event}; mtx::events::collections::TimelineEvents te{event};
std::visit([room_id = room_id](auto &event_) { event_.room_id = room_id; }, std::visit([room_id = room_id](auto &event_) { event_.room_id = room_id; },
te.data); te);
if (auto encryptedEvent = if (auto encryptedEvent =
std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
@ -298,23 +298,24 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent)
auto result = olm::decryptEvent(index, *encryptedEvent); auto result = olm::decryptEvent(index, *encryptedEvent);
if (result.event) if (result.event)
te.data = result.event.value(); te = std::move(result.event).value();
} }
relatedEvents.clear(); relatedEvents.clear();
for (const auto &r : mtx::accessors::relations(te.data).relations) { for (const auto &r : mtx::accessors::relations(te).relations) {
auto related = cache::client()->getEvent(room_id, r.event_id); auto related = cache::client()->getEvent(room_id, r.event_id);
if (related) { if (related) {
relatedEvents.emplace_back(r, *related); relatedEvents.emplace_back(r, *related);
if (auto encryptedEvent = std::get_if< if (auto encryptedEvent = std::get_if<
mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
&related->data); &related.value());
encryptedEvent && userSettings_->decryptNotifications()) { encryptedEvent && userSettings_->decryptNotifications()) {
MegolmSessionIndex index(room_id, encryptedEvent->content); MegolmSessionIndex index(room_id, encryptedEvent->content);
auto result = olm::decryptEvent(index, *encryptedEvent); auto result = olm::decryptEvent(index, *encryptedEvent);
if (result.event) if (result.event)
relatedEvents.back().second.data = result.event.value(); relatedEvents.back().second =
std::move(result.event).value();
} }
} }
} }
@ -343,7 +344,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent)
notificationsManager->postNotification( notificationsManager->postNotification(
mtx::responses::Notification{ mtx::responses::Notification{
.actions = actions, .actions = actions,
.event = te.data, .event = std::move(te),
.read = false, .read = false,
.profile_tag = "", .profile_tag = "",
.room_id = room_id, .room_id = room_id,

View file

@ -461,7 +461,7 @@ mtx::accessors::media_width(const mtx::events::collections::TimelineEvents &even
nlohmann::json nlohmann::json
mtx::accessors::serialize_event(const mtx::events::collections::TimelineEvents &event) mtx::accessors::serialize_event(const mtx::events::collections::TimelineEvents &event)
{ {
return std::visit([](const auto &e) { return nlohmann::json(e); }, event); return nlohmann::json(event);
} }
bool bool

View file

@ -37,8 +37,6 @@
#include "UserSettingsPage.h" #include "UserSettingsPage.h"
#include "timeline/Permissions.h" #include "timeline/Permissions.h"
using TimelineEvent = mtx::events::collections::TimelineEvents;
template<class T, class Event> template<class T, class Event>
static DescInfo static DescInfo
createDescriptionInfo(const Event &event, const QString &localUser, const QString &displayName) createDescriptionInfo(const Event &event, const QString &localUser, const QString &displayName)
@ -89,7 +87,9 @@ utils::stripReplyFromFormattedBody(const std::string &formatted_bodyi)
} }
RelatedInfo RelatedInfo
utils::stripReplyFallbacks(const TimelineEvent &event, std::string id, QString room_id_) utils::stripReplyFallbacks(const mtx::events::collections::TimelineEvents &event,
std::string id,
QString room_id_)
{ {
RelatedInfo related = {}; RelatedInfo related = {};
related.quoted_user = QString::fromStdString(mtx::accessors::sender(event)); related.quoted_user = QString::fromStdString(mtx::accessors::sender(event));
@ -211,7 +211,7 @@ utils::descriptiveTime(const QDateTime &then)
} }
DescInfo DescInfo
utils::getMessageDescription(const TimelineEvent &event, utils::getMessageDescription(const mtx::events::collections::TimelineEvents &event,
const QString &localUser, const QString &localUser,
const QString &displayName) const QString &displayName)
{ {

View file

@ -39,9 +39,6 @@ struct RelatedInfo
}; };
namespace utils { namespace utils {
using TimelineEvent = mtx::events::collections::TimelineEvents;
//! Helper function to remove reply fallback from body //! Helper function to remove reply fallback from body
std::string std::string
stripReplyFromBody(const std::string &body); stripReplyFromBody(const std::string &body);
@ -51,7 +48,9 @@ std::string
stripReplyFromFormattedBody(const std::string &formatted_body); stripReplyFromFormattedBody(const std::string &formatted_body);
RelatedInfo RelatedInfo
stripReplyFallbacks(const TimelineEvent &event, std::string id, QString room_id_); stripReplyFallbacks(const mtx::events::collections::TimelineEvents &event,
std::string id,
QString room_id_);
bool bool
codepointIsEmoji(uint code); codepointIsEmoji(uint code);
@ -75,7 +74,7 @@ descriptiveTime(const QDateTime &then);
//! Generate a message description from the event to be displayed //! Generate a message description from the event to be displayed
//! in the RoomList. //! in the RoomList.
DescInfo DescInfo
getMessageDescription(const TimelineEvent &event, getMessageDescription(const mtx::events::collections::TimelineEvents &event,
const QString &localUser, const QString &localUser,
const QString &displayName); const QString &displayName);

View file

@ -1273,13 +1273,13 @@ decryptEvent(const MegolmSessionIndex &index,
body["origin_server_ts"] = event.origin_server_ts; body["origin_server_ts"] = event.origin_server_ts;
body["unsigned"] = event.unsigned_data; body["unsigned"] = event.unsigned_data;
mtx::events::collections::TimelineEvent te; mtx::events::collections::TimelineEvents te =
from_json(body, te); body.get<mtx::events::collections::TimelineEvents>();
// relations are unencrypted in content... // relations are unencrypted in content...
mtx::accessors::set_relations(te.data, std::move(event.content.relations)); mtx::accessors::set_relations(te, std::move(event.content.relations));
return {DecryptionErrorCode::NoError, std::nullopt, std::move(te.data)}; return {DecryptionErrorCode::NoError, std::nullopt, std::move(te)};
} catch (std::exception &e) { } catch (std::exception &e) {
return {DecryptionErrorCode::ParsingFailed, e.what(), std::nullopt}; return {DecryptionErrorCode::ParsingFailed, e.what(), std::nullopt};
} }

View file

@ -155,7 +155,7 @@ EventStore::EventStore(std::string room_id, QObject *)
} }
}); });
}, },
event->data); event.value());
}); });
connect( connect(
@ -195,20 +195,20 @@ EventStore::EventStore(std::string room_id, QObject *)
mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> original_encrypted; mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> original_encrypted;
if (auto encrypted = if (auto encrypted =
std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
&pending_event->data)) { &pending_event.value())) {
auto d_event = decryptEvent({room_id_, encrypted->event_id}, *encrypted); auto d_event = decryptEvent({room_id_, encrypted->event_id}, *encrypted);
if (d_event->event) { if (d_event->event) {
was_encrypted = true; was_encrypted = true;
original_encrypted = *encrypted; original_encrypted = std::move(*encrypted);
pending_event->data = *d_event->event; *pending_event = std::move(*d_event->event);
} }
} }
auto relations = mtx::accessors::relations(pending_event->data); auto relations = mtx::accessors::relations(pending_event.value());
// Replace the blockquote in fallback reply // Replace the blockquote in fallback reply
auto related_text = std::get_if<mtx::events::RoomEvent<mtx::events::msg::Text>>( auto related_text = std::get_if<mtx::events::RoomEvent<mtx::events::msg::Text>>(
&pending_event->data); &pending_event.value());
if (related_text && relations.reply_to() == txn_id) { if (related_text && relations.reply_to() == txn_id) {
size_t index = related_text->content.formatted_body.find(txn_id); size_t index = related_text->content.formatted_body.find(txn_id);
if (index != std::string::npos) { if (index != std::string::npos) {
@ -228,7 +228,7 @@ EventStore::EventStore(std::string room_id, QObject *)
if (!replaced_txn) if (!replaced_txn)
continue; continue;
mtx::accessors::set_relations(pending_event->data, std::move(relations)); mtx::accessors::set_relations(pending_event.value(), std::move(relations));
// reencrypt. This is a bit of a hack and might make people able to read the // reencrypt. This is a bit of a hack and might make people able to read the
// message, that were in the room at the time of sending the last pending message. // message, that were in the room at the time of sending the last pending message.
@ -246,7 +246,7 @@ EventStore::EventStore(std::string room_id, QObject *)
{"content", nlohmann::json(msg.content)}, {"content", nlohmann::json(msg.content)},
{"room_id", room_id_}}; {"room_id", room_id_}};
}, },
pending_event->data); pending_event.value());
auto data = olm::encrypt_group_message_with_session( auto data = olm::encrypt_group_message_with_session(
session.session, http::client()->device_id(), std::move(doc)); session.session, http::client()->device_id(), std::move(doc));
@ -255,8 +255,8 @@ EventStore::EventStore(std::string room_id, QObject *)
olm_outbound_group_session_message_index(session.session.get()); olm_outbound_group_session_message_index(session.session.get());
cache::updateOutboundMegolmSession(room_id_, session.data, session.session); cache::updateOutboundMegolmSession(room_id_, session.data, session.session);
original_encrypted.content = data; original_encrypted.content = std::move(data);
pending_event->data = original_encrypted; *pending_event = std::move(original_encrypted);
} }
cache::client()->replaceEvent(room_id_, pending_event_id, *pending_event); cache::client()->replaceEvent(room_id_, pending_event_id, *pending_event);
@ -629,7 +629,7 @@ EventStore::reactions(const std::string &event_id)
return temp; return temp;
} }
mtx::events::collections::TimelineEvents * mtx::events::collections::TimelineEvents const *
EventStore::get(int idx, bool decrypt) EventStore::get(int idx, bool decrypt)
{ {
if (this->thread() != QThread::currentThread()) if (this->thread() != QThread::currentThread())
@ -645,17 +645,17 @@ EventStore::get(int idx, bool decrypt)
if (!event_id) if (!event_id)
return nullptr; return nullptr;
std::optional<mtx::events::collections::TimelineEvent> event; std::optional<mtx::events::collections::TimelineEvents> event;
auto edits_ = edits(*event_id); auto edits_ = edits(*event_id);
if (edits_.empty()) if (edits_.empty())
event = cache::client()->getEvent(room_id_, *event_id); event = cache::client()->getEvent(room_id_, *event_id);
else else
event = mtx::events::collections::TimelineEvent{edits_.back()}; event = mtx::events::collections::TimelineEvents{edits_.back()};
if (!event) if (!event)
return nullptr; return nullptr;
else else
event_ptr = new mtx::events::collections::TimelineEvents(std::move(event->data)); event_ptr = new mtx::events::collections::TimelineEvents(std::move(*event));
events_.insert(index, event_ptr); events_.insert(index, event_ptr);
} }
@ -692,7 +692,7 @@ EventStore::indexToId(int idx) const
return cache::client()->getTimelineEventId(room_id_, toInternalIdx(idx)); return cache::client()->getTimelineEventId(room_id_, toInternalIdx(idx));
} }
olm::DecryptionResult * olm::DecryptionResult const *
EventStore::decryptEvent(const IdIndex &idx, EventStore::decryptEvent(const IdIndex &idx,
const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &e) const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &e)
{ {
@ -813,7 +813,7 @@ EventStore::enableKeyRequests(bool suppressKeyRequests_)
suppressKeyRequests = true; suppressKeyRequests = true;
} }
mtx::events::collections::TimelineEvents * mtx::events::collections::TimelineEvents const *
EventStore::get(const std::string &id, EventStore::get(const std::string &id,
std::string_view related_to, std::string_view related_to,
bool decrypt, bool decrypt,
@ -856,7 +856,7 @@ EventStore::get(const std::string &id,
}); });
return nullptr; return nullptr;
} }
event_ptr = new mtx::events::collections::TimelineEvents(std::move(event->data)); event_ptr = new mtx::events::collections::TimelineEvents(std::move(*event));
events_by_id_.insert(index, event_ptr); events_by_id_.insert(index, event_ptr);
} }
@ -895,7 +895,7 @@ EventStore::decryptionError(std::string id)
if (!event) { if (!event) {
return olm::DecryptionErrorCode::NoError; return olm::DecryptionErrorCode::NoError;
} }
event_ptr = new mtx::events::collections::TimelineEvents(std::move(event->data)); event_ptr = new mtx::events::collections::TimelineEvents(std::move(*event));
events_by_id_.insert(index, event_ptr); events_by_id_.insert(index, event_ptr);
} }

View file

@ -73,12 +73,12 @@ public:
// optionally returns the event or nullptr and fetches it, after which it emits a // optionally returns the event or nullptr and fetches it, after which it emits a
// relatedFetched event // relatedFetched event
mtx::events::collections::TimelineEvents *get(const std::string &id, mtx::events::collections::TimelineEvents const *get(const std::string &id,
std::string_view related_to, std::string_view related_to,
bool decrypt = true, bool decrypt = true,
bool resolve_edits = true); bool resolve_edits = true);
// always returns a proper event as long as the idx is valid // always returns a proper event as long as the idx is valid
mtx::events::collections::TimelineEvents *get(int idx, bool decrypt = true); mtx::events::collections::TimelineEvents const *get(int idx, bool decrypt = true);
QVariantList reactions(const std::string &event_id); QVariantList reactions(const std::string &event_id);
std::vector<mtx::events::collections::TimelineEvents> edits(const std::string &event_id); std::vector<mtx::events::collections::TimelineEvents> edits(const std::string &event_id);
@ -126,7 +126,7 @@ public slots:
void enableKeyRequests(bool suppressKeyRequests_); void enableKeyRequests(bool suppressKeyRequests_);
private: private:
olm::DecryptionResult * olm::DecryptionResult const *
decryptEvent(const IdIndex &idx, decryptEvent(const IdIndex &idx,
const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &e); const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &e);

View file

@ -53,7 +53,7 @@ threadFallbackEventId(const std::string &room_id, const std::string &thread_id)
for (const auto &[index, event_id] : orderedEvents) { for (const auto &[index, event_id] : orderedEvents) {
(void)index; (void)index;
if (auto event = cache::client()->getEvent(room_id, event_id)) { if (auto event = cache::client()->getEvent(room_id, event_id)) {
if (mtx::accessors::relations(event->data).thread() == thread_id) if (mtx::accessors::relations(event.value()).thread() == thread_id)
return std::string(event_id); return std::string(event_id);
} }
} }

View file

@ -776,13 +776,12 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
return qml_mtx_events::NotificationLevel::Nothing; return qml_mtx_events::NotificationLevel::Nothing;
const auto &id = event_id(event); const auto &id = event_id(event);
std::vector<std::pair<mtx::common::Relation, mtx::events::collections::TimelineEvent>> std::vector<std::pair<mtx::common::Relation, mtx::events::collections::TimelineEvents>>
relatedEvents; relatedEvents;
for (const auto &r : mtx::accessors::relations(event).relations) { for (const auto &r : mtx::accessors::relations(event).relations) {
auto related = events.get(r.event_id, id); auto related = events.get(r.event_id, id);
if (related) { if (related) {
relatedEvents.emplace_back(r, relatedEvents.emplace_back(r, *related);
mtx::events::collections::TimelineEvent{*related});
} }
} }
@ -1790,7 +1789,7 @@ TimelineModel::openMedia(const QString &eventId)
bool bool
TimelineModel::saveMedia(const QString &eventId) const TimelineModel::saveMedia(const QString &eventId) const
{ {
mtx::events::collections::TimelineEvents *event = events.get(eventId.toStdString(), ""); auto event = events.get(eventId.toStdString(), "");
if (!event) if (!event)
return false; return false;
@ -1865,7 +1864,7 @@ void
TimelineModel::cacheMedia(const QString &eventId, TimelineModel::cacheMedia(const QString &eventId,
const std::function<void(const QString)> &callback) const std::function<void(const QString)> &callback)
{ {
mtx::events::collections::TimelineEvents *event = events.get(eventId.toStdString(), ""); auto event = events.get(eventId.toStdString(), "");
if (!event) if (!event)
return; return;
@ -2150,7 +2149,7 @@ TimelineModel::formatTypingUsers(const std::vector<QString> &users, const QColor
QString QString
TimelineModel::formatJoinRuleEvent(const QString &id) TimelineModel::formatJoinRuleEvent(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); auto e = events.get(id.toStdString(), "");
if (!e) if (!e)
return {}; return {};
@ -2187,7 +2186,7 @@ TimelineModel::formatJoinRuleEvent(const QString &id)
QString QString
TimelineModel::formatGuestAccessEvent(const QString &id) TimelineModel::formatGuestAccessEvent(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); auto e = events.get(id.toStdString(), "");
if (!e) if (!e)
return {}; return {};
@ -2211,7 +2210,7 @@ TimelineModel::formatGuestAccessEvent(const QString &id)
QString QString
TimelineModel::formatHistoryVisibilityEvent(const QString &id) TimelineModel::formatHistoryVisibilityEvent(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); auto e = events.get(id.toStdString(), "");
if (!e) if (!e)
return {}; return {};
@ -2243,7 +2242,7 @@ TimelineModel::formatHistoryVisibilityEvent(const QString &id)
QString QString
TimelineModel::formatPowerLevelEvent(const QString &id) TimelineModel::formatPowerLevelEvent(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); auto e = events.get(id.toStdString(), "");
if (!e) if (!e)
return {}; return {};
@ -2251,7 +2250,7 @@ TimelineModel::formatPowerLevelEvent(const QString &id)
if (!event) if (!event)
return QString(); return QString();
mtx::events::StateEvent<mtx::events::state::PowerLevels> *prevEvent = nullptr; mtx::events::StateEvent<mtx::events::state::PowerLevels> const *prevEvent = nullptr;
if (!event->unsigned_data.replaces_state.empty()) { if (!event->unsigned_data.replaces_state.empty()) {
auto tempPrevEvent = events.get(event->unsigned_data.replaces_state, event->event_id); auto tempPrevEvent = events.get(event->unsigned_data.replaces_state, event->event_id);
if (tempPrevEvent) { if (tempPrevEvent) {
@ -2519,7 +2518,7 @@ TimelineModel::formatPowerLevelEvent(const QString &id)
QString QString
TimelineModel::formatImagePackEvent(const QString &id) TimelineModel::formatImagePackEvent(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); auto e = events.get(id.toStdString(), "");
if (!e) if (!e)
return {}; return {};
@ -2527,7 +2526,7 @@ TimelineModel::formatImagePackEvent(const QString &id)
if (!event) if (!event)
return {}; return {};
mtx::events::StateEvent<mtx::events::msc2545::ImagePack> *prevEvent = nullptr; mtx::events::StateEvent<mtx::events::msc2545::ImagePack> const *prevEvent = nullptr;
if (!event->unsigned_data.replaces_state.empty()) { if (!event->unsigned_data.replaces_state.empty()) {
auto tempPrevEvent = events.get(event->unsigned_data.replaces_state, event->event_id); auto tempPrevEvent = events.get(event->unsigned_data.replaces_state, event->event_id);
if (tempPrevEvent) { if (tempPrevEvent) {
@ -2592,7 +2591,7 @@ QString
TimelineModel::formatPolicyRule(const QString &id) TimelineModel::formatPolicyRule(const QString &id)
{ {
auto idStr = id.toStdString(); auto idStr = id.toStdString();
mtx::events::collections::TimelineEvents *e = events.get(idStr, ""); auto e = events.get(idStr, "");
if (!e) if (!e)
return {}; return {};
@ -2683,7 +2682,7 @@ QVariantMap
TimelineModel::formatRedactedEvent(const QString &id) TimelineModel::formatRedactedEvent(const QString &id)
{ {
QVariantMap pair{{"first", ""}, {"second", ""}}; QVariantMap pair{{"first", ""}, {"second", ""}};
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); auto e = events.get(id.toStdString(), "");
if (!e) if (!e)
return pair; return pair;
@ -2720,7 +2719,7 @@ TimelineModel::formatRedactedEvent(const QString &id)
void void
TimelineModel::acceptKnock(const QString &id) TimelineModel::acceptKnock(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); auto e = events.get(id.toStdString(), "");
if (!e) if (!e)
return; return;
@ -2745,7 +2744,7 @@ TimelineModel::acceptKnock(const QString &id)
bool bool
TimelineModel::showAcceptKnockButton(const QString &id) TimelineModel::showAcceptKnockButton(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); auto e = events.get(id.toStdString(), "");
if (!e) if (!e)
return false; return false;
@ -2766,7 +2765,7 @@ TimelineModel::showAcceptKnockButton(const QString &id)
void void
TimelineModel::joinReplacementRoom(const QString &id) TimelineModel::joinReplacementRoom(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); auto e = events.get(id.toStdString(), "");
if (!e) if (!e)
return; return;
@ -2792,7 +2791,7 @@ TimelineModel::joinReplacementRoom(const QString &id)
QString QString
TimelineModel::formatMemberEvent(const QString &id) TimelineModel::formatMemberEvent(const QString &id)
{ {
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); auto e = events.get(id.toStdString(), "");
if (!e) if (!e)
return {}; return {};
@ -2800,7 +2799,7 @@ TimelineModel::formatMemberEvent(const QString &id)
if (!event) if (!event)
return {}; return {};
mtx::events::StateEvent<mtx::events::state::Member> *prevEvent = nullptr; mtx::events::StateEvent<mtx::events::state::Member> const *prevEvent = nullptr;
if (!event->unsigned_data.replaces_state.empty()) { if (!event->unsigned_data.replaces_state.empty()) {
auto tempPrevEvent = events.get(event->unsigned_data.replaces_state, event->event_id); auto tempPrevEvent = events.get(event->unsigned_data.replaces_state, event->event_id);
if (tempPrevEvent) { if (tempPrevEvent) {

View file

@ -483,7 +483,7 @@ signals:
void isDirectChanged(); void isDirectChanged();
void directChatOtherUserIdChanged(); void directChatOtherUserIdChanged();
void permissionsChanged(); void permissionsChanged();
void forwardToRoom(mtx::events::collections::TimelineEvents *e, QString roomId); void forwardToRoom(mtx::events::collections::TimelineEvents const *e, QString roomId);
void scrollTargetChanged(); void scrollTargetChanged();

View file

@ -461,7 +461,7 @@ TimelineViewManager::completerFor(const QString &completerName, const QString &r
} }
void void
TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEvents *e, TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEvents const *e,
QString roomId) QString roomId)
{ {
auto room = rooms_->getRoomById(roomId); auto room = rooms_->getRoomById(roomId);

View file

@ -113,7 +113,7 @@ public slots:
QObject *completerFor(const QString &completerName, QObject *completerFor(const QString &completerName,
const QString &roomId = QLatin1String(QLatin1String(""))); const QString &roomId = QLatin1String(QLatin1String("")));
void forwardMessageToRoom(mtx::events::collections::TimelineEvents *e, QString roomId); void forwardMessageToRoom(mtx::events::collections::TimelineEvents const *e, QString roomId);
RoomlistModel *rooms() { return rooms_; } RoomlistModel *rooms() { return rooms_; }