summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--io.github.NhekoReborn.Nheko.yaml2
-rw-r--r--src/Cache.cpp296
-rw-r--r--src/Cache_p.h35
-rw-r--r--src/ChatPage.cpp8
-rw-r--r--src/encryption/DeviceVerificationFlow.cpp6
-rw-r--r--src/encryption/Olm.cpp22
-rw-r--r--src/encryption/SelfVerificationStatus.cpp2
-rw-r--r--src/timeline/EventStore.cpp6
-rw-r--r--src/timeline/TimelineModel.cpp6
10 files changed, 198 insertions, 187 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 700609ca..b796938b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -579,7 +579,7 @@ if(USE_BUNDLED_MTXCLIENT)
 	FetchContent_Declare(
 		MatrixClient
 		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_TESTS OFF CACHE INTERNAL "")
diff --git a/io.github.NhekoReborn.Nheko.yaml b/io.github.NhekoReborn.Nheko.yaml
index 2f502c96..119e99fd 100644
--- a/io.github.NhekoReborn.Nheko.yaml
+++ b/io.github.NhekoReborn.Nheko.yaml
@@ -203,7 +203,7 @@ modules:
     buildsystem: cmake-ninja
     name: mtxclient
     sources:
-      - commit: d34fb853256c5d3779f6a837e17ee2583d1c4089
+      - commit: b26cd34fe8806f14a1daff2ca4f98474863acf9b
         #tag: v0.7.0
         type: git
         url: https://github.com/Nheko-Reborn/mtxclient.git
diff --git a/src/Cache.cpp b/src/Cache.cpp
index b2027114..1df16bf5 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -561,10 +561,11 @@ Cache::roomEncryptionSettings(const std::string &room_id)
 
         if (res) {
             try {
-                StateEvent<Encryption> msg = json::parse(event).get<StateEvent<Encryption>>();
+                StateEvent<Encryption> msg =
+                  nlohmann::json::parse(event).get<StateEvent<Encryption>>();
 
                 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());
                 return Encryption{};
             }
@@ -603,7 +604,7 @@ Cache::exportSessionKeys()
             using namespace mtx::crypto;
 
             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>();
                 exported.sender_key = data.sender_key;
                 if (!data.sender_claimed_ed25519_key.empty())
@@ -661,7 +662,7 @@ Cache::saveInboundMegolmSession(const MegolmSessionIndex &index,
                                 const GroupSessionData &data)
 {
     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_);
 
     auto txn = lmdb::txn::begin(env_);
@@ -677,7 +678,7 @@ Cache::saveInboundMegolmSession(const MegolmSessionIndex &index,
     }
 
     inboundMegolmSessionDb_.put(txn, key, pickled);
-    megolmSessionDataDb_.put(txn, key, json(data).dump());
+    megolmSessionDataDb_.put(txn, key, nlohmann::json(data).dump());
     txn.commit();
 }
 
@@ -688,7 +689,7 @@ Cache::getInboundMegolmSession(const MegolmSessionIndex &index)
 
     try {
         auto txn        = ro_txn(env_);
-        std::string key = json(index).dump();
+        std::string key = nlohmann::json(index).dump();
         std::string_view value;
 
         if (inboundMegolmSessionDb_.get(txn, key, value)) {
@@ -709,7 +710,7 @@ Cache::inboundMegolmSessionExists(const MegolmSessionIndex &index)
 
     try {
         auto txn        = ro_txn(env_);
-        std::string key = json(index).dump();
+        std::string key = nlohmann::json(index).dump();
         std::string_view 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());
 
     // Save the updated pickled data for the session.
-    json j;
+    nlohmann::json j;
     j["session"] = pickle<OutboundSessionObject>(ptr.get(), pickle_secret_);
 
     auto txn = lmdb::txn::begin(env_);
     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();
 }
 
@@ -776,12 +777,12 @@ Cache::saveOutboundMegolmSession(const std::string &room_id,
     index.room_id    = room_id;
     index.session_id = mtx::crypto::session_id(session.get());
 
-    json j;
+    nlohmann::json j;
     j["session"] = pickled;
 
     auto txn = lmdb::txn::begin(env_);
     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();
 }
 
@@ -807,7 +808,7 @@ Cache::getOutboundMegolmSession(const std::string &room_id)
         auto txn = ro_txn(env_);
         std::string_view value;
         outboundMegolmSessionDb_.get(txn, room_id, value);
-        auto obj = json::parse(value);
+        auto obj = nlohmann::json::parse(value);
 
         OutboundGroupSessionDataRef ref{};
         ref.session =
@@ -817,7 +818,7 @@ Cache::getOutboundMegolmSession(const std::string &room_id)
         index.room_id    = room_id;
         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>();
         }
 
@@ -837,7 +838,7 @@ Cache::getMegolmSessionData(const MegolmSessionIndex &index)
         auto txn = ro_txn(env_);
 
         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>();
         }
 
@@ -868,7 +869,7 @@ Cache::saveOlmSession(const std::string &curve25519,
     stored_session.pickled_session = pickled;
     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();
 }
@@ -887,7 +888,7 @@ Cache::getOlmSession(const std::string &curve25519, const std::string &session_i
     txn.commit();
 
     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_);
     }
 
@@ -908,7 +909,7 @@ Cache::getLatestOlmSession(const std::string &curve25519)
 
     auto cursor = lmdb::cursor::open(txn, db);
     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)
             currentNewest = data;
     }
@@ -1151,7 +1152,7 @@ Cache::runMigrations()
                              roomsCursor.get(ts, stored_message, start ? MDB_FIRST : MDB_NEXT)) {
                                start = false;
 
-                               auto j = json::parse(
+                               auto j = nlohmann::json::parse(
                                  std::string_view(stored_message.data(), stored_message.size()));
 
                                if (oldMessages.prev_batch.empty())
@@ -1242,8 +1243,8 @@ Cache::runMigrations()
                    auto newDb = lmdb::dbi::open(txn, newDbName.c_str(), MDB_CREATE);
 
                    for (const auto &[key, value] : sessions) {
-                       // nhlog::db()->debug("{}\n{}", key, json(value).dump());
-                       newDb.put(txn, key, json(value).dump());
+                       // nhlog::db()->debug("{}\n{}", key, nlohmann::json(value).dump());
+                       newDb.put(txn, key, nlohmann::json(value).dump());
                    }
                }
                olmDbCursor.close();
@@ -1420,8 +1421,9 @@ Cache::readReceipts(const QString &event_id, const QString &room_id)
         bool res = readReceiptsDb_.get(txn, key, value);
 
         if (res) {
-            auto json_response = json::parse(std::string_view(value.data(), value.size()));
-            auto values        = json_response.get<std::map<std::string, uint64_t>>();
+            auto json_response =
+              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)
                 // 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.
             if (exists) {
                 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.
                 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)) {
             try {
                 updatedInfo =
-                  json::parse(std::string_view(data.data(), data.size())).get<RoomInfo>();
-            } catch (const json::exception &e) {
+                  nlohmann::json::parse(std::string_view(data.data(), data.size())).get<RoomInfo>();
+            } catch (const nlohmann::json::exception &e) {
                 nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
                                   room,
                                   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.is_space   = getRoomIsSpace(txn, statesdb);
 
-    roomsDb_.put(txn, room, json(updatedInfo).dump());
+    roomsDb_.put(txn, room, nlohmann::json(updatedInfo).dump());
     updateSpaces(txn, {room}, {room});
     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());
               },
               ev);
@@ -1671,13 +1673,13 @@ 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())).get<RoomInfo>();
+                    RoomInfo tmp = nlohmann::json::parse(std::string_view(data.data(), data.size()))
+                                     .get<RoomInfo>();
                     updatedInfo.tags = std::move(tmp.tags);
 
                     updatedInfo.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 ({}), {}: {}",
                                       room.first,
                                       std::string(data.data(), data.size()),
@@ -1745,7 +1747,7 @@ Cache::saveState(const mtx::responses::Sync &res)
                               return;
                           }
                       }
-                      auto j = json(event);
+                      auto j = nlohmann::json(event);
                       accountDataDb.put(txn, j["type"].get<std::string>(), j.dump());
                   },
                   evt);
@@ -1775,7 +1777,7 @@ Cache::saveState(const mtx::responses::Sync &res)
               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) {
             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_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};
 
-            membersdb.put(txn, msg->state_key, json(tmp).dump());
+            membersdb.put(txn, msg->state_key, nlohmann::json(tmp).dump());
         } else {
             std::visit(
               [&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());
 
                   if (!res)
-                      nhlog::db()->warn("couldn't save data: {}", json(msg).dump());
+                      nhlog::db()->warn("couldn't save data: {}", nlohmann::json(msg).dump());
               },
               e);
         }
@@ -1904,7 +1906,7 @@ Cache::savePresence(
   const std::vector<mtx::events::Event<mtx::events::presence::Presence>> &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.
         if (roomsDb_.get(txn, room_id, data)) {
             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.join_rule    = getRoomJoinRule(txn, statesdb);
                 tmp.guest_access = getRoomGuestAccess(txn, statesdb);
 
                 return tmp;
-            } catch (const json::exception &e) {
+            } catch (const nlohmann::json::exception &e) {
                 nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
                                   room_id,
                                   std::string(data.data(), data.size()),
@@ -1992,13 +1994,13 @@ 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).get<RoomInfo>();
+                RoomInfo tmp     = nlohmann::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);
 
                 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 ({}), {}: {}",
                                   room,
                                   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.
             if (invitesDb_.get(txn, room, data)) {
                 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);
 
                     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: "
                                       "room_id ({}), {}: {}",
                                       room,
@@ -2078,7 +2080,7 @@ Cache::previousBatchToken(const std::string &room_id)
         return "";
     }
 
-    auto j = json::parse(val);
+    auto j = nlohmann::json::parse(val);
 
     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;
         try {
-            mtx::events::collections::from_json(json::parse(event), te);
+            mtx::events::collections::from_json(nlohmann::json::parse(event), te);
         } catch (std::exception &e) {
             nhlog::db()->error("Failed to parse message from cache {}", e.what());
             continue;
@@ -2152,7 +2154,7 @@ Cache::getEvent(const std::string &room_id, const std::string &event_id)
 
     mtx::events::collections::TimelineEvent te;
     try {
-        mtx::events::collections::from_json(json::parse(event), te);
+        mtx::events::collections::from_json(nlohmann::json::parse(event), te);
     } catch (std::exception &e) {
         nhlog::db()->error("Failed to parse message from cache {}", e.what());
         return std::nullopt;
@@ -2244,7 +2246,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)).get<RoomInfo>();
+        RoomInfo tmp     = nlohmann::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));
     }
@@ -2254,7 +2256,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).get<RoomInfo>();
+            RoomInfo tmp     = nlohmann::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));
         }
@@ -2405,7 +2407,7 @@ Cache::lastInvisibleEventAfter(const std::string &room_id, std::string_view even
         auto cursor = lmdb::cursor::open(txn, eventOrderDb);
         cursor.get(indexVal, MDB_SET);
         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;
             if (timelineDb.get(txn, evId, temp)) {
                 return std::pair{prevIdx, std::string(prevId)};
@@ -2481,10 +2483,10 @@ Cache::invites()
 
     while (cursor.get(room_id, room_data, MDB_NEXT)) {
         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);
             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: "
                               "room_id ({}), {}: {}",
                               room_id,
@@ -2509,10 +2511,10 @@ Cache::invite(std::string_view roomid)
 
     if (invitesDb_.get(txn, roomid, room_data)) {
         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);
             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: "
                               "room_id ({}), {}: {}",
                               roomid,
@@ -2536,11 +2538,12 @@ 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())).get<StateEvent<Avatar>>();
+              nlohmann::json::parse(std::string_view(event.data(), event.size()))
+                .get<StateEvent<Avatar>>();
 
             if (!msg.content.url.empty())
                 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());
         }
     }
@@ -2557,7 +2560,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).get<MemberInfo>();
+            MemberInfo m = nlohmann::json::parse(member_data).get<MemberInfo>();
             if (user_id == localUserId_.toStdString()) {
                 fallback_url = m.avatar_url;
                 continue;
@@ -2565,7 +2568,7 @@ Cache::getRoomAvatarUrl(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersd
 
             cursor.close();
             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());
         }
     }
@@ -2588,11 +2591,12 @@ 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())).get<StateEvent<Name>>();
+              nlohmann::json::parse(std::string_view(event.data(), event.size()))
+                .get<StateEvent<Name>>();
 
             if (!msg.content.name.empty())
                 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());
         }
     }
@@ -2602,12 +2606,12 @@ 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()))
+              nlohmann::json::parse(std::string_view(event.data(), event.size()))
                 .get<StateEvent<CanonicalAlias>>();
 
             if (!msg.content.alias.empty())
                 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());
         }
     }
@@ -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) {
         try {
-            members.emplace(user_id, json::parse(member_data).get<MemberInfo>());
-        } catch (const json::exception &e) {
+            members.emplace(user_id, nlohmann::json::parse(member_data).get<MemberInfo>());
+        } catch (const nlohmann::json::exception &e) {
             nhlog::db()->warn("failed to parse member info: {}", e.what());
         }
 
@@ -2664,9 +2668,9 @@ Cache::getRoomJoinRule(lmdb::txn &txn, lmdb::dbi &statesdb)
     if (res) {
         try {
             StateEvent<state::JoinRules> msg =
-              json::parse(event).get<StateEvent<state::JoinRules>>();
+              nlohmann::json::parse(event).get<StateEvent<state::JoinRules>>();
             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());
         }
     }
@@ -2684,9 +2688,10 @@ Cache::getRoomGuestAccess(lmdb::txn &txn, lmdb::dbi &statesdb)
 
     if (res) {
         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;
-        } catch (const json::exception &e) {
+        } catch (const nlohmann::json::exception &e) {
             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) {
         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())
                 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());
         }
     }
@@ -2727,11 +2732,11 @@ Cache::getRoomVersion(lmdb::txn &txn, lmdb::dbi &statesdb)
 
     if (res) {
         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())
                 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());
         }
     }
@@ -2751,10 +2756,10 @@ Cache::getRoomIsSpace(lmdb::txn &txn, lmdb::dbi &statesdb)
 
     if (res) {
         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;
-        } catch (const json::exception &e) {
+        } catch (const nlohmann::json::exception &e) {
             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) {
         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);
-        } catch (const json::exception &e) {
+        } catch (const nlohmann::json::exception &e) {
             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;
 
         try {
-            MemberInfo tmp = json::parse(member_data).get<MemberInfo>();
+            MemberInfo tmp = nlohmann::json::parse(member_data).get<MemberInfo>();
             cursor.close();
 
             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());
         }
     }
@@ -2815,9 +2821,9 @@ Cache::getInviteRoomAvatarUrl(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &me
     if (res) {
         try {
             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);
-        } catch (const json::exception &e) {
+        } catch (const nlohmann::json::exception &e) {
             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;
 
         try {
-            MemberInfo tmp = json::parse(member_data).get<MemberInfo>();
+            MemberInfo tmp = nlohmann::json::parse(member_data).get<MemberInfo>();
             cursor.close();
 
             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());
         }
     }
@@ -2855,9 +2861,9 @@ Cache::getInviteRoomTopic(lmdb::txn &txn, lmdb::dbi &db)
 
     if (res) {
         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);
-        } catch (const json::exception &e) {
+        } catch (const nlohmann::json::exception &e) {
             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) {
         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;
-        } catch (const json::exception &e) {
+        } catch (const nlohmann::json::exception &e) {
             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;
         if (membersdb.get(txn, user_id, info)) {
-            MemberInfo m = json::parse(info).get<MemberInfo>();
+            MemberInfo m = nlohmann::json::parse(info).get<MemberInfo>();
             return m;
         }
     } catch (std::exception &e) {
@@ -2951,10 +2957,10 @@ Cache::getMembers(const std::string &room_id, std::size_t startIndex, std::size_
             break;
 
         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)),
                                             QString::fromStdString(tmp.name)});
-        } catch (const json::exception &e) {
+        } catch (const nlohmann::json::exception &e) {
             nhlog::db()->warn("{}", e.what());
         }
 
@@ -2991,11 +2997,11 @@ Cache::getMembersFromInvite(const std::string &room_id, std::size_t startIndex,
                 break;
 
             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)),
                                                 QString::fromStdString(tmp.name),
                                                 tmp.is_direct});
-            } catch (const json::exception &e) {
+            } catch (const nlohmann::json::exception &e) {
                 nhlog::db()->warn("{}", e.what());
             }
 
@@ -3088,7 +3094,7 @@ Cache::firstPendingMessage(const std::string &room_id)
 
             try {
                 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();
                 txn.commit();
@@ -3178,8 +3184,8 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
 
         std::string_view event_id = event_id_val;
 
-        json orderEntry        = json::object();
-        orderEntry["event_id"] = event_id_val;
+        nlohmann::json orderEntry = nlohmann::json::object();
+        orderEntry["event_id"]    = event_id_val;
         if (first && !res.prev_batch.empty())
             orderEntry["prev_batch"] = res.prev_batch;
 
@@ -3228,7 +3234,7 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
             mtx::events::collections::TimelineEvent te;
             try {
                 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
                 std::visit(
                   [redaction](auto &ev) {
@@ -3245,7 +3251,7 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
             }
 
             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 {
             first = false;
 
@@ -3316,7 +3322,7 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message
 
     if (res.chunk.empty()) {
         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;
             orderDb.put(txn, lmdb::to_sv(index), orderEntry.dump());
             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)) {
             --index;
 
-            json orderEntry        = json::object();
-            orderEntry["event_id"] = event_id_val;
+            nlohmann::json orderEntry = nlohmann::json::object();
+            orderEntry["event_id"]    = event_id_val;
 
             orderDb.put(txn, lmdb::to_sv(index), orderEntry.dump());
             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();
-    orderEntry["event_id"]   = event_id_val;
-    orderEntry["prev_batch"] = res.end;
+    nlohmann::json orderEntry = nlohmann::json::object();
+    orderEntry["event_id"]    = event_id_val;
+    orderEntry["prev_batch"]  = res.end;
     orderDb.put(txn, lmdb::to_sv(index), orderEntry.dump());
 
     txn.commit();
@@ -3395,10 +3401,10 @@ Cache::clearTimeline(const std::string &room_id)
     bool passed_pagination_token = false;
     while (cursor.get(indexVal, val, start ? MDB_LAST : MDB_PREV)) {
         start = false;
-        json obj;
+        nlohmann::json obj;
 
         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 &) {
             // workaround bug in the initial db format, where we sometimes didn't store
             // json...
@@ -3440,9 +3446,9 @@ Cache::clearTimeline(const std::string &room_id)
         while (cursor.get(indexVal, eventId, innerStart ? MDB_LAST : MDB_PREV)) {
             innerStart = false;
 
-            json obj;
+            nlohmann::json obj;
             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 &) {
                 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);
 
     while (cursor.get(event_id, msg, MDB_NEXT)) {
-        auto obj = json::parse(msg);
+        auto obj = nlohmann::json::parse(msg);
 
         if (obj.count("event") == 0)
             continue;
@@ -3508,7 +3514,7 @@ Cache::saveTimelineMentions(const mtx::responses::Notifications &res)
 
     // Sort into room-specific 'buckets'
     for (const auto &notif : res.notifications) {
-        json val = notif;
+        nlohmann::json val = notif;
         notifsByRoom[notif.room_id].push_back(notif);
     }
 
@@ -3544,7 +3550,7 @@ Cache::saveTimelineMentions(lmdb::txn &txn,
             return;
         }
 
-        json obj = notif;
+        nlohmann::json obj = notif;
 
         db.put(txn, event_id, obj.dump());
     }
@@ -3632,7 +3638,7 @@ Cache::deleteOldMessages()
         while (cursor.get(indexVal, val, start ? MDB_FIRST : MDB_NEXT) &&
                message_count-- > MAX_RESTORED_MESSAGES) {
             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) {
                 std::string event_id = obj["event_id"].get<std::string>();
@@ -3753,7 +3759,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)).get<RoomInfo>();
+                    RoomInfo tmp = nlohmann::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);
@@ -3903,8 +3909,8 @@ Cache::getAccountData(lmdb::txn &txn, mtx::events::EventType type, const std::st
         std::string_view data;
         if (db.get(txn, to_string(type), data)) {
             mtx::responses::utils::RoomAccountDataEvents events;
-            json j = json::array({
-              json::parse(data),
+            nlohmann::json j = nlohmann::json::array({
+              nlohmann::json::parse(data),
             });
             mtx::responses::utils::parse_room_account_data_events(j, events);
             if (events.size() == 1)
@@ -3934,14 +3940,15 @@ Cache::hasEnoughPowerLevel(const std::vector<mtx::events::EventType> &eventTypes
 
     if (res) {
         try {
-            StateEvent<PowerLevels> msg = json::parse(std::string_view(event.data(), event.size()))
-                                            .get<StateEvent<PowerLevels>>();
+            StateEvent<PowerLevels> msg =
+              nlohmann::json::parse(std::string_view(event.data(), event.size()))
+                .get<StateEvent<PowerLevels>>();
 
             user_level = msg.content.user_level(user_id);
 
             for (const auto &ty : eventTypes)
                 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());
         }
     }
@@ -4031,7 +4038,7 @@ Cache::getMembersWithKeys(const std::string &room_id, bool verified_only)
             auto res = keysDb.get(txn, user_id, keys);
 
             if (res) {
-                auto k = json::parse(keys).get<UserKeyCache>();
+                auto k = nlohmann::json::parse(keys).get<UserKeyCache>();
                 if (verified_only) {
                     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);
 
     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>();
     }
 
@@ -4138,7 +4145,7 @@ Cache::presence(const std::string &user_id)
 }
 
 void
-to_json(json &j, const UserKeyCache &info)
+to_json(nlohmann::json &j, const UserKeyCache &info)
 {
     j["device_keys"]        = info.device_keys;
     j["seen_device_keys"]   = info.seen_device_keys;
@@ -4152,7 +4159,7 @@ to_json(json &j, const UserKeyCache &info)
 }
 
 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.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);
 
         if (res) {
-            return json::parse(keys).get<UserKeyCache>();
+            return nlohmann::json::parse(keys).get<UserKeyCache>();
         } else {
             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);
 
         if (res) {
-            updateToWrite     = json::parse(oldKeys).get<UserKeyCache>();
+            updateToWrite     = nlohmann::json::parse(oldKeys).get<UserKeyCache>();
             auto last_changed = updateToWrite.last_changed;
             // skip if we are tracking this and expect it to be up to date with the last
             // sync token
@@ -4289,7 +4296,7 @@ Cache::updateUserKeys(const std::string &sync_token, const mtx::responses::Query
 
                         if (!mtx::crypto::ed25519_verify_signature(
                               device_keys.keys.at(device_signing_key),
-                              json(device_keys),
+                              nlohmann::json(device_keys),
                               device_keys.signatures.at(user).at(device_signing_key))) {
                             nhlog::crypto()->warn(
                               "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;
-        db.put(txn, user, json(updateToWrite).dump());
+        db.put(txn, user, nlohmann::json(updateToWrite).dump());
     }
 
     txn.commit();
@@ -4368,12 +4375,12 @@ Cache::markUserKeysOutOfDate(lmdb::txn &txn,
         UserKeyCache cacheEntry;
         auto res = db.get(txn, user, oldKeys);
         if (res) {
-            cacheEntry =
-              json::parse(std::string_view(oldKeys.data(), oldKeys.size())).get<UserKeyCache>();
+            cacheEntry = nlohmann::json::parse(std::string_view(oldKeys.data(), oldKeys.size()))
+                           .get<UserKeyCache>();
         }
         cacheEntry.last_changed = sync_token;
 
-        db.put(txn, user, json(cacheEntry).dump());
+        db.put(txn, user, nlohmann::json(cacheEntry).dump());
 
         query.device_keys[user] = {};
     }
@@ -4456,28 +4463,28 @@ Cache::query_keys(const std::string &user_id,
 }
 
 void
-to_json(json &j, const VerificationCache &info)
+to_json(nlohmann::json &j, const VerificationCache &info)
 {
     j["device_verified"] = info.device_verified;
     j["device_blocked"]  = info.device_blocked;
 }
 
 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_blocked  = j.at("device_blocked").get<std::set<std::string>>();
 }
 
 void
-to_json(json &j, const OnlineBackupVersion &info)
+to_json(nlohmann::json &j, const OnlineBackupVersion &info)
 {
     j["v"] = info.version;
     j["a"] = info.algorithm;
 }
 
 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.algorithm = j.at("a").get<std::string>();
@@ -4494,7 +4501,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).get<VerificationCache>();
+            verified_state = nlohmann::json::parse(verifiedVal).get<VerificationCache>();
             return verified_state;
         } else {
             return {};
@@ -4517,7 +4524,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).get<VerificationCache>();
+                verified_state = nlohmann::json::parse(val).get<VerificationCache>();
             }
 
             for (const auto &device : verified_state.device_verified)
@@ -4525,7 +4532,7 @@ Cache::markDeviceVerified(const std::string &user_id, const std::string &key)
                     return;
 
             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();
         } catch (std::exception &) {
         }
@@ -4564,12 +4571,12 @@ 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).get<VerificationCache>();
+            verified_state = nlohmann::json::parse(val).get<VerificationCache>();
         }
 
         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();
     } catch (std::exception &) {
     }
@@ -4636,7 +4643,8 @@ Cache::verificationStatus_(const std::string &user_id, lmdb::txn &txn)
             if (!keys.count(key_id))
                 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 false;
@@ -4679,7 +4687,7 @@ Cache::verificationStatus_(const std::string &user_id, lmdb::txn &txn)
             std::string dev_id = "ed25519:" + http::client()->device_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,
-                                                       json(mk),
+                                                       nlohmann::json(mk),
                                                        mk.signatures.at(local_user).at(dev_id))) {
                 nhlog::crypto()->debug("We have not verified our own master key");
                 verification_storage.status[user_id] = status;
@@ -4735,7 +4743,7 @@ Cache::verificationStatus_(const std::string &user_id, lmdb::txn &txn)
 }
 
 void
-to_json(json &j, const RoomInfo &info)
+to_json(nlohmann::json &j, const RoomInfo &info)
 {
     j["name"]         = info.name;
     j["topic"]        = info.topic;
@@ -4759,7 +4767,7 @@ to_json(json &j, const RoomInfo &info)
 }
 
 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.topic      = j.at("topic").get<std::string>();
@@ -4784,20 +4792,20 @@ from_json(const json &j, RoomInfo &info)
 }
 
 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
-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.room_id  = j.at("room_id").get<std::string>();
 }
 
 void
-to_json(json &j, const MemberInfo &info)
+to_json(nlohmann::json &j, const MemberInfo &info)
 {
     j["name"]       = info.name;
     j["avatar_url"] = info.avatar_url;
@@ -4806,7 +4814,7 @@ to_json(json &j, const MemberInfo &info)
 }
 
 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.avatar_url = j.at("avatar_url").get<std::string>();
diff --git a/src/Cache_p.h b/src/Cache_p.h
index 7addb1e4..988dc04f 100644
--- a/src/Cache_p.h
+++ b/src/Cache_p.h
@@ -401,7 +401,7 @@ private:
                 // Lightweight representation of a member.
                 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;
             }
             default: {
@@ -419,7 +419,7 @@ private:
         std::visit(
           [&txn, &statesdb, &stateskeydb, &eventsDb, &membersdb](const auto &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 (std::is_same_v<std::remove_cv_t<std::remove_reference_t<decltype(e)>>,
@@ -431,20 +431,20 @@ private:
                           else
                               stateskeydb.del(txn,
                                               to_string(e.type),
-                                              json::object({
-                                                             {"key", e.state_key},
-                                                             {"id", e.event_id},
-                                                           })
+                                              nlohmann::json::object({
+                                                                       {"key", e.state_key},
+                                                                       {"id", e.event_id},
+                                                                     })
                                                 .dump());
                       } 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
                           stateskeydb.put(txn,
                                           to_string(e.type),
-                                          json::object({
-                                                         {"key", e.state_key},
-                                                         {"id", e.event_id},
-                                                       })
+                                          nlohmann::json::object({
+                                                                   {"key", e.state_key},
+                                                                   {"id", e.event_id},
+                                                                 })
                                             .dump());
                   }
               }
@@ -473,7 +473,7 @@ private:
                 }
             } else {
                 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 typeStrV = typeStr;
 
@@ -483,14 +483,15 @@ private:
 
                 try {
                     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;
                 } catch (std::exception &e) {
                     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) {
             return std::nullopt;
         }
@@ -523,8 +524,10 @@ private:
                     first = false;
 
                     try {
-                        if (eventsDb.get(txn, json::parse(data)["id"].get<std::string>(), value))
-                            events.push_back(json::parse(value).get<mtx::events::StateEvent<T>>());
+                        if (eventsDb.get(
+                              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) {
                         nhlog::db()->warn("Failed to parse state event: {}", e.what());
                     }
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp
index 38d2c8e9..967f349d 100644
--- a/src/ChatPage.cpp
+++ b/src/ChatPage.cpp
@@ -426,7 +426,7 @@ ChatPage::loadStateFromCache()
         nhlog::db()->critical("failed to restore cache: {}", e.what());
         emit dropToLoginPageCb(tr("Failed to restore save data. Please login again."));
         return;
-    } catch (const json::exception &e) {
+    } catch (const nlohmann::json::exception &e) {
         nhlog::db()->critical("failed to parse cache data: {}", e.what());
         emit dropToLoginPageCb(tr("Failed to restore save data. Please login again."));
         return;
@@ -1238,7 +1238,7 @@ ChatPage::decryptDownloadedSecrets(mtx::secret_storage::AesHmacSha2KeyDescriptio
                       olm::client()->identity_keys().ed25519 &&
                     myKey.keys["curve25519:" + http::client()->device_id()] ==
                       olm::client()->identity_keys().curve25519) {
-                    json j = myKey;
+                    nlohmann::json j = myKey;
                     j.erase("signatures");
                     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() &&
                     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("unsigned");
                     mtx::crypto::CrossSigningKeys master_key =
@@ -1270,7 +1270,7 @@ ChatPage::decryptDownloadedSecrets(mtx::secret_storage::AesHmacSha2KeyDescriptio
     }
 
     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(
           req, [](const mtx::responses::KeySignaturesUpload &res, mtx::http::RequestErr err) {
               if (err) {
diff --git a/src/encryption/DeviceVerificationFlow.cpp b/src/encryption/DeviceVerificationFlow.cpp
index 098347cd..fa06fba2 100644
--- a/src/encryption/DeviceVerificationFlow.cpp
+++ b/src/encryption/DeviceVerificationFlow.cpp
@@ -267,7 +267,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *,
                   // verified it
                   for (const auto &mac : msg.mac) {
                       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("unsigned");
                           mtx::crypto::CrossSigningKeys master_key =
@@ -283,7 +283,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *,
                           auto device_id = this->deviceId.toStdString();
 
                           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("unsigned");
 
@@ -305,7 +305,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *,
                   // Sign their master key with user signing key
                   for (const auto &mac : msg.mac) {
                       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("unsigned");
 
diff --git a/src/encryption/Olm.cpp b/src/encryption/Olm.cpp
index 5387d215..8bf2222f 100644
--- a/src/encryption/Olm.cpp
+++ b/src/encryption/Olm.cpp
@@ -116,7 +116,7 @@ handle_to_device_messages(const std::vector<mtx::events::collections::DeviceEven
     nlohmann::json j_msg;
 
     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) {
             nhlog::crypto()->warn("received message with no type field: {}", j_msg.dump(2));
             continue;
@@ -295,8 +295,8 @@ handle_olm_message(const OlmMessage &msg, const UserKeyCache &otherUserDeviceKey
             }
 
             {
-                std::string msg_type = payload["type"].get<std::string>();
-                json event_array     = json::array();
+                std::string msg_type       = payload["type"].get<std::string>();
+                nlohmann::json event_array = nlohmann::json::array();
                 event_array.push_back(payload);
 
                 std::vector<mtx::events::collections::DeviceEvents> temp_events;
@@ -456,7 +456,7 @@ handle_pre_key_olm_message(const std::string &sender,
         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));
 
     try {
@@ -716,8 +716,8 @@ try_olm_decryption(const std::string &sender_key, const mtx::events::msg::OlmCip
         }
 
         try {
-            return json::parse(std::string_view((char *)text.data(), text.size()));
-        } catch (const json::exception &e) {
+            return nlohmann::json::parse(std::string_view((char *)text.data(), text.size()));
+        } catch (const nlohmann::json::exception &e) {
             nhlog::crypto()->critical("failed to parse the decrypted session msg: {} {}",
                                       e.what(),
                                       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.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;
     body[mtx::identifiers::parse<mtx::identifiers::User>(e.sender)]["*"] = request;
@@ -1171,7 +1171,7 @@ decryptEvent(const MegolmSessionIndex &index,
 
     try {
         // 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["sender"]           = event.sender;
         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;
 
-    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;
     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(
                                 dev.second, device_id, user_id)) {
                               nhlog::crypto()->warn("failed to verify identity keys: {}",
-                                                    json(dev.second).dump(2));
+                                                    nlohmann::json(dev.second).dump(2));
                               continue;
                           }
-                      } catch (const json::exception &e) {
+                      } catch (const nlohmann::json::exception &e) {
                           nhlog::crypto()->warn("failed to parse device key json: {}", e.what());
                           continue;
                       } catch (const mtx::crypto::olm_exception &e) {
diff --git a/src/encryption/SelfVerificationStatus.cpp b/src/encryption/SelfVerificationStatus.cpp
index ab50b6f3..f37b2af4 100644
--- a/src/encryption/SelfVerificationStatus.cpp
+++ b/src/encryption/SelfVerificationStatus.cpp
@@ -152,7 +152,7 @@ SelfVerificationStatus::setupCrosssigning(bool useSSSS, QString password, bool u
                     olm::client()->identity_keys().ed25519 &&
                   myKey.keys["curve25519:" + http::client()->device_id()] ==
                     olm::client()->identity_keys().curve25519) {
-                  json j = myKey;
+                  nlohmann::json j = myKey;
                   j.erase("signatures");
                   j.erase("unsigned");
 
diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp
index b0ea07ec..122a6f8e 100644
--- a/src/timeline/EventStore.cpp
+++ b/src/timeline/EventStore.cpp
@@ -241,9 +241,9 @@ EventStore::EventStore(std::string room_id, QObject *)
 
                       std::visit(
                         [&pending_event, &original_encrypted, &session, this](auto &msg) {
-                            json doc = {{"type", mtx::events::to_string(msg.type)},
-                                        {"content", json(msg.content)},
-                                        {"room_id", room_id_}};
+                            nlohmann::json doc = {{"type", mtx::events::to_string(msg.type)},
+                                                  {"content", nlohmann::json(msg.content)},
+                                                  {"room_id", room_id_}};
 
                             auto data = olm::encrypt_group_message_with_session(
                               session.session, http::client()->device_id(), doc);
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 8e9a21db..53d2fe01 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -1346,9 +1346,9 @@ TimelineModel::sendEncryptedMessage(mtx::events::RoomEvent<T> msg, mtx::events::
     using namespace mtx::events;
     using namespace mtx::identifiers;
 
-    json doc = {{"type", mtx::events::to_string(eventType)},
-                {"content", json(msg.content)},
-                {"room_id", room_id}};
+    nlohmann::json doc = {{"type", mtx::events::to_string(eventType)},
+                          {"content", nlohmann::json(msg.content)},
+                          {"room_id", room_id}};
 
     try {
         mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> event;