From 3b8a1f85e6ca3e3c53a0aa76d4190ab987a63cbe Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 9 Mar 2023 21:51:22 +0100 Subject: [PATCH] Fix avatar change being rendered as a join --- src/timeline/TimelineModel.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 6d8de8f5..25ee71cb 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -1122,14 +1122,25 @@ isMessage(const mtx::events::RoomEvent &) // Workaround. We also want to see a room at the top, if we just joined it auto -isYourJoin(const mtx::events::StateEvent &e) +isYourJoin(const mtx::events::StateEvent &e, EventStore &events) { - return e.content.membership == mtx::events::state::Membership::Join && - e.state_key == http::client()->user_id().to_string(); + if (e.content.membership == mtx::events::state::Membership::Join && + e.state_key == http::client()->user_id().to_string() && + !e.unsigned_data.replaces_state.empty()) { + auto tempPrevEvent = events.get(e.unsigned_data.replaces_state, e.event_id); + if (tempPrevEvent) { + if (auto prevEvent = + std::get_if>(tempPrevEvent)) { + if (prevEvent->content.membership != mtx::events::state::Membership::Join) + return true; + } + } + } + return false; } template auto -isYourJoin(const mtx::events::Event &) +isYourJoin(const mtx::events::Event &, EventStore &) { return false; } @@ -1153,7 +1164,7 @@ TimelineModel::updateLastMessage() if (!event) continue; - if (std::visit([](const auto &e) -> bool { return isYourJoin(e); }, *event)) { + if (std::visit([this](const auto &e) -> bool { return isYourJoin(e, events); }, *event)) { auto time = mtx::accessors::origin_server_ts(*event); uint64_t ts = time.toMSecsSinceEpoch(); auto description =