diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 25ee71cb..e17c1c59 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -953,11 +953,15 @@ TimelineModel::syncState(const mtx::responses::State &s) { using namespace mtx::events; + bool avatarChanged = false; + bool nameChanged = false; + bool memberCountChanged = false; + for (const auto &e : s.events) { if (std::holds_alternative>(e)) - emit roomAvatarUrlChanged(); + avatarChanged = true; else if (std::holds_alternative>(e)) - emit roomNameChanged(); + nameChanged = true; else if (std::holds_alternative>(e)) emit roomTopicChanged(); else if (std::holds_alternative>(e)) @@ -968,14 +972,10 @@ TimelineModel::syncState(const mtx::responses::State &s) permissions_.invalidate(); emit permissionsChanged(); } else if (std::holds_alternative>(e)) { - emit roomAvatarUrlChanged(); - emit roomNameChanged(); - emit roomMemberCountChanged(); + avatarChanged = true; + nameChanged = true; + memberCountChanged = true; - if (roomMemberCount() <= 2) { - emit isDirectChanged(); - emit directChatOtherUserIdChanged(); - } } else if (std::holds_alternative>(e)) { this->isEncrypted_ = cache::isRoomEncrypted(room_id_.toStdString()); emit encryptionChanged(); @@ -984,6 +984,19 @@ TimelineModel::syncState(const mtx::responses::State &s) emit parentSpaceChanged(); } } + + if (avatarChanged) + emit roomAvatarUrlChanged(); + if (nameChanged) + emit roomNameChanged(); + + if (memberCountChanged) { + emit roomMemberCountChanged(); + if (roomMemberCount() <= 2) { + emit isDirectChanged(); + emit directChatOtherUserIdChanged(); + } + } } void @@ -999,6 +1012,10 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline) using namespace mtx::events; + bool avatarChanged = false; + bool nameChanged = false; + bool memberCountChanged = false; + for (auto e : timeline.events) { if (auto encryptedEvent = std::get_if>(&e)) { MegolmSessionIndex index(room_id_.toStdString(), encryptedEvent->content); @@ -1033,9 +1050,9 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline) }, e); else if (std::holds_alternative>(e)) - emit roomAvatarUrlChanged(); + avatarChanged = true; else if (std::holds_alternative>(e)) - emit roomNameChanged(); + nameChanged = true; else if (std::holds_alternative>(e)) emit roomTopicChanged(); else if (std::holds_alternative>(e)) @@ -1046,9 +1063,9 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline) permissions_.invalidate(); emit permissionsChanged(); } else if (std::holds_alternative>(e)) { - emit roomAvatarUrlChanged(); - emit roomNameChanged(); - emit roomMemberCountChanged(); + avatarChanged = true; + nameChanged = true; + memberCountChanged = true; } else if (std::holds_alternative>(e)) { this->isEncrypted_ = cache::isRoomEncrypted(room_id_.toStdString()); emit encryptionChanged(); @@ -1067,6 +1084,19 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline) if (needsSpecialEffects_) emit confetti(); + if (avatarChanged) + emit roomAvatarUrlChanged(); + if (nameChanged) + emit roomNameChanged(); + + if (memberCountChanged) { + emit roomMemberCountChanged(); + if (roomMemberCount() <= 2) { + emit isDirectChanged(); + emit directChatOtherUserIdChanged(); + } + } + updateLastMessage(); }