mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 03:00:46 +03:00
Fix compilation without implicit nlohmann conversions
This commit is contained in:
parent
28acea55e2
commit
ef941920ea
10 changed files with 86 additions and 71 deletions
|
@ -576,7 +576,7 @@ if(USE_BUNDLED_MTXCLIENT)
|
|||
FetchContent_Declare(
|
||||
MatrixClient
|
||||
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
|
||||
GIT_TAG a6ca9714490ad0bb0c032e00be4f7d7ebd683378
|
||||
GIT_TAG e13a71d3ca883e8ed88e0b60adb0914120328bac
|
||||
)
|
||||
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
|
||||
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")
|
||||
|
|
|
@ -203,7 +203,7 @@ modules:
|
|||
buildsystem: cmake-ninja
|
||||
name: mtxclient
|
||||
sources:
|
||||
- commit: a6ca9714490ad0bb0c032e00be4f7d7ebd683378
|
||||
- commit: e13a71d3ca883e8ed88e0b60adb0914120328bac
|
||||
#tag: v0.7.0
|
||||
type: git
|
||||
url: https://github.com/Nheko-Reborn/mtxclient.git
|
||||
|
|
114
src/Cache.cpp
114
src/Cache.cpp
|
@ -561,7 +561,7 @@ Cache::roomEncryptionSettings(const std::string &room_id)
|
|||
|
||||
if (res) {
|
||||
try {
|
||||
StateEvent<Encryption> msg = json::parse(event);
|
||||
StateEvent<Encryption> msg = json::parse(event).get<StateEvent<Encryption>>();
|
||||
|
||||
return msg.content;
|
||||
} catch (const json::exception &e) {
|
||||
|
@ -810,7 +810,8 @@ Cache::getOutboundMegolmSession(const std::string &room_id)
|
|||
auto obj = json::parse(value);
|
||||
|
||||
OutboundGroupSessionDataRef ref{};
|
||||
ref.session = unpickle<OutboundSessionObject>(obj.at("session"), pickle_secret_);
|
||||
ref.session =
|
||||
unpickle<OutboundSessionObject>(obj.at("session").get<std::string>(), pickle_secret_);
|
||||
|
||||
MegolmSessionIndex index;
|
||||
index.room_id = room_id;
|
||||
|
@ -1155,7 +1156,7 @@ Cache::runMigrations()
|
|||
|
||||
if (oldMessages.prev_batch.empty())
|
||||
oldMessages.prev_batch = j["token"].get<std::string>();
|
||||
else if (j["token"] != oldMessages.prev_batch)
|
||||
else if (j["token"].get<std::string>() != oldMessages.prev_batch)
|
||||
break;
|
||||
|
||||
mtx::events::collections::TimelineEvent te;
|
||||
|
@ -1325,7 +1326,7 @@ Cache::runMigrations()
|
|||
std::map<std::string, std::string> megolmSessionData;
|
||||
while (cursor.get(key, value, MDB_NEXT)) {
|
||||
auto indexVal = nlohmann::json::parse(key);
|
||||
auto sender_key = indexVal["sender_key"];
|
||||
auto sender_key = indexVal["sender_key"].get<std::string>();
|
||||
indexVal.erase("sender_key");
|
||||
|
||||
std::string_view dataVal;
|
||||
|
@ -1549,7 +1550,8 @@ Cache::updateState(const std::string &room, const mtx::responses::StateEvents &s
|
|||
std::string_view data;
|
||||
if (roomsDb_.get(txn, room, data)) {
|
||||
try {
|
||||
updatedInfo = json::parse(std::string_view(data.data(), data.size()));
|
||||
updatedInfo =
|
||||
json::parse(std::string_view(data.data(), data.size())).get<RoomInfo>();
|
||||
} catch (const json::exception &e) {
|
||||
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
|
||||
room,
|
||||
|
@ -1669,7 +1671,8 @@ Cache::saveState(const mtx::responses::Sync &res)
|
|||
std::string_view data;
|
||||
if (roomsDb_.get(txn, room.first, data)) {
|
||||
try {
|
||||
RoomInfo tmp = json::parse(std::string_view(data.data(), data.size()));
|
||||
RoomInfo tmp =
|
||||
json::parse(std::string_view(data.data(), data.size())).get<RoomInfo>();
|
||||
updatedInfo.tags = std::move(tmp.tags);
|
||||
|
||||
updatedInfo.approximate_last_modification_ts =
|
||||
|
@ -1954,7 +1957,7 @@ Cache::singleRoomInfo(const std::string &room_id)
|
|||
// Check if the room is joined.
|
||||
if (roomsDb_.get(txn, room_id, data)) {
|
||||
try {
|
||||
RoomInfo tmp = json::parse(data);
|
||||
RoomInfo tmp = json::parse(data).get<RoomInfo>();
|
||||
tmp.member_count = getMembersDb(txn, room_id).size(txn);
|
||||
tmp.join_rule = getRoomJoinRule(txn, statesdb);
|
||||
tmp.guest_access = getRoomGuestAccess(txn, statesdb);
|
||||
|
@ -1989,7 +1992,7 @@ Cache::getRoomInfo(const std::vector<std::string> &rooms)
|
|||
// Check if the room is joined.
|
||||
if (roomsDb_.get(txn, room, data)) {
|
||||
try {
|
||||
RoomInfo tmp = json::parse(data);
|
||||
RoomInfo tmp = json::parse(data).get<RoomInfo>();
|
||||
tmp.member_count = getMembersDb(txn, room).size(txn);
|
||||
tmp.join_rule = getRoomJoinRule(txn, statesdb);
|
||||
tmp.guest_access = getRoomGuestAccess(txn, statesdb);
|
||||
|
@ -2005,7 +2008,7 @@ Cache::getRoomInfo(const std::vector<std::string> &rooms)
|
|||
// Check if the room is an invite.
|
||||
if (invitesDb_.get(txn, room, data)) {
|
||||
try {
|
||||
RoomInfo tmp = json::parse(std::string_view(data));
|
||||
RoomInfo tmp = json::parse(std::string_view(data)).get<RoomInfo>();
|
||||
tmp.member_count = getInviteMembersDb(txn, room).size(txn);
|
||||
|
||||
room_info.emplace(QString::fromStdString(room), std::move(tmp));
|
||||
|
@ -2241,7 +2244,7 @@ Cache::roomInfo(bool withInvites)
|
|||
// Gather info about the joined rooms.
|
||||
auto roomsCursor = lmdb::cursor::open(txn, roomsDb_);
|
||||
while (roomsCursor.get(room_id, room_data, MDB_NEXT)) {
|
||||
RoomInfo tmp = json::parse(std::move(room_data));
|
||||
RoomInfo tmp = json::parse(std::move(room_data)).get<RoomInfo>();
|
||||
tmp.member_count = getMembersDb(txn, std::string(room_id)).size(txn);
|
||||
result.insert(QString::fromStdString(std::string(room_id)), std::move(tmp));
|
||||
}
|
||||
|
@ -2251,7 +2254,7 @@ Cache::roomInfo(bool withInvites)
|
|||
// Gather info about the invites.
|
||||
auto invitesCursor = lmdb::cursor::open(txn, invitesDb_);
|
||||
while (invitesCursor.get(room_id, room_data, MDB_NEXT)) {
|
||||
RoomInfo tmp = json::parse(room_data);
|
||||
RoomInfo tmp = json::parse(room_data).get<RoomInfo>();
|
||||
tmp.member_count = getInviteMembersDb(txn, std::string(room_id)).size(txn);
|
||||
result.insert(QString::fromStdString(std::string(room_id)), std::move(tmp));
|
||||
}
|
||||
|
@ -2478,7 +2481,7 @@ Cache::invites()
|
|||
|
||||
while (cursor.get(room_id, room_data, MDB_NEXT)) {
|
||||
try {
|
||||
RoomInfo tmp = json::parse(room_data);
|
||||
RoomInfo tmp = json::parse(room_data).get<RoomInfo>();
|
||||
tmp.member_count = getInviteMembersDb(txn, std::string(room_id)).size(txn);
|
||||
result.insert(QString::fromStdString(std::string(room_id)), std::move(tmp));
|
||||
} catch (const json::exception &e) {
|
||||
|
@ -2506,7 +2509,7 @@ Cache::invite(std::string_view roomid)
|
|||
|
||||
if (invitesDb_.get(txn, roomid, room_data)) {
|
||||
try {
|
||||
RoomInfo tmp = json::parse(room_data);
|
||||
RoomInfo tmp = json::parse(room_data).get<RoomInfo>();
|
||||
tmp.member_count = getInviteMembersDb(txn, std::string(roomid)).size(txn);
|
||||
result = std::move(tmp);
|
||||
} catch (const json::exception &e) {
|
||||
|
@ -2532,7 +2535,8 @@ Cache::getRoomAvatarUrl(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersd
|
|||
|
||||
if (res) {
|
||||
try {
|
||||
StateEvent<Avatar> msg = json::parse(std::string_view(event.data(), event.size()));
|
||||
StateEvent<Avatar> msg =
|
||||
json::parse(std::string_view(event.data(), event.size())).get<StateEvent<Avatar>>();
|
||||
|
||||
if (!msg.content.url.empty())
|
||||
return QString::fromStdString(msg.content.url);
|
||||
|
@ -2553,7 +2557,7 @@ Cache::getRoomAvatarUrl(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersd
|
|||
// Resolve avatar for 1-1 chats.
|
||||
while (cursor.get(user_id, member_data, MDB_NEXT)) {
|
||||
try {
|
||||
MemberInfo m = json::parse(member_data);
|
||||
MemberInfo m = json::parse(member_data).get<MemberInfo>();
|
||||
if (user_id == localUserId_.toStdString()) {
|
||||
fallback_url = m.avatar_url;
|
||||
continue;
|
||||
|
@ -2583,7 +2587,8 @@ Cache::getRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb)
|
|||
|
||||
if (res) {
|
||||
try {
|
||||
StateEvent<Name> msg = json::parse(std::string_view(event.data(), event.size()));
|
||||
StateEvent<Name> msg =
|
||||
json::parse(std::string_view(event.data(), event.size())).get<StateEvent<Name>>();
|
||||
|
||||
if (!msg.content.name.empty())
|
||||
return QString::fromStdString(msg.content.name);
|
||||
|
@ -2597,7 +2602,8 @@ Cache::getRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb)
|
|||
if (res) {
|
||||
try {
|
||||
StateEvent<CanonicalAlias> msg =
|
||||
json::parse(std::string_view(event.data(), event.size()));
|
||||
json::parse(std::string_view(event.data(), event.size()))
|
||||
.get<StateEvent<CanonicalAlias>>();
|
||||
|
||||
if (!msg.content.alias.empty())
|
||||
return QString::fromStdString(msg.content.alias);
|
||||
|
@ -2616,7 +2622,7 @@ Cache::getRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb)
|
|||
|
||||
while (cursor.get(user_id, member_data, MDB_NEXT) && ii < 3) {
|
||||
try {
|
||||
members.emplace(user_id, json::parse(member_data));
|
||||
members.emplace(user_id, json::parse(member_data).get<MemberInfo>());
|
||||
} catch (const json::exception &e) {
|
||||
nhlog::db()->warn("failed to parse member info: {}", e.what());
|
||||
}
|
||||
|
@ -2657,7 +2663,8 @@ Cache::getRoomJoinRule(lmdb::txn &txn, lmdb::dbi &statesdb)
|
|||
|
||||
if (res) {
|
||||
try {
|
||||
StateEvent<state::JoinRules> msg = json::parse(event);
|
||||
StateEvent<state::JoinRules> msg =
|
||||
json::parse(event).get<StateEvent<state::JoinRules>>();
|
||||
return msg.content.join_rule;
|
||||
} catch (const json::exception &e) {
|
||||
nhlog::db()->warn("failed to parse m.room.join_rule event: {}", e.what());
|
||||
|
@ -2677,7 +2684,7 @@ Cache::getRoomGuestAccess(lmdb::txn &txn, lmdb::dbi &statesdb)
|
|||
|
||||
if (res) {
|
||||
try {
|
||||
StateEvent<GuestAccess> msg = json::parse(event);
|
||||
StateEvent<GuestAccess> msg = json::parse(event).get<StateEvent<GuestAccess>>();
|
||||
return msg.content.guest_access == AccessState::CanJoin;
|
||||
} catch (const json::exception &e) {
|
||||
nhlog::db()->warn("failed to parse m.room.guest_access event: {}", e.what());
|
||||
|
@ -2697,7 +2704,7 @@ Cache::getRoomTopic(lmdb::txn &txn, lmdb::dbi &statesdb)
|
|||
|
||||
if (res) {
|
||||
try {
|
||||
StateEvent<Topic> msg = json::parse(event);
|
||||
StateEvent<Topic> msg = json::parse(event).get<StateEvent<Topic>>();
|
||||
|
||||
if (!msg.content.topic.empty())
|
||||
return QString::fromStdString(msg.content.topic);
|
||||
|
@ -2720,7 +2727,7 @@ Cache::getRoomVersion(lmdb::txn &txn, lmdb::dbi &statesdb)
|
|||
|
||||
if (res) {
|
||||
try {
|
||||
StateEvent<Create> msg = json::parse(event);
|
||||
StateEvent<Create> msg = json::parse(event).get<StateEvent<Create>>();
|
||||
|
||||
if (!msg.content.room_version.empty())
|
||||
return QString::fromStdString(msg.content.room_version);
|
||||
|
@ -2744,7 +2751,7 @@ Cache::getRoomIsSpace(lmdb::txn &txn, lmdb::dbi &statesdb)
|
|||
|
||||
if (res) {
|
||||
try {
|
||||
StateEvent<Create> msg = json::parse(event);
|
||||
StateEvent<Create> msg = json::parse(event).get<StateEvent<Create>>();
|
||||
|
||||
return msg.content.type == mtx::events::state::room_type::space;
|
||||
} catch (const json::exception &e) {
|
||||
|
@ -2767,7 +2774,7 @@ Cache::getInviteRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &members
|
|||
|
||||
if (res) {
|
||||
try {
|
||||
StrippedEvent<state::Name> msg = json::parse(event);
|
||||
StrippedEvent<state::Name> msg = json::parse(event).get<StrippedEvent<state::Name>>();
|
||||
return QString::fromStdString(msg.content.name);
|
||||
} catch (const json::exception &e) {
|
||||
nhlog::db()->warn("failed to parse m.room.name event: {}", e.what());
|
||||
|
@ -2782,7 +2789,7 @@ Cache::getInviteRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &members
|
|||
continue;
|
||||
|
||||
try {
|
||||
MemberInfo tmp = json::parse(member_data);
|
||||
MemberInfo tmp = json::parse(member_data).get<MemberInfo>();
|
||||
cursor.close();
|
||||
|
||||
return QString::fromStdString(tmp.name);
|
||||
|
@ -2807,7 +2814,8 @@ Cache::getInviteRoomAvatarUrl(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &me
|
|||
|
||||
if (res) {
|
||||
try {
|
||||
StrippedEvent<state::Avatar> msg = json::parse(event);
|
||||
StrippedEvent<state::Avatar> msg =
|
||||
json::parse(event).get<StrippedEvent<state::Avatar>>();
|
||||
return QString::fromStdString(msg.content.url);
|
||||
} catch (const json::exception &e) {
|
||||
nhlog::db()->warn("failed to parse m.room.avatar event: {}", e.what());
|
||||
|
@ -2822,7 +2830,7 @@ Cache::getInviteRoomAvatarUrl(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &me
|
|||
continue;
|
||||
|
||||
try {
|
||||
MemberInfo tmp = json::parse(member_data);
|
||||
MemberInfo tmp = json::parse(member_data).get<MemberInfo>();
|
||||
cursor.close();
|
||||
|
||||
return QString::fromStdString(tmp.avatar_url);
|
||||
|
@ -2847,7 +2855,7 @@ Cache::getInviteRoomTopic(lmdb::txn &txn, lmdb::dbi &db)
|
|||
|
||||
if (res) {
|
||||
try {
|
||||
StrippedEvent<Topic> msg = json::parse(event);
|
||||
StrippedEvent<Topic> msg = json::parse(event).get<StrippedEvent<Topic>>();
|
||||
return QString::fromStdString(msg.content.topic);
|
||||
} catch (const json::exception &e) {
|
||||
nhlog::db()->warn("failed to parse m.room.topic event: {}", e.what());
|
||||
|
@ -2868,7 +2876,7 @@ Cache::getInviteRoomIsSpace(lmdb::txn &txn, lmdb::dbi &db)
|
|||
|
||||
if (res) {
|
||||
try {
|
||||
StrippedEvent<Create> msg = json::parse(event);
|
||||
StrippedEvent<Create> msg = json::parse(event).get<StrippedEvent<Create>>();
|
||||
return msg.content.type == mtx::events::state::room_type::space;
|
||||
} catch (const json::exception &e) {
|
||||
nhlog::db()->warn("failed to parse m.room.topic event: {}", e.what());
|
||||
|
@ -2909,7 +2917,7 @@ Cache::getMember(const std::string &room_id, const std::string &user_id)
|
|||
|
||||
std::string_view info;
|
||||
if (membersdb.get(txn, user_id, info)) {
|
||||
MemberInfo m = json::parse(info);
|
||||
MemberInfo m = json::parse(info).get<MemberInfo>();
|
||||
return m;
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
|
@ -2943,7 +2951,7 @@ Cache::getMembers(const std::string &room_id, std::size_t startIndex, std::size_
|
|||
break;
|
||||
|
||||
try {
|
||||
MemberInfo tmp = json::parse(user_data);
|
||||
MemberInfo tmp = json::parse(user_data).get<MemberInfo>();
|
||||
members.emplace_back(RoomMember{QString::fromStdString(std::string(user_id)),
|
||||
QString::fromStdString(tmp.name)});
|
||||
} catch (const json::exception &e) {
|
||||
|
@ -2983,7 +2991,7 @@ Cache::getMembersFromInvite(const std::string &room_id, std::size_t startIndex,
|
|||
break;
|
||||
|
||||
try {
|
||||
MemberInfo tmp = json::parse(user_data);
|
||||
MemberInfo tmp = json::parse(user_data).get<MemberInfo>();
|
||||
members.emplace_back(RoomMember{QString::fromStdString(std::string(user_id)),
|
||||
QString::fromStdString(tmp.name),
|
||||
tmp.is_direct});
|
||||
|
@ -3745,7 +3753,7 @@ Cache::spaces()
|
|||
if (!space_child.empty()) {
|
||||
std::string_view room_data;
|
||||
if (roomsDb_.get(txn, space_id, room_data)) {
|
||||
RoomInfo tmp = json::parse(std::move(room_data));
|
||||
RoomInfo tmp = json::parse(std::move(room_data)).get<RoomInfo>();
|
||||
ret.insert(QString::fromUtf8(space_id.data(), space_id.size()), tmp);
|
||||
} else {
|
||||
ret.insert(QString::fromUtf8(space_id.data(), space_id.size()), std::nullopt);
|
||||
|
@ -3926,7 +3934,8 @@ Cache::hasEnoughPowerLevel(const std::vector<mtx::events::EventType> &eventTypes
|
|||
|
||||
if (res) {
|
||||
try {
|
||||
StateEvent<PowerLevels> msg = json::parse(std::string_view(event.data(), event.size()));
|
||||
StateEvent<PowerLevels> msg = json::parse(std::string_view(event.data(), event.size()))
|
||||
.get<StateEvent<PowerLevels>>();
|
||||
|
||||
user_level = msg.content.user_level(user_id);
|
||||
|
||||
|
@ -4121,7 +4130,8 @@ Cache::presence(const std::string &user_id)
|
|||
auto res = presenceDb_.get(txn, user_id, presenceVal);
|
||||
|
||||
if (res) {
|
||||
presence_ = json::parse(std::string_view(presenceVal.data(), presenceVal.size()));
|
||||
presence_ = json::parse(std::string_view(presenceVal.data(), presenceVal.size()))
|
||||
.get<mtx::events::presence::Presence>();
|
||||
}
|
||||
|
||||
return presence_;
|
||||
|
@ -4484,7 +4494,7 @@ Cache::verificationCache(const std::string &user_id, lmdb::txn &txn)
|
|||
VerificationCache verified_state;
|
||||
auto res = db.get(txn, user_id, verifiedVal);
|
||||
if (res) {
|
||||
verified_state = json::parse(verifiedVal);
|
||||
verified_state = json::parse(verifiedVal).get<VerificationCache>();
|
||||
return verified_state;
|
||||
} else {
|
||||
return {};
|
||||
|
@ -4507,7 +4517,7 @@ Cache::markDeviceVerified(const std::string &user_id, const std::string &key)
|
|||
VerificationCache verified_state;
|
||||
auto res = db.get(txn, user_id, val);
|
||||
if (res) {
|
||||
verified_state = json::parse(val);
|
||||
verified_state = json::parse(val).get<VerificationCache>();
|
||||
}
|
||||
|
||||
for (const auto &device : verified_state.device_verified)
|
||||
|
@ -4554,7 +4564,7 @@ Cache::markDeviceUnverified(const std::string &user_id, const std::string &key)
|
|||
VerificationCache verified_state;
|
||||
auto res = db.get(txn, user_id, val);
|
||||
if (res) {
|
||||
verified_state = json::parse(val);
|
||||
verified_state = json::parse(val).get<VerificationCache>();
|
||||
}
|
||||
|
||||
verified_state.device_verified.erase(key);
|
||||
|
@ -4751,15 +4761,15 @@ to_json(json &j, const RoomInfo &info)
|
|||
void
|
||||
from_json(const json &j, RoomInfo &info)
|
||||
{
|
||||
info.name = j.at("name");
|
||||
info.topic = j.at("topic");
|
||||
info.avatar_url = j.at("avatar_url");
|
||||
info.name = j.at("name").get<std::string>();
|
||||
info.topic = j.at("topic").get<std::string>();
|
||||
info.avatar_url = j.at("avatar_url").get<std::string>();
|
||||
info.version = j.value(
|
||||
"version", QCoreApplication::translate("RoomInfo", "no version stored").toStdString());
|
||||
info.is_invite = j.at("is_invite");
|
||||
info.is_invite = j.at("is_invite").get<bool>();
|
||||
info.is_space = j.value("is_space", false);
|
||||
info.join_rule = j.at("join_rule");
|
||||
info.guest_access = j.at("guest_access");
|
||||
info.join_rule = j.at("join_rule").get<mtx::events::state::JoinRule>();
|
||||
info.guest_access = j.at("guest_access").get<bool>();
|
||||
|
||||
info.approximate_last_modification_ts = j.value("app_l_ts", 0);
|
||||
|
||||
|
@ -4767,7 +4777,7 @@ from_json(const json &j, RoomInfo &info)
|
|||
info.highlight_count = j.value("highlight_count", 0);
|
||||
|
||||
if (j.count("member_count"))
|
||||
info.member_count = j.at("member_count");
|
||||
info.member_count = j.at("member_count").get<size_t>();
|
||||
|
||||
if (j.count("tags"))
|
||||
info.tags = j.at("tags").get<std::vector<std::string>>();
|
||||
|
@ -4798,8 +4808,8 @@ to_json(json &j, const MemberInfo &info)
|
|||
void
|
||||
from_json(const json &j, MemberInfo &info)
|
||||
{
|
||||
info.name = j.at("name");
|
||||
info.avatar_url = j.at("avatar_url");
|
||||
info.name = j.at("name").get<std::string>();
|
||||
info.avatar_url = j.at("avatar_url").get<std::string>();
|
||||
info.is_direct = j.value("is_direct", false);
|
||||
}
|
||||
|
||||
|
@ -4846,7 +4856,7 @@ to_json(nlohmann::json &obj, const GroupSessionData &msg)
|
|||
void
|
||||
from_json(const nlohmann::json &obj, GroupSessionData &msg)
|
||||
{
|
||||
msg.message_index = obj.at("message_index");
|
||||
msg.message_index = obj.at("message_index").get<uint64_t>();
|
||||
msg.timestamp = obj.value("ts", 0ULL);
|
||||
msg.trusted = obj.value("trust", true);
|
||||
|
||||
|
@ -4870,8 +4880,8 @@ to_json(nlohmann::json &obj, const DevicePublicKeys &msg)
|
|||
void
|
||||
from_json(const nlohmann::json &obj, DevicePublicKeys &msg)
|
||||
{
|
||||
msg.ed25519 = obj.at("ed25519");
|
||||
msg.curve25519 = obj.at("curve25519");
|
||||
msg.ed25519 = obj.at("ed25519").get<std::string>();
|
||||
msg.curve25519 = obj.at("curve25519").get<std::string>();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -4884,8 +4894,8 @@ to_json(nlohmann::json &obj, const MegolmSessionIndex &msg)
|
|||
void
|
||||
from_json(const nlohmann::json &obj, MegolmSessionIndex &msg)
|
||||
{
|
||||
msg.room_id = obj.at("room_id");
|
||||
msg.session_id = obj.at("session_id");
|
||||
msg.room_id = obj.at("room_id").get<std::string>();
|
||||
msg.session_id = obj.at("session_id").get<std::string>();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1257,7 +1257,8 @@ ChatPage::decryptDownloadedSecrets(mtx::secret_storage::AesHmacSha2KeyDescriptio
|
|||
json j = deviceKeys->master_keys;
|
||||
j.erase("signatures");
|
||||
j.erase("unsigned");
|
||||
mtx::crypto::CrossSigningKeys master_key = j;
|
||||
mtx::crypto::CrossSigningKeys master_key =
|
||||
j.get<mtx::crypto::CrossSigningKeys>();
|
||||
master_key.signatures[http::client()->user_id().to_string()]
|
||||
["ed25519:" + http::client()->device_id()] =
|
||||
olm::client()->sign_message(j.dump());
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <spdlog/logger.h>
|
||||
|
||||
namespace nhlog {
|
||||
void
|
||||
|
|
|
@ -270,7 +270,8 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *,
|
|||
json j = their_keys.master_keys;
|
||||
j.erase("signatures");
|
||||
j.erase("unsigned");
|
||||
mtx::crypto::CrossSigningKeys master_key = j;
|
||||
mtx::crypto::CrossSigningKeys master_key =
|
||||
j.get<mtx::crypto::CrossSigningKeys>();
|
||||
master_key.signatures[utils::localUser().toStdString()]
|
||||
["ed25519:" + http::client()->device_id()] =
|
||||
olm::client()->sign_message(j.dump());
|
||||
|
@ -292,7 +293,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *,
|
|||
continue;
|
||||
auto ssk = mtx::crypto::PkSigning::from_seed(*secret);
|
||||
|
||||
mtx::crypto::DeviceKeys dev = j;
|
||||
mtx::crypto::DeviceKeys dev = j.get<mtx::crypto::DeviceKeys>();
|
||||
dev.signatures[utils::localUser().toStdString()]
|
||||
["ed25519:" + ssk.public_key()] = ssk.sign(j.dump());
|
||||
|
||||
|
@ -314,7 +315,8 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *,
|
|||
continue;
|
||||
auto usk = mtx::crypto::PkSigning::from_seed(*secret);
|
||||
|
||||
mtx::crypto::CrossSigningKeys master_key = j;
|
||||
mtx::crypto::CrossSigningKeys master_key =
|
||||
j.get<mtx::crypto::CrossSigningKeys>();
|
||||
master_key.signatures[utils::localUser().toStdString()]
|
||||
["ed25519:" + usk.public_key()] = usk.sign(j.dump());
|
||||
|
||||
|
|
|
@ -47,8 +47,8 @@ from_json(const nlohmann::json &obj, OlmMessage &msg)
|
|||
if (obj.at("content").at("algorithm") != OLM_ALGO)
|
||||
throw std::invalid_argument("invalid algorithm for olm message");
|
||||
|
||||
msg.sender = obj.at("sender");
|
||||
msg.sender_key = obj.at("content").at("sender_key");
|
||||
msg.sender = obj.at("sender").get<std::string>();
|
||||
msg.sender_key = obj.at("content").at("sender_key").get<std::string>();
|
||||
msg.ciphertext = obj.at("content")
|
||||
.at("ciphertext")
|
||||
.get<std::map<std::string, mtx::events::msg::OlmCipherContent>>();
|
||||
|
@ -122,11 +122,11 @@ handle_to_device_messages(const std::vector<mtx::events::collections::DeviceEven
|
|||
continue;
|
||||
}
|
||||
|
||||
std::string msg_type = j_msg.at("type");
|
||||
std::string msg_type = j_msg.at("type").get<std::string>();
|
||||
|
||||
if (msg_type == to_string(mtx::events::EventType::RoomEncrypted)) {
|
||||
try {
|
||||
olm::OlmMessage olm_msg = j_msg;
|
||||
olm::OlmMessage olm_msg = j_msg.get<olm::OlmMessage>();
|
||||
cache::client()->query_keys(
|
||||
olm_msg.sender, [olm_msg](const UserKeyCache &userKeys, mtx::http::RequestErr e) {
|
||||
if (e) {
|
||||
|
@ -147,7 +147,8 @@ handle_to_device_messages(const std::vector<mtx::events::collections::DeviceEven
|
|||
} else if (msg_type == to_string(mtx::events::EventType::RoomKeyRequest)) {
|
||||
nhlog::crypto()->warn("handling key request event: {}", j_msg.dump(2));
|
||||
try {
|
||||
mtx::events::DeviceEvent<mtx::events::msg::KeyRequest> req = j_msg;
|
||||
mtx::events::DeviceEvent<mtx::events::msg::KeyRequest> req =
|
||||
j_msg.get<mtx::events::DeviceEvent<mtx::events::msg::KeyRequest>>();
|
||||
if (req.content.action == mtx::events::msg::RequestAction::Request)
|
||||
handle_key_request_message(req);
|
||||
else
|
||||
|
@ -246,14 +247,14 @@ handle_olm_message(const OlmMessage &msg, const UserKeyCache &otherUserDeviceKey
|
|||
// claiming to have sent messages which they didn't. sender must correspond
|
||||
// to the user who sent the event, recipient to the local user, and
|
||||
// recipient_keys to the local ed25519 key.
|
||||
std::string receiver_ed25519 = payload["recipient_keys"]["ed25519"];
|
||||
std::string receiver_ed25519 = payload["recipient_keys"]["ed25519"].get<std::string>();
|
||||
if (receiver_ed25519.empty() ||
|
||||
receiver_ed25519 != olm::client()->identity_keys().ed25519) {
|
||||
nhlog::crypto()->warn("Decrypted event doesn't include our ed25519: {}",
|
||||
payload.dump());
|
||||
return;
|
||||
}
|
||||
std::string receiver = payload["recipient"];
|
||||
std::string receiver = payload["recipient"].get<std::string>();
|
||||
if (receiver.empty() || receiver != http::client()->user_id().to_string()) {
|
||||
nhlog::crypto()->warn("Decrypted event doesn't include our user_id: {}",
|
||||
payload.dump());
|
||||
|
@ -266,7 +267,7 @@ handle_olm_message(const OlmMessage &msg, const UserKeyCache &otherUserDeviceKey
|
|||
// this check, a client cannot be sure that the sender device owns the
|
||||
// private part of the ed25519 key it claims to have in the Olm payload.
|
||||
// This is crucial when the ed25519 key corresponds to a verified device.
|
||||
std::string sender_ed25519 = payload["keys"]["ed25519"];
|
||||
std::string sender_ed25519 = payload["keys"]["ed25519"].get<std::string>();
|
||||
if (sender_ed25519.empty()) {
|
||||
nhlog::crypto()->warn("Decrypted event doesn't include sender ed25519: {}",
|
||||
payload.dump());
|
||||
|
@ -294,7 +295,7 @@ handle_olm_message(const OlmMessage &msg, const UserKeyCache &otherUserDeviceKey
|
|||
}
|
||||
|
||||
{
|
||||
std::string msg_type = payload["type"];
|
||||
std::string msg_type = payload["type"].get<std::string>();
|
||||
json event_array = json::array();
|
||||
event_array.push_back(payload);
|
||||
|
||||
|
@ -1334,7 +1335,7 @@ send_encrypted_to_device_messages(const std::map<std::string, std::vector<std::s
|
|||
continue;
|
||||
}
|
||||
|
||||
auto otk = rd.second.begin()->at("key");
|
||||
auto otk = rd.second.begin()->at("key").get<std::string>();
|
||||
|
||||
auto sign_key = pks.at(user_id).at(device_id).ed25519;
|
||||
auto id_key = pks.at(user_id).at(device_id).curve25519;
|
||||
|
|
|
@ -464,7 +464,7 @@ private:
|
|||
|
||||
friend struct SendMessageVisitor;
|
||||
|
||||
int notification_count = 0, highlight_count = 0;
|
||||
uint64_t notification_count = 0, highlight_count = 0;
|
||||
|
||||
unsigned int relatedEventCacheBuster = 0;
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <mtx/responses/common.hpp>
|
||||
|
||||
#include "Logging.h"
|
||||
#include "MatrixClient.h"
|
||||
#include "dialogs/FallbackAuth.h"
|
||||
#include "dialogs/ReCaptcha.h"
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
#include <MatrixClient.h>
|
||||
#include <mtxclient/http/client.hpp>
|
||||
|
||||
class UIA : public QObject
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue