From e7d4aec6ecf65ad970c341e30949218e4472944a Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 21 Nov 2021 07:06:37 +0100 Subject: [PATCH] Only mark as direct, if invite was direct --- src/Cache.cpp | 8 ++++++-- src/CacheStructs.h | 2 ++ src/timeline/RoomlistModel.cpp | 15 ++++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Cache.cpp b/src/Cache.cpp index c22cd0d6..4f96f430 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -1640,7 +1640,7 @@ Cache::saveInvite(lmdb::txn &txn, auto display_name = msg->content.display_name.empty() ? msg->state_key : msg->content.display_name; - MemberInfo tmp{display_name, msg->content.avatar_url}; + MemberInfo tmp{display_name, msg->content.avatar_url, msg->content.is_direct}; membersdb.put(txn, msg->state_key, json(tmp).dump()); } else { @@ -2777,7 +2777,8 @@ Cache::getMembersFromInvite(const std::string &room_id, std::size_t startIndex, try { MemberInfo tmp = json::parse(user_data); members.emplace_back(RoomMember{QString::fromStdString(std::string(user_id)), - QString::fromStdString(tmp.name)}); + QString::fromStdString(tmp.name), + tmp.is_direct}); } catch (const json::exception &e) { nhlog::db()->warn("{}", e.what()); } @@ -4563,6 +4564,8 @@ to_json(json &j, const MemberInfo &info) { j["name"] = info.name; j["avatar_url"] = info.avatar_url; + if (info.is_direct) + j["is_direct"] = info.is_direct; } void @@ -4570,6 +4573,7 @@ from_json(const json &j, MemberInfo &info) { info.name = j.at("name"); info.avatar_url = j.at("avatar_url"); + info.is_direct = j.value("is_direct", false); } void diff --git a/src/CacheStructs.h b/src/CacheStructs.h index e28f5b2d..01a050da 100644 --- a/src/CacheStructs.h +++ b/src/CacheStructs.h @@ -26,6 +26,7 @@ struct RoomMember { QString user_id; QString display_name; + bool is_direct = false; }; //! Used to uniquely identify a list of read receipts. @@ -98,6 +99,7 @@ struct MemberInfo { std::string name; std::string avatar_url; + bool is_direct = false; }; void diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp index 7d727659..79324628 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp @@ -586,8 +586,9 @@ RoomlistModel::initializeRooms() } invites = cache::client()->invites(); - for (const auto &id : invites.keys()) + for (const auto &id : invites.keys()) { roomids.push_back(id); + } for (const auto &id : cache::client()->roomIds()) addRoom(id, true); @@ -626,9 +627,17 @@ RoomlistModel::acceptInvite(QString roomid) { if (invites.contains(roomid)) { // Don't remove invite yet, so that we can switch to it + auto members = cache::getMembersFromInvite(roomid.toStdString(), 0, -1); + auto local = utils::localUser(); + for (const auto &m : members) { + if (m.user_id == local && m.is_direct) { + nhlog::db()->info("marking {} as direct", roomid.toStdString()); + utils::markRoomAsDirect(roomid, members); + break; + } + } + ChatPage::instance()->joinRoom(roomid); - utils::markRoomAsDirect(roomid, - cache::client()->getMembersFromInvite(roomid.toStdString(), 0, -1)); } } void