Only mark as direct, if invite was direct

This commit is contained in:
Nicolas Werner 2021-11-21 07:06:37 +01:00
parent 3d92e8ae60
commit e7d4aec6ec
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
3 changed files with 20 additions and 5 deletions

View file

@ -1640,7 +1640,7 @@ Cache::saveInvite(lmdb::txn &txn,
auto display_name = auto display_name =
msg->content.display_name.empty() ? msg->state_key : msg->content.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()); membersdb.put(txn, msg->state_key, json(tmp).dump());
} else { } else {
@ -2777,7 +2777,8 @@ Cache::getMembersFromInvite(const std::string &room_id, std::size_t startIndex,
try { try {
MemberInfo tmp = json::parse(user_data); MemberInfo tmp = json::parse(user_data);
members.emplace_back(RoomMember{QString::fromStdString(std::string(user_id)), members.emplace_back(RoomMember{QString::fromStdString(std::string(user_id)),
QString::fromStdString(tmp.name)}); QString::fromStdString(tmp.name),
tmp.is_direct});
} catch (const json::exception &e) { } catch (const json::exception &e) {
nhlog::db()->warn("{}", e.what()); nhlog::db()->warn("{}", e.what());
} }
@ -4563,6 +4564,8 @@ to_json(json &j, const MemberInfo &info)
{ {
j["name"] = info.name; j["name"] = info.name;
j["avatar_url"] = info.avatar_url; j["avatar_url"] = info.avatar_url;
if (info.is_direct)
j["is_direct"] = info.is_direct;
} }
void void
@ -4570,6 +4573,7 @@ from_json(const json &j, MemberInfo &info)
{ {
info.name = j.at("name"); info.name = j.at("name");
info.avatar_url = j.at("avatar_url"); info.avatar_url = j.at("avatar_url");
info.is_direct = j.value("is_direct", false);
} }
void void

View file

@ -26,6 +26,7 @@ struct RoomMember
{ {
QString user_id; QString user_id;
QString display_name; QString display_name;
bool is_direct = false;
}; };
//! Used to uniquely identify a list of read receipts. //! Used to uniquely identify a list of read receipts.
@ -98,6 +99,7 @@ struct MemberInfo
{ {
std::string name; std::string name;
std::string avatar_url; std::string avatar_url;
bool is_direct = false;
}; };
void void

View file

@ -586,8 +586,9 @@ RoomlistModel::initializeRooms()
} }
invites = cache::client()->invites(); invites = cache::client()->invites();
for (const auto &id : invites.keys()) for (const auto &id : invites.keys()) {
roomids.push_back(id); roomids.push_back(id);
}
for (const auto &id : cache::client()->roomIds()) for (const auto &id : cache::client()->roomIds())
addRoom(id, true); addRoom(id, true);
@ -626,9 +627,17 @@ RoomlistModel::acceptInvite(QString roomid)
{ {
if (invites.contains(roomid)) { if (invites.contains(roomid)) {
// Don't remove invite yet, so that we can switch to it // 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); ChatPage::instance()->joinRoom(roomid);
utils::markRoomAsDirect(roomid,
cache::client()->getMembersFromInvite(roomid.toStdString(), 0, -1));
} }
} }
void void