From 692c6119b44ef0f034d45ec3c445eaf616db672a Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 4 May 2020 20:17:57 +0200 Subject: Fix joined rooms dropping to the bottom at first --- src/timeline/TimelineModel.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/timeline/TimelineModel.cpp') diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 340bae39..1c0abd17 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -518,6 +518,20 @@ isMessage(const mtx::events::EncryptedEvent &) return true; } +// Workaround. We also want to see a room at the top, if we just joined it +auto +isYourJoin(const mtx::events::StateEvent &e) +{ + return e.content.membership == mtx::events::state::Membership::Join && + e.state_key == http::client()->user_id().to_string(); +} +template +auto +isYourJoin(const mtx::events::Event &) +{ + return false; +} + void TimelineModel::updateLastMessage() { @@ -530,6 +544,19 @@ TimelineModel::updateLastMessage() } } + if (std::visit([](const auto &e) -> bool { return isYourJoin(e); }, event)) { + auto time = mtx::accessors::origin_server_ts(event); + uint64_t ts = time.toMSecsSinceEpoch(); + emit manager_->updateRoomsLastMessage( + room_id_, + DescInfo{QString::fromStdString(mtx::accessors::event_id(event)), + QString::fromStdString(http::client()->user_id().to_string()), + tr("You joined this room"), + utils::descriptiveTime(time), + ts, + time}); + return; + } if (!std::visit([](const auto &e) -> bool { return isMessage(e); }, event)) continue; -- cgit 1.5.1