mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Speed up processing UI changes with large syncs
This commit is contained in:
parent
4bf6e58511
commit
703a07fb7d
1 changed files with 44 additions and 14 deletions
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue