mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 04:28:49 +03:00
Store notification counts across restarts
This commit is contained in:
parent
5306a4ecac
commit
0a405a7446
3 changed files with 24 additions and 10 deletions
|
@ -1543,18 +1543,12 @@ Cache::updateState(const std::string &room, const mtx::responses::StateEvents &s
|
||||||
saveStateEvents(txn, statesdb, stateskeydb, membersdb, eventsDb, room, state.events);
|
saveStateEvents(txn, statesdb, stateskeydb, membersdb, eventsDb, room, state.events);
|
||||||
|
|
||||||
RoomInfo updatedInfo;
|
RoomInfo updatedInfo;
|
||||||
updatedInfo.name = getRoomName(txn, statesdb, membersdb).toStdString();
|
|
||||||
updatedInfo.topic = getRoomTopic(txn, statesdb).toStdString();
|
|
||||||
updatedInfo.avatar_url = getRoomAvatarUrl(txn, statesdb, membersdb).toStdString();
|
|
||||||
updatedInfo.version = getRoomVersion(txn, statesdb).toStdString();
|
|
||||||
updatedInfo.is_space = getRoomIsSpace(txn, statesdb);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
std::string_view data;
|
std::string_view data;
|
||||||
if (roomsDb_.get(txn, room, data)) {
|
if (roomsDb_.get(txn, room, data)) {
|
||||||
try {
|
try {
|
||||||
RoomInfo tmp = json::parse(std::string_view(data.data(), data.size()));
|
RoomInfo updatedInfo = json::parse(std::string_view(data.data(), data.size()));
|
||||||
updatedInfo.tags = tmp.tags;
|
|
||||||
} catch (const json::exception &e) {
|
} catch (const json::exception &e) {
|
||||||
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
|
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
|
||||||
room,
|
room,
|
||||||
|
@ -1564,6 +1558,12 @@ Cache::updateState(const std::string &room, const mtx::responses::StateEvents &s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updatedInfo.name = getRoomName(txn, statesdb, membersdb).toStdString();
|
||||||
|
updatedInfo.topic = getRoomTopic(txn, statesdb).toStdString();
|
||||||
|
updatedInfo.avatar_url = getRoomAvatarUrl(txn, statesdb, membersdb).toStdString();
|
||||||
|
updatedInfo.version = getRoomVersion(txn, statesdb).toStdString();
|
||||||
|
updatedInfo.is_space = getRoomIsSpace(txn, statesdb);
|
||||||
|
|
||||||
roomsDb_.put(txn, room, json(updatedInfo).dump());
|
roomsDb_.put(txn, room, json(updatedInfo).dump());
|
||||||
updateSpaces(txn, {room}, {room});
|
updateSpaces(txn, {room}, {room});
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
@ -1628,6 +1628,9 @@ Cache::saveState(const mtx::responses::Sync &res)
|
||||||
updatedInfo.version = getRoomVersion(txn, statesdb).toStdString();
|
updatedInfo.version = getRoomVersion(txn, statesdb).toStdString();
|
||||||
updatedInfo.is_space = getRoomIsSpace(txn, statesdb);
|
updatedInfo.is_space = getRoomIsSpace(txn, statesdb);
|
||||||
|
|
||||||
|
updatedInfo.notification_count = room.second.unread_notifications.notification_count;
|
||||||
|
updatedInfo.highlight_count = room.second.unread_notifications.highlight_count;
|
||||||
|
|
||||||
if (updatedInfo.is_space) {
|
if (updatedInfo.is_space) {
|
||||||
bool space_updates = false;
|
bool space_updates = false;
|
||||||
for (const auto &e : room.second.state.events)
|
for (const auto &e : room.second.state.events)
|
||||||
|
@ -4693,6 +4696,9 @@ to_json(json &j, const RoomInfo &info)
|
||||||
j["join_rule"] = info.join_rule;
|
j["join_rule"] = info.join_rule;
|
||||||
j["guest_access"] = info.guest_access;
|
j["guest_access"] = info.guest_access;
|
||||||
|
|
||||||
|
j["notification_count"] = info.notification_count;
|
||||||
|
j["highlight_count"] = info.highlight_count;
|
||||||
|
|
||||||
if (info.member_count != 0)
|
if (info.member_count != 0)
|
||||||
j["member_count"] = info.member_count;
|
j["member_count"] = info.member_count;
|
||||||
|
|
||||||
|
@ -4713,6 +4719,9 @@ from_json(const json &j, RoomInfo &info)
|
||||||
info.join_rule = j.at("join_rule");
|
info.join_rule = j.at("join_rule");
|
||||||
info.guest_access = j.at("guest_access");
|
info.guest_access = j.at("guest_access");
|
||||||
|
|
||||||
|
info.notification_count = j.value("notification_count", 0);
|
||||||
|
info.highlight_count = j.value("highlight_count", 0);
|
||||||
|
|
||||||
if (j.count("member_count"))
|
if (j.count("member_count"))
|
||||||
info.member_count = j.at("member_count");
|
info.member_count = j.at("member_count");
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,9 @@ struct RoomInfo
|
||||||
bool guest_access = false;
|
bool guest_access = false;
|
||||||
//! The list of tags associated with this room
|
//! The list of tags associated with this room
|
||||||
std::vector<std::string> tags;
|
std::vector<std::string> tags;
|
||||||
|
|
||||||
|
uint16_t highlight_count = 0;
|
||||||
|
uint16_t notification_count = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -349,11 +349,13 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
|
||||||
{
|
{
|
||||||
lastMessage_.timestamp = 0;
|
lastMessage_.timestamp = 0;
|
||||||
|
|
||||||
if (auto create =
|
|
||||||
cache::client()->getStateEvent<mtx::events::state::Create>(room_id_.toStdString()))
|
|
||||||
this->isSpace_ = create->content.type == mtx::events::state::room_type::space;
|
|
||||||
this->isEncrypted_ = cache::isRoomEncrypted(room_id_.toStdString());
|
this->isEncrypted_ = cache::isRoomEncrypted(room_id_.toStdString());
|
||||||
|
|
||||||
|
auto roomInfo = cache::singleRoomInfo(room_id_.toStdString());
|
||||||
|
this->isSpace_ = roomInfo.is_space;
|
||||||
|
this->notification_count = roomInfo.notification_count;
|
||||||
|
this->highlight_count = roomInfo.highlight_count;
|
||||||
|
|
||||||
// this connection will simplify adding the plainRoomNameChanged() signal everywhere that it
|
// this connection will simplify adding the plainRoomNameChanged() signal everywhere that it
|
||||||
// needs to be
|
// needs to be
|
||||||
connect(this, &TimelineModel::roomNameChanged, this, &TimelineModel::plainRoomNameChanged);
|
connect(this, &TimelineModel::roomNameChanged, this, &TimelineModel::plainRoomNameChanged);
|
||||||
|
|
Loading…
Reference in a new issue