diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2020-05-04 20:17:57 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2020-05-05 19:08:59 +0200 |
commit | 692c6119b44ef0f034d45ec3c445eaf616db672a (patch) | |
tree | a9d31da2eec177486d3bd3a8ec4452452d238f8d /src/Cache.cpp | |
parent | Fix jumpy room list, when sort order is ambiguous (diff) | |
download | nheko-692c6119b44ef0f034d45ec3c445eaf616db672a.tar.xz |
Fix joined rooms dropping to the bottom at first
Diffstat (limited to 'src/Cache.cpp')
-rw-r--r-- | src/Cache.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp index aca01c1a..016ba371 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -1314,16 +1314,33 @@ Cache::getLastMessageInfo(lmdb::txn &txn, const std::string &room_id) std::string timestamp, msg; - QSettings settings; const auto local_user = utils::localUser(); + DescInfo fallbackDesc{}; + auto cursor = lmdb::cursor::open(txn, db); while (cursor.get(timestamp, msg, MDB_NEXT)) { auto obj = json::parse(msg); - if (obj.count("event") == 0 || !(obj["event"]["type"] == "m.room.message" || - obj["event"]["type"] == "m.sticker" || - obj["event"]["type"] == "m.room.encrypted")) + if (obj.count("event") == 0) + continue; + + if (fallbackDesc.event_id.isEmpty() && obj["event"]["type"] == "m.room.member" && + obj["event"]["state_key"] == local_user.toStdString() && + obj["event"]["content"]["membership"] == "join") { + uint64_t ts = obj["event"]["origin_server_ts"]; + auto time = QDateTime::fromMSecsSinceEpoch(ts); + fallbackDesc = DescInfo{QString::fromStdString(obj["event"]["event_id"]), + local_user, + tr("You joined this room"), + utils::descriptiveTime(time), + ts, + time}; + } + + if (!(obj["event"]["type"] == "m.room.message" || + obj["event"]["type"] == "m.sticker" || + obj["event"]["type"] == "m.room.encrypted")) continue; mtx::events::collections::TimelineEvent event; @@ -1335,7 +1352,7 @@ Cache::getLastMessageInfo(lmdb::txn &txn, const std::string &room_id) } cursor.close(); - return DescInfo{}; + return fallbackDesc; } std::map<QString, bool> |