mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 03:00:46 +03:00
Get rid of 'using json = nlohmann::json'
This commit is contained in:
parent
b0c353c550
commit
8cdfbf9391
10 changed files with 198 additions and 187 deletions
|
@ -579,7 +579,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 d34fb853256c5d3779f6a837e17ee2583d1c4089
|
GIT_TAG b26cd34fe8806f14a1daff2ca4f98474863acf9b
|
||||||
)
|
)
|
||||||
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 "")
|
||||||
|
|
|
@ -203,7 +203,7 @@ modules:
|
||||||
buildsystem: cmake-ninja
|
buildsystem: cmake-ninja
|
||||||
name: mtxclient
|
name: mtxclient
|
||||||
sources:
|
sources:
|
||||||
- commit: d34fb853256c5d3779f6a837e17ee2583d1c4089
|
- commit: b26cd34fe8806f14a1daff2ca4f98474863acf9b
|
||||||
#tag: v0.7.0
|
#tag: v0.7.0
|
||||||
type: git
|
type: git
|
||||||
url: https://github.com/Nheko-Reborn/mtxclient.git
|
url: https://github.com/Nheko-Reborn/mtxclient.git
|
||||||
|
|
296
src/Cache.cpp
296
src/Cache.cpp
|
@ -561,10 +561,11 @@ Cache::roomEncryptionSettings(const std::string &room_id)
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
StateEvent<Encryption> msg = json::parse(event).get<StateEvent<Encryption>>();
|
StateEvent<Encryption> msg =
|
||||||
|
nlohmann::json::parse(event).get<StateEvent<Encryption>>();
|
||||||
|
|
||||||
return msg.content;
|
return msg.content;
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse m.room.encryption event: {}", e.what());
|
nhlog::db()->warn("failed to parse m.room.encryption event: {}", e.what());
|
||||||
return Encryption{};
|
return Encryption{};
|
||||||
}
|
}
|
||||||
|
@ -603,7 +604,7 @@ Cache::exportSessionKeys()
|
||||||
using namespace mtx::crypto;
|
using namespace mtx::crypto;
|
||||||
|
|
||||||
std::string_view v;
|
std::string_view v;
|
||||||
if (megolmSessionDataDb_.get(txn, json(index).dump(), v)) {
|
if (megolmSessionDataDb_.get(txn, nlohmann::json(index).dump(), v)) {
|
||||||
auto data = nlohmann::json::parse(v).get<GroupSessionData>();
|
auto data = nlohmann::json::parse(v).get<GroupSessionData>();
|
||||||
exported.sender_key = data.sender_key;
|
exported.sender_key = data.sender_key;
|
||||||
if (!data.sender_claimed_ed25519_key.empty())
|
if (!data.sender_claimed_ed25519_key.empty())
|
||||||
|
@ -661,7 +662,7 @@ Cache::saveInboundMegolmSession(const MegolmSessionIndex &index,
|
||||||
const GroupSessionData &data)
|
const GroupSessionData &data)
|
||||||
{
|
{
|
||||||
using namespace mtx::crypto;
|
using namespace mtx::crypto;
|
||||||
const auto key = json(index).dump();
|
const auto key = nlohmann::json(index).dump();
|
||||||
const auto pickled = pickle<InboundSessionObject>(session.get(), pickle_secret_);
|
const auto pickled = pickle<InboundSessionObject>(session.get(), pickle_secret_);
|
||||||
|
|
||||||
auto txn = lmdb::txn::begin(env_);
|
auto txn = lmdb::txn::begin(env_);
|
||||||
|
@ -677,7 +678,7 @@ Cache::saveInboundMegolmSession(const MegolmSessionIndex &index,
|
||||||
}
|
}
|
||||||
|
|
||||||
inboundMegolmSessionDb_.put(txn, key, pickled);
|
inboundMegolmSessionDb_.put(txn, key, pickled);
|
||||||
megolmSessionDataDb_.put(txn, key, json(data).dump());
|
megolmSessionDataDb_.put(txn, key, nlohmann::json(data).dump());
|
||||||
txn.commit();
|
txn.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -688,7 +689,7 @@ Cache::getInboundMegolmSession(const MegolmSessionIndex &index)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto txn = ro_txn(env_);
|
auto txn = ro_txn(env_);
|
||||||
std::string key = json(index).dump();
|
std::string key = nlohmann::json(index).dump();
|
||||||
std::string_view value;
|
std::string_view value;
|
||||||
|
|
||||||
if (inboundMegolmSessionDb_.get(txn, key, value)) {
|
if (inboundMegolmSessionDb_.get(txn, key, value)) {
|
||||||
|
@ -709,7 +710,7 @@ Cache::inboundMegolmSessionExists(const MegolmSessionIndex &index)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto txn = ro_txn(env_);
|
auto txn = ro_txn(env_);
|
||||||
std::string key = json(index).dump();
|
std::string key = nlohmann::json(index).dump();
|
||||||
std::string_view value;
|
std::string_view value;
|
||||||
|
|
||||||
return inboundMegolmSessionDb_.get(txn, key, value);
|
return inboundMegolmSessionDb_.get(txn, key, value);
|
||||||
|
@ -737,12 +738,12 @@ Cache::updateOutboundMegolmSession(const std::string &room_id,
|
||||||
index.session_id = mtx::crypto::session_id(ptr.get());
|
index.session_id = mtx::crypto::session_id(ptr.get());
|
||||||
|
|
||||||
// Save the updated pickled data for the session.
|
// Save the updated pickled data for the session.
|
||||||
json j;
|
nlohmann::json j;
|
||||||
j["session"] = pickle<OutboundSessionObject>(ptr.get(), pickle_secret_);
|
j["session"] = pickle<OutboundSessionObject>(ptr.get(), pickle_secret_);
|
||||||
|
|
||||||
auto txn = lmdb::txn::begin(env_);
|
auto txn = lmdb::txn::begin(env_);
|
||||||
outboundMegolmSessionDb_.put(txn, room_id, j.dump());
|
outboundMegolmSessionDb_.put(txn, room_id, j.dump());
|
||||||
megolmSessionDataDb_.put(txn, json(index).dump(), json(data).dump());
|
megolmSessionDataDb_.put(txn, nlohmann::json(index).dump(), nlohmann::json(data).dump());
|
||||||
txn.commit();
|
txn.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -776,12 +777,12 @@ Cache::saveOutboundMegolmSession(const std::string &room_id,
|
||||||
index.room_id = room_id;
|
index.room_id = room_id;
|
||||||
index.session_id = mtx::crypto::session_id(session.get());
|
index.session_id = mtx::crypto::session_id(session.get());
|
||||||
|
|
||||||
json j;
|
nlohmann::json j;
|
||||||
j["session"] = pickled;
|
j["session"] = pickled;
|
||||||
|
|
||||||
auto txn = lmdb::txn::begin(env_);
|
auto txn = lmdb::txn::begin(env_);
|
||||||
outboundMegolmSessionDb_.put(txn, room_id, j.dump());
|
outboundMegolmSessionDb_.put(txn, room_id, j.dump());
|
||||||
megolmSessionDataDb_.put(txn, json(index).dump(), json(data).dump());
|
megolmSessionDataDb_.put(txn, nlohmann::json(index).dump(), nlohmann::json(data).dump());
|
||||||
txn.commit();
|
txn.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -807,7 +808,7 @@ Cache::getOutboundMegolmSession(const std::string &room_id)
|
||||||
auto txn = ro_txn(env_);
|
auto txn = ro_txn(env_);
|
||||||
std::string_view value;
|
std::string_view value;
|
||||||
outboundMegolmSessionDb_.get(txn, room_id, value);
|
outboundMegolmSessionDb_.get(txn, room_id, value);
|
||||||
auto obj = json::parse(value);
|
auto obj = nlohmann::json::parse(value);
|
||||||
|
|
||||||
OutboundGroupSessionDataRef ref{};
|
OutboundGroupSessionDataRef ref{};
|
||||||
ref.session =
|
ref.session =
|
||||||
|
@ -817,7 +818,7 @@ Cache::getOutboundMegolmSession(const std::string &room_id)
|
||||||
index.room_id = room_id;
|
index.room_id = room_id;
|
||||||
index.session_id = mtx::crypto::session_id(ref.session.get());
|
index.session_id = mtx::crypto::session_id(ref.session.get());
|
||||||
|
|
||||||
if (megolmSessionDataDb_.get(txn, json(index).dump(), value)) {
|
if (megolmSessionDataDb_.get(txn, nlohmann::json(index).dump(), value)) {
|
||||||
ref.data = nlohmann::json::parse(value).get<GroupSessionData>();
|
ref.data = nlohmann::json::parse(value).get<GroupSessionData>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -837,7 +838,7 @@ Cache::getMegolmSessionData(const MegolmSessionIndex &index)
|
||||||
auto txn = ro_txn(env_);
|
auto txn = ro_txn(env_);
|
||||||
|
|
||||||
std::string_view value;
|
std::string_view value;
|
||||||
if (megolmSessionDataDb_.get(txn, json(index).dump(), value)) {
|
if (megolmSessionDataDb_.get(txn, nlohmann::json(index).dump(), value)) {
|
||||||
return nlohmann::json::parse(value).get<GroupSessionData>();
|
return nlohmann::json::parse(value).get<GroupSessionData>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -868,7 +869,7 @@ Cache::saveOlmSession(const std::string &curve25519,
|
||||||
stored_session.pickled_session = pickled;
|
stored_session.pickled_session = pickled;
|
||||||
stored_session.last_message_ts = timestamp;
|
stored_session.last_message_ts = timestamp;
|
||||||
|
|
||||||
db.put(txn, session_id, json(stored_session).dump());
|
db.put(txn, session_id, nlohmann::json(stored_session).dump());
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
}
|
}
|
||||||
|
@ -887,7 +888,7 @@ Cache::getOlmSession(const std::string &curve25519, const std::string &session_i
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
auto data = json::parse(pickled).get<StoredOlmSession>();
|
auto data = nlohmann::json::parse(pickled).get<StoredOlmSession>();
|
||||||
return unpickle<SessionObject>(data.pickled_session, pickle_secret_);
|
return unpickle<SessionObject>(data.pickled_session, pickle_secret_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -908,7 +909,7 @@ Cache::getLatestOlmSession(const std::string &curve25519)
|
||||||
|
|
||||||
auto cursor = lmdb::cursor::open(txn, db);
|
auto cursor = lmdb::cursor::open(txn, db);
|
||||||
while (cursor.get(session_id, pickled_session, MDB_NEXT)) {
|
while (cursor.get(session_id, pickled_session, MDB_NEXT)) {
|
||||||
auto data = json::parse(pickled_session).get<StoredOlmSession>();
|
auto data = nlohmann::json::parse(pickled_session).get<StoredOlmSession>();
|
||||||
if (!currentNewest || currentNewest->last_message_ts < data.last_message_ts)
|
if (!currentNewest || currentNewest->last_message_ts < data.last_message_ts)
|
||||||
currentNewest = data;
|
currentNewest = data;
|
||||||
}
|
}
|
||||||
|
@ -1151,7 +1152,7 @@ Cache::runMigrations()
|
||||||
roomsCursor.get(ts, stored_message, start ? MDB_FIRST : MDB_NEXT)) {
|
roomsCursor.get(ts, stored_message, start ? MDB_FIRST : MDB_NEXT)) {
|
||||||
start = false;
|
start = false;
|
||||||
|
|
||||||
auto j = json::parse(
|
auto j = nlohmann::json::parse(
|
||||||
std::string_view(stored_message.data(), stored_message.size()));
|
std::string_view(stored_message.data(), stored_message.size()));
|
||||||
|
|
||||||
if (oldMessages.prev_batch.empty())
|
if (oldMessages.prev_batch.empty())
|
||||||
|
@ -1242,8 +1243,8 @@ Cache::runMigrations()
|
||||||
auto newDb = lmdb::dbi::open(txn, newDbName.c_str(), MDB_CREATE);
|
auto newDb = lmdb::dbi::open(txn, newDbName.c_str(), MDB_CREATE);
|
||||||
|
|
||||||
for (const auto &[key, value] : sessions) {
|
for (const auto &[key, value] : sessions) {
|
||||||
// nhlog::db()->debug("{}\n{}", key, json(value).dump());
|
// nhlog::db()->debug("{}\n{}", key, nlohmann::json(value).dump());
|
||||||
newDb.put(txn, key, json(value).dump());
|
newDb.put(txn, key, nlohmann::json(value).dump());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
olmDbCursor.close();
|
olmDbCursor.close();
|
||||||
|
@ -1420,8 +1421,9 @@ Cache::readReceipts(const QString &event_id, const QString &room_id)
|
||||||
bool res = readReceiptsDb_.get(txn, key, value);
|
bool res = readReceiptsDb_.get(txn, key, value);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
auto json_response = json::parse(std::string_view(value.data(), value.size()));
|
auto json_response =
|
||||||
auto values = json_response.get<std::map<std::string, uint64_t>>();
|
nlohmann::json::parse(std::string_view(value.data(), value.size()));
|
||||||
|
auto values = json_response.get<std::map<std::string, uint64_t>>();
|
||||||
|
|
||||||
for (const auto &v : values)
|
for (const auto &v : values)
|
||||||
// timestamp, user_id
|
// timestamp, user_id
|
||||||
|
@ -1459,7 +1461,7 @@ Cache::updateReadReceipt(lmdb::txn &txn, const std::string &room_id, const Recei
|
||||||
// merge the existing receipts with the new ones.
|
// merge the existing receipts with the new ones.
|
||||||
if (exists) {
|
if (exists) {
|
||||||
auto json_value =
|
auto json_value =
|
||||||
json::parse(std::string_view(prev_value.data(), prev_value.size()));
|
nlohmann::json::parse(std::string_view(prev_value.data(), prev_value.size()));
|
||||||
|
|
||||||
// Retrieve the saved receipts.
|
// Retrieve the saved receipts.
|
||||||
saved_receipts = json_value.get<std::map<std::string, uint64_t>>();
|
saved_receipts = json_value.get<std::map<std::string, uint64_t>>();
|
||||||
|
@ -1551,8 +1553,8 @@ Cache::updateState(const std::string &room, const mtx::responses::StateEvents &s
|
||||||
if (roomsDb_.get(txn, room, data)) {
|
if (roomsDb_.get(txn, room, data)) {
|
||||||
try {
|
try {
|
||||||
updatedInfo =
|
updatedInfo =
|
||||||
json::parse(std::string_view(data.data(), data.size())).get<RoomInfo>();
|
nlohmann::json::parse(std::string_view(data.data(), data.size())).get<RoomInfo>();
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
|
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
|
||||||
room,
|
room,
|
||||||
std::string(data.data(), data.size()),
|
std::string(data.data(), data.size()),
|
||||||
|
@ -1567,7 +1569,7 @@ Cache::updateState(const std::string &room, const mtx::responses::StateEvents &s
|
||||||
updatedInfo.version = getRoomVersion(txn, statesdb).toStdString();
|
updatedInfo.version = getRoomVersion(txn, statesdb).toStdString();
|
||||||
updatedInfo.is_space = getRoomIsSpace(txn, statesdb);
|
updatedInfo.is_space = getRoomIsSpace(txn, statesdb);
|
||||||
|
|
||||||
roomsDb_.put(txn, room, json(updatedInfo).dump());
|
roomsDb_.put(txn, room, nlohmann::json(updatedInfo).dump());
|
||||||
updateSpaces(txn, {room}, {room});
|
updateSpaces(txn, {room}, {room});
|
||||||
txn.commit();
|
txn.commit();
|
||||||
}
|
}
|
||||||
|
@ -1640,7 +1642,7 @@ Cache::saveState(const mtx::responses::Sync &res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto j = json(event);
|
auto j = nlohmann::json(event);
|
||||||
accountDataDb.put(txn, j["type"].get<std::string>(), j.dump());
|
accountDataDb.put(txn, j["type"].get<std::string>(), j.dump());
|
||||||
},
|
},
|
||||||
ev);
|
ev);
|
||||||
|
@ -1671,13 +1673,13 @@ Cache::saveState(const mtx::responses::Sync &res)
|
||||||
std::string_view data;
|
std::string_view data;
|
||||||
if (roomsDb_.get(txn, room.first, data)) {
|
if (roomsDb_.get(txn, room.first, data)) {
|
||||||
try {
|
try {
|
||||||
RoomInfo tmp =
|
RoomInfo tmp = nlohmann::json::parse(std::string_view(data.data(), data.size()))
|
||||||
json::parse(std::string_view(data.data(), data.size())).get<RoomInfo>();
|
.get<RoomInfo>();
|
||||||
updatedInfo.tags = std::move(tmp.tags);
|
updatedInfo.tags = std::move(tmp.tags);
|
||||||
|
|
||||||
updatedInfo.approximate_last_modification_ts =
|
updatedInfo.approximate_last_modification_ts =
|
||||||
tmp.approximate_last_modification_ts;
|
tmp.approximate_last_modification_ts;
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
|
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
|
||||||
room.first,
|
room.first,
|
||||||
std::string(data.data(), data.size()),
|
std::string(data.data(), data.size()),
|
||||||
|
@ -1745,7 +1747,7 @@ Cache::saveState(const mtx::responses::Sync &res)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto j = json(event);
|
auto j = nlohmann::json(event);
|
||||||
accountDataDb.put(txn, j["type"].get<std::string>(), j.dump());
|
accountDataDb.put(txn, j["type"].get<std::string>(), j.dump());
|
||||||
},
|
},
|
||||||
evt);
|
evt);
|
||||||
|
@ -1775,7 +1777,7 @@ Cache::saveState(const mtx::responses::Sync &res)
|
||||||
mtx::accessors::origin_server_ts(e).toMSecsSinceEpoch();
|
mtx::accessors::origin_server_ts(e).toMSecsSinceEpoch();
|
||||||
}
|
}
|
||||||
|
|
||||||
roomsDb_.put(txn, room.first, json(updatedInfo).dump());
|
roomsDb_.put(txn, room.first, nlohmann::json(updatedInfo).dump());
|
||||||
|
|
||||||
for (const auto &e : room.second.ephemeral.events) {
|
for (const auto &e : room.second.ephemeral.events) {
|
||||||
if (auto receiptsEv =
|
if (auto receiptsEv =
|
||||||
|
@ -1863,7 +1865,7 @@ Cache::saveInvites(lmdb::txn &txn, const std::map<std::string, mtx::responses::I
|
||||||
updatedInfo.is_space = getInviteRoomIsSpace(txn, statesdb);
|
updatedInfo.is_space = getInviteRoomIsSpace(txn, statesdb);
|
||||||
updatedInfo.is_invite = true;
|
updatedInfo.is_invite = true;
|
||||||
|
|
||||||
invitesDb_.put(txn, room.first, json(updatedInfo).dump());
|
invitesDb_.put(txn, room.first, nlohmann::json(updatedInfo).dump());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1883,15 +1885,15 @@ Cache::saveInvite(lmdb::txn &txn,
|
||||||
|
|
||||||
MemberInfo tmp{display_name, msg->content.avatar_url, msg->content.is_direct};
|
MemberInfo tmp{display_name, msg->content.avatar_url, msg->content.is_direct};
|
||||||
|
|
||||||
membersdb.put(txn, msg->state_key, json(tmp).dump());
|
membersdb.put(txn, msg->state_key, nlohmann::json(tmp).dump());
|
||||||
} else {
|
} else {
|
||||||
std::visit(
|
std::visit(
|
||||||
[&txn, &statesdb](auto msg) {
|
[&txn, &statesdb](auto msg) {
|
||||||
auto j = json(msg);
|
auto j = nlohmann::json(msg);
|
||||||
bool res = statesdb.put(txn, j["type"].get<std::string>(), j.dump());
|
bool res = statesdb.put(txn, j["type"].get<std::string>(), j.dump());
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
nhlog::db()->warn("couldn't save data: {}", json(msg).dump());
|
nhlog::db()->warn("couldn't save data: {}", nlohmann::json(msg).dump());
|
||||||
},
|
},
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
|
@ -1904,7 +1906,7 @@ Cache::savePresence(
|
||||||
const std::vector<mtx::events::Event<mtx::events::presence::Presence>> &presenceUpdates)
|
const std::vector<mtx::events::Event<mtx::events::presence::Presence>> &presenceUpdates)
|
||||||
{
|
{
|
||||||
for (const auto &update : presenceUpdates) {
|
for (const auto &update : presenceUpdates) {
|
||||||
presenceDb_.put(txn, update.sender, json(update.content).dump());
|
presenceDb_.put(txn, update.sender, nlohmann::json(update.content).dump());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1957,13 +1959,13 @@ Cache::singleRoomInfo(const std::string &room_id)
|
||||||
// Check if the room is joined.
|
// Check if the room is joined.
|
||||||
if (roomsDb_.get(txn, room_id, data)) {
|
if (roomsDb_.get(txn, room_id, data)) {
|
||||||
try {
|
try {
|
||||||
RoomInfo tmp = json::parse(data).get<RoomInfo>();
|
RoomInfo tmp = nlohmann::json::parse(data).get<RoomInfo>();
|
||||||
tmp.member_count = getMembersDb(txn, room_id).size(txn);
|
tmp.member_count = getMembersDb(txn, room_id).size(txn);
|
||||||
tmp.join_rule = getRoomJoinRule(txn, statesdb);
|
tmp.join_rule = getRoomJoinRule(txn, statesdb);
|
||||||
tmp.guest_access = getRoomGuestAccess(txn, statesdb);
|
tmp.guest_access = getRoomGuestAccess(txn, statesdb);
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
|
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
|
||||||
room_id,
|
room_id,
|
||||||
std::string(data.data(), data.size()),
|
std::string(data.data(), data.size()),
|
||||||
|
@ -1992,13 +1994,13 @@ Cache::getRoomInfo(const std::vector<std::string> &rooms)
|
||||||
// Check if the room is joined.
|
// Check if the room is joined.
|
||||||
if (roomsDb_.get(txn, room, data)) {
|
if (roomsDb_.get(txn, room, data)) {
|
||||||
try {
|
try {
|
||||||
RoomInfo tmp = json::parse(data).get<RoomInfo>();
|
RoomInfo tmp = nlohmann::json::parse(data).get<RoomInfo>();
|
||||||
tmp.member_count = getMembersDb(txn, room).size(txn);
|
tmp.member_count = getMembersDb(txn, room).size(txn);
|
||||||
tmp.join_rule = getRoomJoinRule(txn, statesdb);
|
tmp.join_rule = getRoomJoinRule(txn, statesdb);
|
||||||
tmp.guest_access = getRoomGuestAccess(txn, statesdb);
|
tmp.guest_access = getRoomGuestAccess(txn, statesdb);
|
||||||
|
|
||||||
room_info.emplace(QString::fromStdString(room), std::move(tmp));
|
room_info.emplace(QString::fromStdString(room), std::move(tmp));
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
|
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
|
||||||
room,
|
room,
|
||||||
std::string(data.data(), data.size()),
|
std::string(data.data(), data.size()),
|
||||||
|
@ -2008,11 +2010,11 @@ Cache::getRoomInfo(const std::vector<std::string> &rooms)
|
||||||
// Check if the room is an invite.
|
// Check if the room is an invite.
|
||||||
if (invitesDb_.get(txn, room, data)) {
|
if (invitesDb_.get(txn, room, data)) {
|
||||||
try {
|
try {
|
||||||
RoomInfo tmp = json::parse(std::string_view(data)).get<RoomInfo>();
|
RoomInfo tmp = nlohmann::json::parse(std::string_view(data)).get<RoomInfo>();
|
||||||
tmp.member_count = getInviteMembersDb(txn, room).size(txn);
|
tmp.member_count = getInviteMembersDb(txn, room).size(txn);
|
||||||
|
|
||||||
room_info.emplace(QString::fromStdString(room), std::move(tmp));
|
room_info.emplace(QString::fromStdString(room), std::move(tmp));
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse room info for invite: "
|
nhlog::db()->warn("failed to parse room info for invite: "
|
||||||
"room_id ({}), {}: {}",
|
"room_id ({}), {}: {}",
|
||||||
room,
|
room,
|
||||||
|
@ -2078,7 +2080,7 @@ Cache::previousBatchToken(const std::string &room_id)
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto j = json::parse(val);
|
auto j = nlohmann::json::parse(val);
|
||||||
|
|
||||||
return j.value("prev_batch", "");
|
return j.value("prev_batch", "");
|
||||||
}
|
}
|
||||||
|
@ -2122,7 +2124,7 @@ Cache::getTimelineMessages(lmdb::txn &txn, const std::string &room_id, uint64_t
|
||||||
|
|
||||||
mtx::events::collections::TimelineEvent te;
|
mtx::events::collections::TimelineEvent te;
|
||||||
try {
|
try {
|
||||||
mtx::events::collections::from_json(json::parse(event), te);
|
mtx::events::collections::from_json(nlohmann::json::parse(event), te);
|
||||||
} 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;
|
||||||
|
@ -2152,7 +2154,7 @@ Cache::getEvent(const std::string &room_id, const std::string &event_id)
|
||||||
|
|
||||||
mtx::events::collections::TimelineEvent te;
|
mtx::events::collections::TimelineEvent te;
|
||||||
try {
|
try {
|
||||||
mtx::events::collections::from_json(json::parse(event), te);
|
mtx::events::collections::from_json(nlohmann::json::parse(event), te);
|
||||||
} 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;
|
||||||
|
@ -2244,7 +2246,7 @@ Cache::roomInfo(bool withInvites)
|
||||||
// Gather info about the joined rooms.
|
// Gather info about the joined rooms.
|
||||||
auto roomsCursor = lmdb::cursor::open(txn, roomsDb_);
|
auto roomsCursor = lmdb::cursor::open(txn, roomsDb_);
|
||||||
while (roomsCursor.get(room_id, room_data, MDB_NEXT)) {
|
while (roomsCursor.get(room_id, room_data, MDB_NEXT)) {
|
||||||
RoomInfo tmp = json::parse(std::move(room_data)).get<RoomInfo>();
|
RoomInfo tmp = nlohmann::json::parse(std::move(room_data)).get<RoomInfo>();
|
||||||
tmp.member_count = getMembersDb(txn, std::string(room_id)).size(txn);
|
tmp.member_count = getMembersDb(txn, std::string(room_id)).size(txn);
|
||||||
result.insert(QString::fromStdString(std::string(room_id)), std::move(tmp));
|
result.insert(QString::fromStdString(std::string(room_id)), std::move(tmp));
|
||||||
}
|
}
|
||||||
|
@ -2254,7 +2256,7 @@ Cache::roomInfo(bool withInvites)
|
||||||
// Gather info about the invites.
|
// Gather info about the invites.
|
||||||
auto invitesCursor = lmdb::cursor::open(txn, invitesDb_);
|
auto invitesCursor = lmdb::cursor::open(txn, invitesDb_);
|
||||||
while (invitesCursor.get(room_id, room_data, MDB_NEXT)) {
|
while (invitesCursor.get(room_id, room_data, MDB_NEXT)) {
|
||||||
RoomInfo tmp = json::parse(room_data).get<RoomInfo>();
|
RoomInfo tmp = nlohmann::json::parse(room_data).get<RoomInfo>();
|
||||||
tmp.member_count = getInviteMembersDb(txn, std::string(room_id)).size(txn);
|
tmp.member_count = getInviteMembersDb(txn, std::string(room_id)).size(txn);
|
||||||
result.insert(QString::fromStdString(std::string(room_id)), std::move(tmp));
|
result.insert(QString::fromStdString(std::string(room_id)), std::move(tmp));
|
||||||
}
|
}
|
||||||
|
@ -2405,7 +2407,7 @@ Cache::lastInvisibleEventAfter(const std::string &room_id, std::string_view even
|
||||||
auto cursor = lmdb::cursor::open(txn, eventOrderDb);
|
auto cursor = lmdb::cursor::open(txn, eventOrderDb);
|
||||||
cursor.get(indexVal, MDB_SET);
|
cursor.get(indexVal, MDB_SET);
|
||||||
while (cursor.get(indexVal, event_id, MDB_NEXT)) {
|
while (cursor.get(indexVal, event_id, MDB_NEXT)) {
|
||||||
std::string evId = json::parse(event_id)["event_id"].get<std::string>();
|
std::string evId = nlohmann::json::parse(event_id)["event_id"].get<std::string>();
|
||||||
std::string_view temp;
|
std::string_view temp;
|
||||||
if (timelineDb.get(txn, evId, temp)) {
|
if (timelineDb.get(txn, evId, temp)) {
|
||||||
return std::pair{prevIdx, std::string(prevId)};
|
return std::pair{prevIdx, std::string(prevId)};
|
||||||
|
@ -2481,10 +2483,10 @@ Cache::invites()
|
||||||
|
|
||||||
while (cursor.get(room_id, room_data, MDB_NEXT)) {
|
while (cursor.get(room_id, room_data, MDB_NEXT)) {
|
||||||
try {
|
try {
|
||||||
RoomInfo tmp = json::parse(room_data).get<RoomInfo>();
|
RoomInfo tmp = nlohmann::json::parse(room_data).get<RoomInfo>();
|
||||||
tmp.member_count = getInviteMembersDb(txn, std::string(room_id)).size(txn);
|
tmp.member_count = getInviteMembersDb(txn, std::string(room_id)).size(txn);
|
||||||
result.insert(QString::fromStdString(std::string(room_id)), std::move(tmp));
|
result.insert(QString::fromStdString(std::string(room_id)), std::move(tmp));
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse room info for invite: "
|
nhlog::db()->warn("failed to parse room info for invite: "
|
||||||
"room_id ({}), {}: {}",
|
"room_id ({}), {}: {}",
|
||||||
room_id,
|
room_id,
|
||||||
|
@ -2509,10 +2511,10 @@ Cache::invite(std::string_view roomid)
|
||||||
|
|
||||||
if (invitesDb_.get(txn, roomid, room_data)) {
|
if (invitesDb_.get(txn, roomid, room_data)) {
|
||||||
try {
|
try {
|
||||||
RoomInfo tmp = json::parse(room_data).get<RoomInfo>();
|
RoomInfo tmp = nlohmann::json::parse(room_data).get<RoomInfo>();
|
||||||
tmp.member_count = getInviteMembersDb(txn, std::string(roomid)).size(txn);
|
tmp.member_count = getInviteMembersDb(txn, std::string(roomid)).size(txn);
|
||||||
result = std::move(tmp);
|
result = std::move(tmp);
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse room info for invite: "
|
nhlog::db()->warn("failed to parse room info for invite: "
|
||||||
"room_id ({}), {}: {}",
|
"room_id ({}), {}: {}",
|
||||||
roomid,
|
roomid,
|
||||||
|
@ -2536,11 +2538,12 @@ Cache::getRoomAvatarUrl(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersd
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
StateEvent<Avatar> msg =
|
StateEvent<Avatar> msg =
|
||||||
json::parse(std::string_view(event.data(), event.size())).get<StateEvent<Avatar>>();
|
nlohmann::json::parse(std::string_view(event.data(), event.size()))
|
||||||
|
.get<StateEvent<Avatar>>();
|
||||||
|
|
||||||
if (!msg.content.url.empty())
|
if (!msg.content.url.empty())
|
||||||
return QString::fromStdString(msg.content.url);
|
return QString::fromStdString(msg.content.url);
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse m.room.avatar event: {}", e.what());
|
nhlog::db()->warn("failed to parse m.room.avatar event: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2557,7 +2560,7 @@ Cache::getRoomAvatarUrl(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersd
|
||||||
// Resolve avatar for 1-1 chats.
|
// Resolve avatar for 1-1 chats.
|
||||||
while (cursor.get(user_id, member_data, MDB_NEXT)) {
|
while (cursor.get(user_id, member_data, MDB_NEXT)) {
|
||||||
try {
|
try {
|
||||||
MemberInfo m = json::parse(member_data).get<MemberInfo>();
|
MemberInfo m = nlohmann::json::parse(member_data).get<MemberInfo>();
|
||||||
if (user_id == localUserId_.toStdString()) {
|
if (user_id == localUserId_.toStdString()) {
|
||||||
fallback_url = m.avatar_url;
|
fallback_url = m.avatar_url;
|
||||||
continue;
|
continue;
|
||||||
|
@ -2565,7 +2568,7 @@ Cache::getRoomAvatarUrl(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersd
|
||||||
|
|
||||||
cursor.close();
|
cursor.close();
|
||||||
return QString::fromStdString(m.avatar_url);
|
return QString::fromStdString(m.avatar_url);
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse member info: {}", e.what());
|
nhlog::db()->warn("failed to parse member info: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2588,11 +2591,12 @@ Cache::getRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb)
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
StateEvent<Name> msg =
|
StateEvent<Name> msg =
|
||||||
json::parse(std::string_view(event.data(), event.size())).get<StateEvent<Name>>();
|
nlohmann::json::parse(std::string_view(event.data(), event.size()))
|
||||||
|
.get<StateEvent<Name>>();
|
||||||
|
|
||||||
if (!msg.content.name.empty())
|
if (!msg.content.name.empty())
|
||||||
return QString::fromStdString(msg.content.name);
|
return QString::fromStdString(msg.content.name);
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse m.room.name event: {}", e.what());
|
nhlog::db()->warn("failed to parse m.room.name event: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2602,12 +2606,12 @@ Cache::getRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb)
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
StateEvent<CanonicalAlias> msg =
|
StateEvent<CanonicalAlias> msg =
|
||||||
json::parse(std::string_view(event.data(), event.size()))
|
nlohmann::json::parse(std::string_view(event.data(), event.size()))
|
||||||
.get<StateEvent<CanonicalAlias>>();
|
.get<StateEvent<CanonicalAlias>>();
|
||||||
|
|
||||||
if (!msg.content.alias.empty())
|
if (!msg.content.alias.empty())
|
||||||
return QString::fromStdString(msg.content.alias);
|
return QString::fromStdString(msg.content.alias);
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse m.room.canonical_alias event: {}", e.what());
|
nhlog::db()->warn("failed to parse m.room.canonical_alias event: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2622,8 +2626,8 @@ Cache::getRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb)
|
||||||
|
|
||||||
while (cursor.get(user_id, member_data, MDB_NEXT) && ii < 3) {
|
while (cursor.get(user_id, member_data, MDB_NEXT) && ii < 3) {
|
||||||
try {
|
try {
|
||||||
members.emplace(user_id, json::parse(member_data).get<MemberInfo>());
|
members.emplace(user_id, nlohmann::json::parse(member_data).get<MemberInfo>());
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse member info: {}", e.what());
|
nhlog::db()->warn("failed to parse member info: {}", e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2664,9 +2668,9 @@ Cache::getRoomJoinRule(lmdb::txn &txn, lmdb::dbi &statesdb)
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
StateEvent<state::JoinRules> msg =
|
StateEvent<state::JoinRules> msg =
|
||||||
json::parse(event).get<StateEvent<state::JoinRules>>();
|
nlohmann::json::parse(event).get<StateEvent<state::JoinRules>>();
|
||||||
return msg.content.join_rule;
|
return msg.content.join_rule;
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse m.room.join_rule event: {}", e.what());
|
nhlog::db()->warn("failed to parse m.room.join_rule event: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2684,9 +2688,10 @@ Cache::getRoomGuestAccess(lmdb::txn &txn, lmdb::dbi &statesdb)
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
StateEvent<GuestAccess> msg = json::parse(event).get<StateEvent<GuestAccess>>();
|
StateEvent<GuestAccess> msg =
|
||||||
|
nlohmann::json::parse(event).get<StateEvent<GuestAccess>>();
|
||||||
return msg.content.guest_access == AccessState::CanJoin;
|
return msg.content.guest_access == AccessState::CanJoin;
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse m.room.guest_access event: {}", e.what());
|
nhlog::db()->warn("failed to parse m.room.guest_access event: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2704,11 +2709,11 @@ Cache::getRoomTopic(lmdb::txn &txn, lmdb::dbi &statesdb)
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
StateEvent<Topic> msg = json::parse(event).get<StateEvent<Topic>>();
|
StateEvent<Topic> msg = nlohmann::json::parse(event).get<StateEvent<Topic>>();
|
||||||
|
|
||||||
if (!msg.content.topic.empty())
|
if (!msg.content.topic.empty())
|
||||||
return QString::fromStdString(msg.content.topic);
|
return QString::fromStdString(msg.content.topic);
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse m.room.topic event: {}", e.what());
|
nhlog::db()->warn("failed to parse m.room.topic event: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2727,11 +2732,11 @@ Cache::getRoomVersion(lmdb::txn &txn, lmdb::dbi &statesdb)
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
StateEvent<Create> msg = json::parse(event).get<StateEvent<Create>>();
|
StateEvent<Create> msg = nlohmann::json::parse(event).get<StateEvent<Create>>();
|
||||||
|
|
||||||
if (!msg.content.room_version.empty())
|
if (!msg.content.room_version.empty())
|
||||||
return QString::fromStdString(msg.content.room_version);
|
return QString::fromStdString(msg.content.room_version);
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse m.room.create event: {}", e.what());
|
nhlog::db()->warn("failed to parse m.room.create event: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2751,10 +2756,10 @@ Cache::getRoomIsSpace(lmdb::txn &txn, lmdb::dbi &statesdb)
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
StateEvent<Create> msg = json::parse(event).get<StateEvent<Create>>();
|
StateEvent<Create> msg = nlohmann::json::parse(event).get<StateEvent<Create>>();
|
||||||
|
|
||||||
return msg.content.type == mtx::events::state::room_type::space;
|
return msg.content.type == mtx::events::state::room_type::space;
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse m.room.create event: {}", e.what());
|
nhlog::db()->warn("failed to parse m.room.create event: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2774,9 +2779,10 @@ Cache::getInviteRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &members
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
StrippedEvent<state::Name> msg = json::parse(event).get<StrippedEvent<state::Name>>();
|
StrippedEvent<state::Name> msg =
|
||||||
|
nlohmann::json::parse(event).get<StrippedEvent<state::Name>>();
|
||||||
return QString::fromStdString(msg.content.name);
|
return QString::fromStdString(msg.content.name);
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse m.room.name event: {}", e.what());
|
nhlog::db()->warn("failed to parse m.room.name event: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2789,11 +2795,11 @@ Cache::getInviteRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &members
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MemberInfo tmp = json::parse(member_data).get<MemberInfo>();
|
MemberInfo tmp = nlohmann::json::parse(member_data).get<MemberInfo>();
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
|
||||||
return QString::fromStdString(tmp.name);
|
return QString::fromStdString(tmp.name);
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse member info: {}", e.what());
|
nhlog::db()->warn("failed to parse member info: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2815,9 +2821,9 @@ Cache::getInviteRoomAvatarUrl(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &me
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
StrippedEvent<state::Avatar> msg =
|
StrippedEvent<state::Avatar> msg =
|
||||||
json::parse(event).get<StrippedEvent<state::Avatar>>();
|
nlohmann::json::parse(event).get<StrippedEvent<state::Avatar>>();
|
||||||
return QString::fromStdString(msg.content.url);
|
return QString::fromStdString(msg.content.url);
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse m.room.avatar event: {}", e.what());
|
nhlog::db()->warn("failed to parse m.room.avatar event: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2830,11 +2836,11 @@ Cache::getInviteRoomAvatarUrl(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &me
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MemberInfo tmp = json::parse(member_data).get<MemberInfo>();
|
MemberInfo tmp = nlohmann::json::parse(member_data).get<MemberInfo>();
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
|
||||||
return QString::fromStdString(tmp.avatar_url);
|
return QString::fromStdString(tmp.avatar_url);
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse member info: {}", e.what());
|
nhlog::db()->warn("failed to parse member info: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2855,9 +2861,9 @@ Cache::getInviteRoomTopic(lmdb::txn &txn, lmdb::dbi &db)
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
StrippedEvent<Topic> msg = json::parse(event).get<StrippedEvent<Topic>>();
|
StrippedEvent<Topic> msg = nlohmann::json::parse(event).get<StrippedEvent<Topic>>();
|
||||||
return QString::fromStdString(msg.content.topic);
|
return QString::fromStdString(msg.content.topic);
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse m.room.topic event: {}", e.what());
|
nhlog::db()->warn("failed to parse m.room.topic event: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2876,9 +2882,9 @@ Cache::getInviteRoomIsSpace(lmdb::txn &txn, lmdb::dbi &db)
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
StrippedEvent<Create> msg = json::parse(event).get<StrippedEvent<Create>>();
|
StrippedEvent<Create> msg = nlohmann::json::parse(event).get<StrippedEvent<Create>>();
|
||||||
return msg.content.type == mtx::events::state::room_type::space;
|
return msg.content.type == mtx::events::state::room_type::space;
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse m.room.topic event: {}", e.what());
|
nhlog::db()->warn("failed to parse m.room.topic event: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2917,7 +2923,7 @@ Cache::getMember(const std::string &room_id, const std::string &user_id)
|
||||||
|
|
||||||
std::string_view info;
|
std::string_view info;
|
||||||
if (membersdb.get(txn, user_id, info)) {
|
if (membersdb.get(txn, user_id, info)) {
|
||||||
MemberInfo m = json::parse(info).get<MemberInfo>();
|
MemberInfo m = nlohmann::json::parse(info).get<MemberInfo>();
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
|
@ -2951,10 +2957,10 @@ Cache::getMembers(const std::string &room_id, std::size_t startIndex, std::size_
|
||||||
break;
|
break;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MemberInfo tmp = json::parse(user_data).get<MemberInfo>();
|
MemberInfo tmp = nlohmann::json::parse(user_data).get<MemberInfo>();
|
||||||
members.emplace_back(RoomMember{QString::fromStdString(std::string(user_id)),
|
members.emplace_back(RoomMember{QString::fromStdString(std::string(user_id)),
|
||||||
QString::fromStdString(tmp.name)});
|
QString::fromStdString(tmp.name)});
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("{}", e.what());
|
nhlog::db()->warn("{}", e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2991,11 +2997,11 @@ Cache::getMembersFromInvite(const std::string &room_id, std::size_t startIndex,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MemberInfo tmp = json::parse(user_data).get<MemberInfo>();
|
MemberInfo tmp = nlohmann::json::parse(user_data).get<MemberInfo>();
|
||||||
members.emplace_back(RoomMember{QString::fromStdString(std::string(user_id)),
|
members.emplace_back(RoomMember{QString::fromStdString(std::string(user_id)),
|
||||||
QString::fromStdString(tmp.name),
|
QString::fromStdString(tmp.name),
|
||||||
tmp.is_direct});
|
tmp.is_direct});
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("{}", e.what());
|
nhlog::db()->warn("{}", e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3088,7 +3094,7 @@ Cache::firstPendingMessage(const std::string &room_id)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mtx::events::collections::TimelineEvent te;
|
mtx::events::collections::TimelineEvent te;
|
||||||
mtx::events::collections::from_json(json::parse(event), te);
|
mtx::events::collections::from_json(nlohmann::json::parse(event), te);
|
||||||
|
|
||||||
pendingCursor.close();
|
pendingCursor.close();
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
@ -3178,8 +3184,8 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
|
||||||
|
|
||||||
std::string_view event_id = event_id_val;
|
std::string_view event_id = event_id_val;
|
||||||
|
|
||||||
json orderEntry = json::object();
|
nlohmann::json orderEntry = nlohmann::json::object();
|
||||||
orderEntry["event_id"] = event_id_val;
|
orderEntry["event_id"] = event_id_val;
|
||||||
if (first && !res.prev_batch.empty())
|
if (first && !res.prev_batch.empty())
|
||||||
orderEntry["prev_batch"] = res.prev_batch;
|
orderEntry["prev_batch"] = res.prev_batch;
|
||||||
|
|
||||||
|
@ -3228,7 +3234,7 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
|
||||||
mtx::events::collections::TimelineEvent te;
|
mtx::events::collections::TimelineEvent te;
|
||||||
try {
|
try {
|
||||||
mtx::events::collections::from_json(
|
mtx::events::collections::from_json(
|
||||||
json::parse(std::string_view(oldEvent.data(), oldEvent.size())), te);
|
nlohmann::json::parse(std::string_view(oldEvent.data(), oldEvent.size())), te);
|
||||||
// overwrite the content and add redation data
|
// overwrite the content and add redation data
|
||||||
std::visit(
|
std::visit(
|
||||||
[redaction](auto &ev) {
|
[redaction](auto &ev) {
|
||||||
|
@ -3245,7 +3251,7 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
|
||||||
}
|
}
|
||||||
|
|
||||||
eventsDb.put(txn, redaction->redacts, event.dump());
|
eventsDb.put(txn, redaction->redacts, event.dump());
|
||||||
eventsDb.put(txn, redaction->event_id, json(*redaction).dump());
|
eventsDb.put(txn, redaction->event_id, nlohmann::json(*redaction).dump());
|
||||||
} else {
|
} else {
|
||||||
first = false;
|
first = false;
|
||||||
|
|
||||||
|
@ -3316,7 +3322,7 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message
|
||||||
|
|
||||||
if (res.chunk.empty()) {
|
if (res.chunk.empty()) {
|
||||||
if (orderDb.get(txn, lmdb::to_sv(index), val)) {
|
if (orderDb.get(txn, lmdb::to_sv(index), val)) {
|
||||||
auto orderEntry = json::parse(val);
|
auto orderEntry = nlohmann::json::parse(val);
|
||||||
orderEntry["prev_batch"] = res.end;
|
orderEntry["prev_batch"] = res.end;
|
||||||
orderDb.put(txn, lmdb::to_sv(index), orderEntry.dump());
|
orderDb.put(txn, lmdb::to_sv(index), orderEntry.dump());
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
@ -3340,8 +3346,8 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message
|
||||||
if (!evToOrderDb.get(txn, event_id, unused_read)) {
|
if (!evToOrderDb.get(txn, event_id, unused_read)) {
|
||||||
--index;
|
--index;
|
||||||
|
|
||||||
json orderEntry = json::object();
|
nlohmann::json orderEntry = nlohmann::json::object();
|
||||||
orderEntry["event_id"] = event_id_val;
|
orderEntry["event_id"] = event_id_val;
|
||||||
|
|
||||||
orderDb.put(txn, lmdb::to_sv(index), orderEntry.dump());
|
orderDb.put(txn, lmdb::to_sv(index), orderEntry.dump());
|
||||||
evToOrderDb.put(txn, event_id, lmdb::to_sv(index));
|
evToOrderDb.put(txn, event_id, lmdb::to_sv(index));
|
||||||
|
@ -3366,9 +3372,9 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
json orderEntry = json::object();
|
nlohmann::json orderEntry = nlohmann::json::object();
|
||||||
orderEntry["event_id"] = event_id_val;
|
orderEntry["event_id"] = event_id_val;
|
||||||
orderEntry["prev_batch"] = res.end;
|
orderEntry["prev_batch"] = res.end;
|
||||||
orderDb.put(txn, lmdb::to_sv(index), orderEntry.dump());
|
orderDb.put(txn, lmdb::to_sv(index), orderEntry.dump());
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
@ -3395,10 +3401,10 @@ Cache::clearTimeline(const std::string &room_id)
|
||||||
bool passed_pagination_token = false;
|
bool passed_pagination_token = false;
|
||||||
while (cursor.get(indexVal, val, start ? MDB_LAST : MDB_PREV)) {
|
while (cursor.get(indexVal, val, start ? MDB_LAST : MDB_PREV)) {
|
||||||
start = false;
|
start = false;
|
||||||
json obj;
|
nlohmann::json obj;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
obj = json::parse(std::string_view(val.data(), val.size()));
|
obj = nlohmann::json::parse(std::string_view(val.data(), val.size()));
|
||||||
} catch (std::exception &) {
|
} catch (std::exception &) {
|
||||||
// workaround bug in the initial db format, where we sometimes didn't store
|
// workaround bug in the initial db format, where we sometimes didn't store
|
||||||
// json...
|
// json...
|
||||||
|
@ -3440,9 +3446,9 @@ Cache::clearTimeline(const std::string &room_id)
|
||||||
while (cursor.get(indexVal, eventId, innerStart ? MDB_LAST : MDB_PREV)) {
|
while (cursor.get(indexVal, eventId, innerStart ? MDB_LAST : MDB_PREV)) {
|
||||||
innerStart = false;
|
innerStart = false;
|
||||||
|
|
||||||
json obj;
|
nlohmann::json obj;
|
||||||
try {
|
try {
|
||||||
obj = json::parse(std::string_view(eventId.data(), eventId.size()));
|
obj = nlohmann::json::parse(std::string_view(eventId.data(), eventId.size()));
|
||||||
} catch (std::exception &) {
|
} catch (std::exception &) {
|
||||||
obj = {{"event_id", std::string(eventId.data(), eventId.size())}};
|
obj = {{"event_id", std::string(eventId.data(), eventId.size())}};
|
||||||
}
|
}
|
||||||
|
@ -3483,7 +3489,7 @@ Cache::getTimelineMentionsForRoom(lmdb::txn &txn, const std::string &room_id)
|
||||||
auto cursor = lmdb::cursor::open(txn, db);
|
auto cursor = lmdb::cursor::open(txn, db);
|
||||||
|
|
||||||
while (cursor.get(event_id, msg, MDB_NEXT)) {
|
while (cursor.get(event_id, msg, MDB_NEXT)) {
|
||||||
auto obj = json::parse(msg);
|
auto obj = nlohmann::json::parse(msg);
|
||||||
|
|
||||||
if (obj.count("event") == 0)
|
if (obj.count("event") == 0)
|
||||||
continue;
|
continue;
|
||||||
|
@ -3508,7 +3514,7 @@ Cache::saveTimelineMentions(const mtx::responses::Notifications &res)
|
||||||
|
|
||||||
// Sort into room-specific 'buckets'
|
// Sort into room-specific 'buckets'
|
||||||
for (const auto ¬if : res.notifications) {
|
for (const auto ¬if : res.notifications) {
|
||||||
json val = notif;
|
nlohmann::json val = notif;
|
||||||
notifsByRoom[notif.room_id].push_back(notif);
|
notifsByRoom[notif.room_id].push_back(notif);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3544,7 +3550,7 @@ Cache::saveTimelineMentions(lmdb::txn &txn,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
json obj = notif;
|
nlohmann::json obj = notif;
|
||||||
|
|
||||||
db.put(txn, event_id, obj.dump());
|
db.put(txn, event_id, obj.dump());
|
||||||
}
|
}
|
||||||
|
@ -3632,7 +3638,7 @@ Cache::deleteOldMessages()
|
||||||
while (cursor.get(indexVal, val, start ? MDB_FIRST : MDB_NEXT) &&
|
while (cursor.get(indexVal, val, start ? MDB_FIRST : MDB_NEXT) &&
|
||||||
message_count-- > MAX_RESTORED_MESSAGES) {
|
message_count-- > MAX_RESTORED_MESSAGES) {
|
||||||
start = false;
|
start = false;
|
||||||
auto obj = json::parse(std::string_view(val.data(), val.size()));
|
auto obj = nlohmann::json::parse(std::string_view(val.data(), val.size()));
|
||||||
|
|
||||||
if (obj.count("event_id") != 0) {
|
if (obj.count("event_id") != 0) {
|
||||||
std::string event_id = obj["event_id"].get<std::string>();
|
std::string event_id = obj["event_id"].get<std::string>();
|
||||||
|
@ -3753,7 +3759,7 @@ Cache::spaces()
|
||||||
if (!space_child.empty()) {
|
if (!space_child.empty()) {
|
||||||
std::string_view room_data;
|
std::string_view room_data;
|
||||||
if (roomsDb_.get(txn, space_id, room_data)) {
|
if (roomsDb_.get(txn, space_id, room_data)) {
|
||||||
RoomInfo tmp = json::parse(std::move(room_data)).get<RoomInfo>();
|
RoomInfo tmp = nlohmann::json::parse(std::move(room_data)).get<RoomInfo>();
|
||||||
ret.insert(QString::fromUtf8(space_id.data(), space_id.size()), tmp);
|
ret.insert(QString::fromUtf8(space_id.data(), space_id.size()), tmp);
|
||||||
} else {
|
} else {
|
||||||
ret.insert(QString::fromUtf8(space_id.data(), space_id.size()), std::nullopt);
|
ret.insert(QString::fromUtf8(space_id.data(), space_id.size()), std::nullopt);
|
||||||
|
@ -3903,8 +3909,8 @@ Cache::getAccountData(lmdb::txn &txn, mtx::events::EventType type, const std::st
|
||||||
std::string_view data;
|
std::string_view data;
|
||||||
if (db.get(txn, to_string(type), data)) {
|
if (db.get(txn, to_string(type), data)) {
|
||||||
mtx::responses::utils::RoomAccountDataEvents events;
|
mtx::responses::utils::RoomAccountDataEvents events;
|
||||||
json j = json::array({
|
nlohmann::json j = nlohmann::json::array({
|
||||||
json::parse(data),
|
nlohmann::json::parse(data),
|
||||||
});
|
});
|
||||||
mtx::responses::utils::parse_room_account_data_events(j, events);
|
mtx::responses::utils::parse_room_account_data_events(j, events);
|
||||||
if (events.size() == 1)
|
if (events.size() == 1)
|
||||||
|
@ -3934,14 +3940,15 @@ Cache::hasEnoughPowerLevel(const std::vector<mtx::events::EventType> &eventTypes
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
StateEvent<PowerLevels> msg = json::parse(std::string_view(event.data(), event.size()))
|
StateEvent<PowerLevels> msg =
|
||||||
.get<StateEvent<PowerLevels>>();
|
nlohmann::json::parse(std::string_view(event.data(), event.size()))
|
||||||
|
.get<StateEvent<PowerLevels>>();
|
||||||
|
|
||||||
user_level = msg.content.user_level(user_id);
|
user_level = msg.content.user_level(user_id);
|
||||||
|
|
||||||
for (const auto &ty : eventTypes)
|
for (const auto &ty : eventTypes)
|
||||||
min_event_level = std::min(min_event_level, msg.content.state_level(to_string(ty)));
|
min_event_level = std::min(min_event_level, msg.content.state_level(to_string(ty)));
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse m.room.power_levels event: {}", e.what());
|
nhlog::db()->warn("failed to parse m.room.power_levels event: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4031,7 +4038,7 @@ Cache::getMembersWithKeys(const std::string &room_id, bool verified_only)
|
||||||
auto res = keysDb.get(txn, user_id, keys);
|
auto res = keysDb.get(txn, user_id, keys);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
auto k = json::parse(keys).get<UserKeyCache>();
|
auto k = nlohmann::json::parse(keys).get<UserKeyCache>();
|
||||||
if (verified_only) {
|
if (verified_only) {
|
||||||
auto verif = verificationStatus_(std::string(user_id), txn);
|
auto verif = verificationStatus_(std::string(user_id), txn);
|
||||||
|
|
||||||
|
@ -4130,7 +4137,7 @@ Cache::presence(const std::string &user_id)
|
||||||
auto res = presenceDb_.get(txn, user_id, presenceVal);
|
auto res = presenceDb_.get(txn, user_id, presenceVal);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
presence_ = json::parse(std::string_view(presenceVal.data(), presenceVal.size()))
|
presence_ = nlohmann::json::parse(std::string_view(presenceVal.data(), presenceVal.size()))
|
||||||
.get<mtx::events::presence::Presence>();
|
.get<mtx::events::presence::Presence>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4138,7 +4145,7 @@ Cache::presence(const std::string &user_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
to_json(json &j, const UserKeyCache &info)
|
to_json(nlohmann::json &j, const UserKeyCache &info)
|
||||||
{
|
{
|
||||||
j["device_keys"] = info.device_keys;
|
j["device_keys"] = info.device_keys;
|
||||||
j["seen_device_keys"] = info.seen_device_keys;
|
j["seen_device_keys"] = info.seen_device_keys;
|
||||||
|
@ -4152,7 +4159,7 @@ to_json(json &j, const UserKeyCache &info)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
from_json(const json &j, UserKeyCache &info)
|
from_json(const nlohmann::json &j, UserKeyCache &info)
|
||||||
{
|
{
|
||||||
info.device_keys = j.value("device_keys", std::map<std::string, mtx::crypto::DeviceKeys>{});
|
info.device_keys = j.value("device_keys", std::map<std::string, mtx::crypto::DeviceKeys>{});
|
||||||
info.seen_device_keys = j.value("seen_device_keys", std::set<std::string>{});
|
info.seen_device_keys = j.value("seen_device_keys", std::set<std::string>{});
|
||||||
|
@ -4182,7 +4189,7 @@ Cache::userKeys_(const std::string &user_id, lmdb::txn &txn)
|
||||||
auto res = db.get(txn, user_id, keys);
|
auto res = db.get(txn, user_id, keys);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
return json::parse(keys).get<UserKeyCache>();
|
return nlohmann::json::parse(keys).get<UserKeyCache>();
|
||||||
} else {
|
} else {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
@ -4218,7 +4225,7 @@ Cache::updateUserKeys(const std::string &sync_token, const mtx::responses::Query
|
||||||
auto res = db.get(txn, user, oldKeys);
|
auto res = db.get(txn, user, oldKeys);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
updateToWrite = json::parse(oldKeys).get<UserKeyCache>();
|
updateToWrite = nlohmann::json::parse(oldKeys).get<UserKeyCache>();
|
||||||
auto last_changed = updateToWrite.last_changed;
|
auto last_changed = updateToWrite.last_changed;
|
||||||
// skip if we are tracking this and expect it to be up to date with the last
|
// skip if we are tracking this and expect it to be up to date with the last
|
||||||
// sync token
|
// sync token
|
||||||
|
@ -4289,7 +4296,7 @@ Cache::updateUserKeys(const std::string &sync_token, const mtx::responses::Query
|
||||||
|
|
||||||
if (!mtx::crypto::ed25519_verify_signature(
|
if (!mtx::crypto::ed25519_verify_signature(
|
||||||
device_keys.keys.at(device_signing_key),
|
device_keys.keys.at(device_signing_key),
|
||||||
json(device_keys),
|
nlohmann::json(device_keys),
|
||||||
device_keys.signatures.at(user).at(device_signing_key))) {
|
device_keys.signatures.at(user).at(device_signing_key))) {
|
||||||
nhlog::crypto()->warn(
|
nhlog::crypto()->warn(
|
||||||
"device {}:{} has an invalid signature", user, device_id);
|
"device {}:{} has an invalid signature", user, device_id);
|
||||||
|
@ -4308,7 +4315,7 @@ Cache::updateUserKeys(const std::string &sync_token, const mtx::responses::Query
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateToWrite.updated_at = sync_token;
|
updateToWrite.updated_at = sync_token;
|
||||||
db.put(txn, user, json(updateToWrite).dump());
|
db.put(txn, user, nlohmann::json(updateToWrite).dump());
|
||||||
}
|
}
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
@ -4368,12 +4375,12 @@ Cache::markUserKeysOutOfDate(lmdb::txn &txn,
|
||||||
UserKeyCache cacheEntry;
|
UserKeyCache cacheEntry;
|
||||||
auto res = db.get(txn, user, oldKeys);
|
auto res = db.get(txn, user, oldKeys);
|
||||||
if (res) {
|
if (res) {
|
||||||
cacheEntry =
|
cacheEntry = nlohmann::json::parse(std::string_view(oldKeys.data(), oldKeys.size()))
|
||||||
json::parse(std::string_view(oldKeys.data(), oldKeys.size())).get<UserKeyCache>();
|
.get<UserKeyCache>();
|
||||||
}
|
}
|
||||||
cacheEntry.last_changed = sync_token;
|
cacheEntry.last_changed = sync_token;
|
||||||
|
|
||||||
db.put(txn, user, json(cacheEntry).dump());
|
db.put(txn, user, nlohmann::json(cacheEntry).dump());
|
||||||
|
|
||||||
query.device_keys[user] = {};
|
query.device_keys[user] = {};
|
||||||
}
|
}
|
||||||
|
@ -4456,28 +4463,28 @@ Cache::query_keys(const std::string &user_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
to_json(json &j, const VerificationCache &info)
|
to_json(nlohmann::json &j, const VerificationCache &info)
|
||||||
{
|
{
|
||||||
j["device_verified"] = info.device_verified;
|
j["device_verified"] = info.device_verified;
|
||||||
j["device_blocked"] = info.device_blocked;
|
j["device_blocked"] = info.device_blocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
from_json(const json &j, VerificationCache &info)
|
from_json(const nlohmann::json &j, VerificationCache &info)
|
||||||
{
|
{
|
||||||
info.device_verified = j.at("device_verified").get<std::set<std::string>>();
|
info.device_verified = j.at("device_verified").get<std::set<std::string>>();
|
||||||
info.device_blocked = j.at("device_blocked").get<std::set<std::string>>();
|
info.device_blocked = j.at("device_blocked").get<std::set<std::string>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
to_json(json &j, const OnlineBackupVersion &info)
|
to_json(nlohmann::json &j, const OnlineBackupVersion &info)
|
||||||
{
|
{
|
||||||
j["v"] = info.version;
|
j["v"] = info.version;
|
||||||
j["a"] = info.algorithm;
|
j["a"] = info.algorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
from_json(const json &j, OnlineBackupVersion &info)
|
from_json(const nlohmann::json &j, OnlineBackupVersion &info)
|
||||||
{
|
{
|
||||||
info.version = j.at("v").get<std::string>();
|
info.version = j.at("v").get<std::string>();
|
||||||
info.algorithm = j.at("a").get<std::string>();
|
info.algorithm = j.at("a").get<std::string>();
|
||||||
|
@ -4494,7 +4501,7 @@ Cache::verificationCache(const std::string &user_id, lmdb::txn &txn)
|
||||||
VerificationCache verified_state;
|
VerificationCache verified_state;
|
||||||
auto res = db.get(txn, user_id, verifiedVal);
|
auto res = db.get(txn, user_id, verifiedVal);
|
||||||
if (res) {
|
if (res) {
|
||||||
verified_state = json::parse(verifiedVal).get<VerificationCache>();
|
verified_state = nlohmann::json::parse(verifiedVal).get<VerificationCache>();
|
||||||
return verified_state;
|
return verified_state;
|
||||||
} else {
|
} else {
|
||||||
return {};
|
return {};
|
||||||
|
@ -4517,7 +4524,7 @@ Cache::markDeviceVerified(const std::string &user_id, const std::string &key)
|
||||||
VerificationCache verified_state;
|
VerificationCache verified_state;
|
||||||
auto res = db.get(txn, user_id, val);
|
auto res = db.get(txn, user_id, val);
|
||||||
if (res) {
|
if (res) {
|
||||||
verified_state = json::parse(val).get<VerificationCache>();
|
verified_state = nlohmann::json::parse(val).get<VerificationCache>();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &device : verified_state.device_verified)
|
for (const auto &device : verified_state.device_verified)
|
||||||
|
@ -4525,7 +4532,7 @@ Cache::markDeviceVerified(const std::string &user_id, const std::string &key)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
verified_state.device_verified.insert(key);
|
verified_state.device_verified.insert(key);
|
||||||
db.put(txn, user_id, json(verified_state).dump());
|
db.put(txn, user_id, nlohmann::json(verified_state).dump());
|
||||||
txn.commit();
|
txn.commit();
|
||||||
} catch (std::exception &) {
|
} catch (std::exception &) {
|
||||||
}
|
}
|
||||||
|
@ -4564,12 +4571,12 @@ Cache::markDeviceUnverified(const std::string &user_id, const std::string &key)
|
||||||
VerificationCache verified_state;
|
VerificationCache verified_state;
|
||||||
auto res = db.get(txn, user_id, val);
|
auto res = db.get(txn, user_id, val);
|
||||||
if (res) {
|
if (res) {
|
||||||
verified_state = json::parse(val).get<VerificationCache>();
|
verified_state = nlohmann::json::parse(val).get<VerificationCache>();
|
||||||
}
|
}
|
||||||
|
|
||||||
verified_state.device_verified.erase(key);
|
verified_state.device_verified.erase(key);
|
||||||
|
|
||||||
db.put(txn, user_id, json(verified_state).dump());
|
db.put(txn, user_id, nlohmann::json(verified_state).dump());
|
||||||
txn.commit();
|
txn.commit();
|
||||||
} catch (std::exception &) {
|
} catch (std::exception &) {
|
||||||
}
|
}
|
||||||
|
@ -4636,7 +4643,8 @@ Cache::verificationStatus_(const std::string &user_id, lmdb::txn &txn)
|
||||||
if (!keys.count(key_id))
|
if (!keys.count(key_id))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (mtx::crypto::ed25519_verify_signature(keys.at(key_id), json(toVerif), signature))
|
if (mtx::crypto::ed25519_verify_signature(
|
||||||
|
keys.at(key_id), nlohmann::json(toVerif), signature))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -4679,7 +4687,7 @@ Cache::verificationStatus_(const std::string &user_id, lmdb::txn &txn)
|
||||||
std::string dev_id = "ed25519:" + http::client()->device_id();
|
std::string dev_id = "ed25519:" + http::client()->device_id();
|
||||||
if (!mk.signatures.count(local_user) || !mk.signatures.at(local_user).count(dev_id) ||
|
if (!mk.signatures.count(local_user) || !mk.signatures.at(local_user).count(dev_id) ||
|
||||||
!mtx::crypto::ed25519_verify_signature(olm::client()->identity_keys().ed25519,
|
!mtx::crypto::ed25519_verify_signature(olm::client()->identity_keys().ed25519,
|
||||||
json(mk),
|
nlohmann::json(mk),
|
||||||
mk.signatures.at(local_user).at(dev_id))) {
|
mk.signatures.at(local_user).at(dev_id))) {
|
||||||
nhlog::crypto()->debug("We have not verified our own master key");
|
nhlog::crypto()->debug("We have not verified our own master key");
|
||||||
verification_storage.status[user_id] = status;
|
verification_storage.status[user_id] = status;
|
||||||
|
@ -4735,7 +4743,7 @@ Cache::verificationStatus_(const std::string &user_id, lmdb::txn &txn)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
to_json(json &j, const RoomInfo &info)
|
to_json(nlohmann::json &j, const RoomInfo &info)
|
||||||
{
|
{
|
||||||
j["name"] = info.name;
|
j["name"] = info.name;
|
||||||
j["topic"] = info.topic;
|
j["topic"] = info.topic;
|
||||||
|
@ -4759,7 +4767,7 @@ to_json(json &j, const RoomInfo &info)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
from_json(const json &j, RoomInfo &info)
|
from_json(const nlohmann::json &j, RoomInfo &info)
|
||||||
{
|
{
|
||||||
info.name = j.at("name").get<std::string>();
|
info.name = j.at("name").get<std::string>();
|
||||||
info.topic = j.at("topic").get<std::string>();
|
info.topic = j.at("topic").get<std::string>();
|
||||||
|
@ -4784,20 +4792,20 @@ from_json(const json &j, RoomInfo &info)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
to_json(json &j, const ReadReceiptKey &key)
|
to_json(nlohmann::json &j, const ReadReceiptKey &key)
|
||||||
{
|
{
|
||||||
j = json{{"event_id", key.event_id}, {"room_id", key.room_id}};
|
j = nlohmann::json{{"event_id", key.event_id}, {"room_id", key.room_id}};
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
from_json(const json &j, ReadReceiptKey &key)
|
from_json(const nlohmann::json &j, ReadReceiptKey &key)
|
||||||
{
|
{
|
||||||
key.event_id = j.at("event_id").get<std::string>();
|
key.event_id = j.at("event_id").get<std::string>();
|
||||||
key.room_id = j.at("room_id").get<std::string>();
|
key.room_id = j.at("room_id").get<std::string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
to_json(json &j, const MemberInfo &info)
|
to_json(nlohmann::json &j, const MemberInfo &info)
|
||||||
{
|
{
|
||||||
j["name"] = info.name;
|
j["name"] = info.name;
|
||||||
j["avatar_url"] = info.avatar_url;
|
j["avatar_url"] = info.avatar_url;
|
||||||
|
@ -4806,7 +4814,7 @@ to_json(json &j, const MemberInfo &info)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
from_json(const json &j, MemberInfo &info)
|
from_json(const nlohmann::json &j, MemberInfo &info)
|
||||||
{
|
{
|
||||||
info.name = j.at("name").get<std::string>();
|
info.name = j.at("name").get<std::string>();
|
||||||
info.avatar_url = j.at("avatar_url").get<std::string>();
|
info.avatar_url = j.at("avatar_url").get<std::string>();
|
||||||
|
|
|
@ -401,7 +401,7 @@ private:
|
||||||
// Lightweight representation of a member.
|
// Lightweight representation of a member.
|
||||||
MemberInfo tmp{display_name, e->content.avatar_url};
|
MemberInfo tmp{display_name, e->content.avatar_url};
|
||||||
|
|
||||||
membersdb.put(txn, e->state_key, json(tmp).dump());
|
membersdb.put(txn, e->state_key, nlohmann::json(tmp).dump());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -419,7 +419,7 @@ private:
|
||||||
std::visit(
|
std::visit(
|
||||||
[&txn, &statesdb, &stateskeydb, &eventsDb, &membersdb](const auto &e) {
|
[&txn, &statesdb, &stateskeydb, &eventsDb, &membersdb](const auto &e) {
|
||||||
if constexpr (isStateEvent_<decltype(e)>) {
|
if constexpr (isStateEvent_<decltype(e)>) {
|
||||||
eventsDb.put(txn, e.event_id, json(e).dump());
|
eventsDb.put(txn, e.event_id, nlohmann::json(e).dump());
|
||||||
|
|
||||||
if (e.type != EventType::Unsupported) {
|
if (e.type != EventType::Unsupported) {
|
||||||
if (std::is_same_v<std::remove_cv_t<std::remove_reference_t<decltype(e)>>,
|
if (std::is_same_v<std::remove_cv_t<std::remove_reference_t<decltype(e)>>,
|
||||||
|
@ -431,20 +431,20 @@ private:
|
||||||
else
|
else
|
||||||
stateskeydb.del(txn,
|
stateskeydb.del(txn,
|
||||||
to_string(e.type),
|
to_string(e.type),
|
||||||
json::object({
|
nlohmann::json::object({
|
||||||
{"key", e.state_key},
|
{"key", e.state_key},
|
||||||
{"id", e.event_id},
|
{"id", e.event_id},
|
||||||
})
|
})
|
||||||
.dump());
|
.dump());
|
||||||
} else if (e.state_key.empty())
|
} else if (e.state_key.empty())
|
||||||
statesdb.put(txn, to_string(e.type), json(e).dump());
|
statesdb.put(txn, to_string(e.type), nlohmann::json(e).dump());
|
||||||
else
|
else
|
||||||
stateskeydb.put(txn,
|
stateskeydb.put(txn,
|
||||||
to_string(e.type),
|
to_string(e.type),
|
||||||
json::object({
|
nlohmann::json::object({
|
||||||
{"key", e.state_key},
|
{"key", e.state_key},
|
||||||
{"id", e.event_id},
|
{"id", e.event_id},
|
||||||
})
|
})
|
||||||
.dump());
|
.dump());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -473,7 +473,7 @@ private:
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
auto db = getStatesKeyDb(txn, room_id);
|
auto db = getStatesKeyDb(txn, room_id);
|
||||||
std::string d = json::object({{"key", state_key}}).dump();
|
std::string d = nlohmann::json::object({{"key", state_key}}).dump();
|
||||||
std::string_view data = d;
|
std::string_view data = d;
|
||||||
std::string_view typeStrV = typeStr;
|
std::string_view typeStrV = typeStr;
|
||||||
|
|
||||||
|
@ -483,14 +483,15 @@ private:
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto eventsDb = getEventsDb(txn, room_id);
|
auto eventsDb = getEventsDb(txn, room_id);
|
||||||
if (!eventsDb.get(txn, json::parse(data)["id"].get<std::string>(), value))
|
if (!eventsDb.get(
|
||||||
|
txn, nlohmann::json::parse(data)["id"].get<std::string>(), value))
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return json::parse(value).get<mtx::events::StateEvent<T>>();
|
return nlohmann::json::parse(value).get<mtx::events::StateEvent<T>>();
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
@ -523,8 +524,10 @@ private:
|
||||||
first = false;
|
first = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (eventsDb.get(txn, json::parse(data)["id"].get<std::string>(), value))
|
if (eventsDb.get(
|
||||||
events.push_back(json::parse(value).get<mtx::events::StateEvent<T>>());
|
txn, nlohmann::json::parse(data)["id"].get<std::string>(), value))
|
||||||
|
events.push_back(
|
||||||
|
nlohmann::json::parse(value).get<mtx::events::StateEvent<T>>());
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
nhlog::db()->warn("Failed to parse state event: {}", e.what());
|
nhlog::db()->warn("Failed to parse state event: {}", e.what());
|
||||||
}
|
}
|
||||||
|
|
|
@ -426,7 +426,7 @@ ChatPage::loadStateFromCache()
|
||||||
nhlog::db()->critical("failed to restore cache: {}", e.what());
|
nhlog::db()->critical("failed to restore cache: {}", e.what());
|
||||||
emit dropToLoginPageCb(tr("Failed to restore save data. Please login again."));
|
emit dropToLoginPageCb(tr("Failed to restore save data. Please login again."));
|
||||||
return;
|
return;
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->critical("failed to parse cache data: {}", e.what());
|
nhlog::db()->critical("failed to parse cache data: {}", e.what());
|
||||||
emit dropToLoginPageCb(tr("Failed to restore save data. Please login again."));
|
emit dropToLoginPageCb(tr("Failed to restore save data. Please login again."));
|
||||||
return;
|
return;
|
||||||
|
@ -1238,7 +1238,7 @@ ChatPage::decryptDownloadedSecrets(mtx::secret_storage::AesHmacSha2KeyDescriptio
|
||||||
olm::client()->identity_keys().ed25519 &&
|
olm::client()->identity_keys().ed25519 &&
|
||||||
myKey.keys["curve25519:" + http::client()->device_id()] ==
|
myKey.keys["curve25519:" + http::client()->device_id()] ==
|
||||||
olm::client()->identity_keys().curve25519) {
|
olm::client()->identity_keys().curve25519) {
|
||||||
json j = myKey;
|
nlohmann::json j = myKey;
|
||||||
j.erase("signatures");
|
j.erase("signatures");
|
||||||
j.erase("unsigned");
|
j.erase("unsigned");
|
||||||
|
|
||||||
|
@ -1254,7 +1254,7 @@ ChatPage::decryptDownloadedSecrets(mtx::secret_storage::AesHmacSha2KeyDescriptio
|
||||||
|
|
||||||
if (deviceKeys->master_keys.user_id == http::client()->user_id().to_string() &&
|
if (deviceKeys->master_keys.user_id == http::client()->user_id().to_string() &&
|
||||||
deviceKeys->master_keys.keys["ed25519:" + mk.public_key()] == mk.public_key()) {
|
deviceKeys->master_keys.keys["ed25519:" + mk.public_key()] == mk.public_key()) {
|
||||||
json j = deviceKeys->master_keys;
|
nlohmann::json j = deviceKeys->master_keys;
|
||||||
j.erase("signatures");
|
j.erase("signatures");
|
||||||
j.erase("unsigned");
|
j.erase("unsigned");
|
||||||
mtx::crypto::CrossSigningKeys master_key =
|
mtx::crypto::CrossSigningKeys master_key =
|
||||||
|
@ -1270,7 +1270,7 @@ ChatPage::decryptDownloadedSecrets(mtx::secret_storage::AesHmacSha2KeyDescriptio
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!req.signatures.empty()) {
|
if (!req.signatures.empty()) {
|
||||||
nhlog::crypto()->debug("Uploading new signatures: {}", json(req).dump(2));
|
nhlog::crypto()->debug("Uploading new signatures: {}", nlohmann::json(req).dump(2));
|
||||||
http::client()->keys_signatures_upload(
|
http::client()->keys_signatures_upload(
|
||||||
req, [](const mtx::responses::KeySignaturesUpload &res, mtx::http::RequestErr err) {
|
req, [](const mtx::responses::KeySignaturesUpload &res, mtx::http::RequestErr err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -267,7 +267,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *,
|
||||||
// verified it
|
// verified it
|
||||||
for (const auto &mac : msg.mac) {
|
for (const auto &mac : msg.mac) {
|
||||||
if (their_keys.master_keys.keys.count(mac.first)) {
|
if (their_keys.master_keys.keys.count(mac.first)) {
|
||||||
json j = their_keys.master_keys;
|
nlohmann::json j = their_keys.master_keys;
|
||||||
j.erase("signatures");
|
j.erase("signatures");
|
||||||
j.erase("unsigned");
|
j.erase("unsigned");
|
||||||
mtx::crypto::CrossSigningKeys master_key =
|
mtx::crypto::CrossSigningKeys master_key =
|
||||||
|
@ -283,7 +283,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *,
|
||||||
auto device_id = this->deviceId.toStdString();
|
auto device_id = this->deviceId.toStdString();
|
||||||
|
|
||||||
if (their_keys.device_keys.count(device_id)) {
|
if (their_keys.device_keys.count(device_id)) {
|
||||||
json j = their_keys.device_keys.at(device_id);
|
nlohmann::json j = their_keys.device_keys.at(device_id);
|
||||||
j.erase("signatures");
|
j.erase("signatures");
|
||||||
j.erase("unsigned");
|
j.erase("unsigned");
|
||||||
|
|
||||||
|
@ -305,7 +305,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *,
|
||||||
// Sign their master key with user signing key
|
// Sign their master key with user signing key
|
||||||
for (const auto &mac : msg.mac) {
|
for (const auto &mac : msg.mac) {
|
||||||
if (their_keys.master_keys.keys.count(mac.first)) {
|
if (their_keys.master_keys.keys.count(mac.first)) {
|
||||||
json j = their_keys.master_keys;
|
nlohmann::json j = their_keys.master_keys;
|
||||||
j.erase("signatures");
|
j.erase("signatures");
|
||||||
j.erase("unsigned");
|
j.erase("unsigned");
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ handle_to_device_messages(const std::vector<mtx::events::collections::DeviceEven
|
||||||
nlohmann::json j_msg;
|
nlohmann::json j_msg;
|
||||||
|
|
||||||
for (const auto &msg : msgs) {
|
for (const auto &msg : msgs) {
|
||||||
j_msg = std::visit([](auto &e) { return json(e); }, std::move(msg));
|
j_msg = std::visit([](auto &e) { return nlohmann::json(e); }, std::move(msg));
|
||||||
if (j_msg.count("type") == 0) {
|
if (j_msg.count("type") == 0) {
|
||||||
nhlog::crypto()->warn("received message with no type field: {}", j_msg.dump(2));
|
nhlog::crypto()->warn("received message with no type field: {}", j_msg.dump(2));
|
||||||
continue;
|
continue;
|
||||||
|
@ -295,8 +295,8 @@ handle_olm_message(const OlmMessage &msg, const UserKeyCache &otherUserDeviceKey
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::string msg_type = payload["type"].get<std::string>();
|
std::string msg_type = payload["type"].get<std::string>();
|
||||||
json event_array = json::array();
|
nlohmann::json event_array = nlohmann::json::array();
|
||||||
event_array.push_back(payload);
|
event_array.push_back(payload);
|
||||||
|
|
||||||
std::vector<mtx::events::collections::DeviceEvents> temp_events;
|
std::vector<mtx::events::collections::DeviceEvents> temp_events;
|
||||||
|
@ -456,7 +456,7 @@ handle_pre_key_olm_message(const std::string &sender,
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto plaintext = json::parse(std::string((char *)output.data(), output.size()));
|
auto plaintext = nlohmann::json::parse(std::string((char *)output.data(), output.size()));
|
||||||
nhlog::crypto()->debug("decrypted message: \n {}", plaintext.dump(2));
|
nhlog::crypto()->debug("decrypted message: \n {}", plaintext.dump(2));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -716,8 +716,8 @@ try_olm_decryption(const std::string &sender_key, const mtx::events::msg::OlmCip
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return json::parse(std::string_view((char *)text.data(), text.size()));
|
return nlohmann::json::parse(std::string_view((char *)text.data(), text.size()));
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::crypto()->critical("failed to parse the decrypted session msg: {} {}",
|
nhlog::crypto()->critical("failed to parse the decrypted session msg: {} {}",
|
||||||
e.what(),
|
e.what(),
|
||||||
std::string_view((char *)text.data(), text.size()));
|
std::string_view((char *)text.data(), text.size()));
|
||||||
|
@ -980,7 +980,7 @@ send_key_request_for(mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> e,
|
||||||
request.request_id = request_id;
|
request.request_id = request_id;
|
||||||
request.requesting_device_id = http::client()->device_id();
|
request.requesting_device_id = http::client()->device_id();
|
||||||
|
|
||||||
nhlog::crypto()->debug("m.room_key_request: {}", json(request).dump(2));
|
nhlog::crypto()->debug("m.room_key_request: {}", nlohmann::json(request).dump(2));
|
||||||
|
|
||||||
std::map<mtx::identifiers::User, std::map<std::string, decltype(request)>> body;
|
std::map<mtx::identifiers::User, std::map<std::string, decltype(request)>> body;
|
||||||
body[mtx::identifiers::parse<mtx::identifiers::User>(e.sender)]["*"] = request;
|
body[mtx::identifiers::parse<mtx::identifiers::User>(e.sender)]["*"] = request;
|
||||||
|
@ -1171,7 +1171,7 @@ decryptEvent(const MegolmSessionIndex &index,
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Add missing fields for the event.
|
// Add missing fields for the event.
|
||||||
json body = json::parse(msg_str);
|
nlohmann::json body = nlohmann::json::parse(msg_str);
|
||||||
body["event_id"] = event.event_id;
|
body["event_id"] = event.event_id;
|
||||||
body["sender"] = event.sender;
|
body["sender"] = event.sender;
|
||||||
body["origin_server_ts"] = event.origin_server_ts;
|
body["origin_server_ts"] = event.origin_server_ts;
|
||||||
|
@ -1212,7 +1212,7 @@ send_encrypted_to_device_messages(const std::map<std::string, std::vector<std::s
|
||||||
{
|
{
|
||||||
static QMap<QPair<std::string, std::string>, qint64> rateLimit;
|
static QMap<QPair<std::string, std::string>, qint64> rateLimit;
|
||||||
|
|
||||||
nlohmann::json ev_json = std::visit([](const auto &e) { return json(e); }, event);
|
nlohmann::json ev_json = std::visit([](const auto &e) { return nlohmann::json(e); }, event);
|
||||||
|
|
||||||
std::map<std::string, std::vector<std::string>> keysToQuery;
|
std::map<std::string, std::vector<std::string>> keysToQuery;
|
||||||
mtx::requests::ClaimKeys claims;
|
mtx::requests::ClaimKeys claims;
|
||||||
|
@ -1450,10 +1450,10 @@ send_encrypted_to_device_messages(const std::map<std::string, std::vector<std::s
|
||||||
if (!mtx::crypto::verify_identity_signature(
|
if (!mtx::crypto::verify_identity_signature(
|
||||||
dev.second, device_id, user_id)) {
|
dev.second, device_id, user_id)) {
|
||||||
nhlog::crypto()->warn("failed to verify identity keys: {}",
|
nhlog::crypto()->warn("failed to verify identity keys: {}",
|
||||||
json(dev.second).dump(2));
|
nlohmann::json(dev.second).dump(2));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} catch (const json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::crypto()->warn("failed to parse device key json: {}", e.what());
|
nhlog::crypto()->warn("failed to parse device key json: {}", e.what());
|
||||||
continue;
|
continue;
|
||||||
} catch (const mtx::crypto::olm_exception &e) {
|
} catch (const mtx::crypto::olm_exception &e) {
|
||||||
|
|
|
@ -152,7 +152,7 @@ SelfVerificationStatus::setupCrosssigning(bool useSSSS, QString password, bool u
|
||||||
olm::client()->identity_keys().ed25519 &&
|
olm::client()->identity_keys().ed25519 &&
|
||||||
myKey.keys["curve25519:" + http::client()->device_id()] ==
|
myKey.keys["curve25519:" + http::client()->device_id()] ==
|
||||||
olm::client()->identity_keys().curve25519) {
|
olm::client()->identity_keys().curve25519) {
|
||||||
json j = myKey;
|
nlohmann::json j = myKey;
|
||||||
j.erase("signatures");
|
j.erase("signatures");
|
||||||
j.erase("unsigned");
|
j.erase("unsigned");
|
||||||
|
|
||||||
|
|
|
@ -241,9 +241,9 @@ EventStore::EventStore(std::string room_id, QObject *)
|
||||||
|
|
||||||
std::visit(
|
std::visit(
|
||||||
[&pending_event, &original_encrypted, &session, this](auto &msg) {
|
[&pending_event, &original_encrypted, &session, this](auto &msg) {
|
||||||
json doc = {{"type", mtx::events::to_string(msg.type)},
|
nlohmann::json doc = {{"type", mtx::events::to_string(msg.type)},
|
||||||
{"content", json(msg.content)},
|
{"content", nlohmann::json(msg.content)},
|
||||||
{"room_id", room_id_}};
|
{"room_id", room_id_}};
|
||||||
|
|
||||||
auto data = olm::encrypt_group_message_with_session(
|
auto data = olm::encrypt_group_message_with_session(
|
||||||
session.session, http::client()->device_id(), doc);
|
session.session, http::client()->device_id(), doc);
|
||||||
|
|
|
@ -1346,9 +1346,9 @@ TimelineModel::sendEncryptedMessage(mtx::events::RoomEvent<T> msg, mtx::events::
|
||||||
using namespace mtx::events;
|
using namespace mtx::events;
|
||||||
using namespace mtx::identifiers;
|
using namespace mtx::identifiers;
|
||||||
|
|
||||||
json doc = {{"type", mtx::events::to_string(eventType)},
|
nlohmann::json doc = {{"type", mtx::events::to_string(eventType)},
|
||||||
{"content", json(msg.content)},
|
{"content", nlohmann::json(msg.content)},
|
||||||
{"room_id", room_id}};
|
{"room_id", room_id}};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> event;
|
mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> event;
|
||||||
|
|
Loading…
Reference in a new issue