Speed up processing UI changes with large syncs

This commit is contained in:
Nicolas Werner 2023-03-12 03:46:29 +01:00
parent 4bf6e58511
commit 703a07fb7d
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9

View file

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