Don't skip updateGroupCallParticipants while in getDifference.

This commit is contained in:
John Preston 2021-03-18 00:25:53 +04:00
parent 67623072d6
commit 8c53a3c19e
2 changed files with 46 additions and 7 deletions

View File

@ -277,13 +277,13 @@ void Updates::checkLastUpdate(bool afterSleep) {
void Updates::feedUpdateVector( void Updates::feedUpdateVector(
const MTPVector<MTPUpdate> &updates, const MTPVector<MTPUpdate> &updates,
bool skipMessageIds) { SkipUpdatePolicy policy) {
auto list = updates.v; auto list = updates.v;
const auto needsSorting = ranges::contains( const auto hasGroupCallParticipantUpdates = ranges::contains(
list, list,
mtpc_updateGroupCallParticipants, mtpc_updateGroupCallParticipants,
&MTPUpdate::type); &MTPUpdate::type);
if (needsSorting) { if (hasGroupCallParticipantUpdates) {
ranges::stable_sort(list, std::less<>(), [](const MTPUpdate &entry) { ranges::stable_sort(list, std::less<>(), [](const MTPUpdate &entry) {
if (entry.type() == mtpc_updateGroupCallParticipants) { if (entry.type() == mtpc_updateGroupCallParticipants) {
return 0; return 0;
@ -291,9 +291,15 @@ void Updates::feedUpdateVector(
return 1; return 1;
} }
}); });
} else if (policy == SkipUpdatePolicy::SkipExceptGroupCallParticipants) {
return;
} }
for (const auto &entry : std::as_const(list)) { for (const auto &entry : std::as_const(list)) {
if (skipMessageIds && entry.type() == mtpc_updateMessageID) { const auto type = entry.type();
if ((policy == SkipUpdatePolicy::SkipMessageIds
&& type == mtpc_updateMessageID)
|| (policy == SkipUpdatePolicy::SkipExceptGroupCallParticipants
&& type != mtpc_updateGroupCallParticipants)) {
continue; continue;
} }
feedUpdate(entry); feedUpdate(entry);
@ -406,7 +412,9 @@ void Updates::feedChannelDifference(
session().data().processMessages( session().data().processMessages(
data.vnew_messages(), data.vnew_messages(),
NewMessageType::Unread); NewMessageType::Unread);
feedUpdateVector(data.vother_updates(), true); feedUpdateVector(
data.vother_updates(),
SkipUpdatePolicy::SkipMessageIds);
_handlingChannelDifference = false; _handlingChannelDifference = false;
} }
@ -567,7 +575,7 @@ void Updates::feedDifference(
session().data().processChats(chats); session().data().processChats(chats);
feedMessageIds(other); feedMessageIds(other);
session().data().processMessages(msgs, NewMessageType::Unread); session().data().processMessages(msgs, NewMessageType::Unread);
feedUpdateVector(other, true); feedUpdateVector(other, SkipUpdatePolicy::SkipMessageIds);
} }
void Updates::differenceFail(const MTP::Error &error) { void Updates::differenceFail(const MTP::Error &error) {
@ -824,9 +832,32 @@ void Updates::mtpUpdateReceived(const MTPUpdates &updates) {
if (!requestingDifference() if (!requestingDifference()
|| HasForceLogoutNotification(updates)) { || HasForceLogoutNotification(updates)) {
applyUpdates(updates); applyUpdates(updates);
} else {
applyGroupCallParticipantUpdates(updates);
} }
} }
void Updates::applyGroupCallParticipantUpdates(const MTPUpdates &updates) {
updates.match([&](const MTPDupdates &data) {
session().data().processUsers(data.vusers());
session().data().processChats(data.vchats());
feedUpdateVector(
data.vupdates(),
SkipUpdatePolicy::SkipExceptGroupCallParticipants);
}, [&](const MTPDupdatesCombined &data) {
session().data().processUsers(data.vusers());
session().data().processChats(data.vchats());
feedUpdateVector(
data.vupdates(),
SkipUpdatePolicy::SkipExceptGroupCallParticipants);
}, [&](const MTPDupdateShort &data) {
if (data.vupdate().type() == mtpc_updateGroupCallParticipants) {
feedUpdate(data.vupdate());
}
}, [](const auto &) {
});
}
int32 Updates::pts() const { int32 Updates::pts() const {
return _ptsWaiter.current(); return _ptsWaiter.current();
} }

View File

@ -66,6 +66,12 @@ private:
AfterFail, AfterFail,
}; };
enum class SkipUpdatePolicy {
SkipNone,
SkipMessageIds,
SkipExceptGroupCallParticipants,
};
struct ActiveChatTracker { struct ActiveChatTracker {
PeerData *peer = nullptr; PeerData *peer = nullptr;
rpl::lifetime lifetime; rpl::lifetime lifetime;
@ -113,12 +119,14 @@ private:
void mtpNewSessionCreated(); void mtpNewSessionCreated();
void feedUpdateVector( void feedUpdateVector(
const MTPVector<MTPUpdate> &updates, const MTPVector<MTPUpdate> &updates,
bool skipMessageIds = false); SkipUpdatePolicy policy = SkipUpdatePolicy::SkipNone);
// Doesn't call sendHistoryChangeNotifications itself. // Doesn't call sendHistoryChangeNotifications itself.
void feedMessageIds(const MTPVector<MTPUpdate> &updates); void feedMessageIds(const MTPVector<MTPUpdate> &updates);
// Doesn't call sendHistoryChangeNotifications itself. // Doesn't call sendHistoryChangeNotifications itself.
void feedUpdate(const MTPUpdate &update); void feedUpdate(const MTPUpdate &update);
void applyGroupCallParticipantUpdates(const MTPUpdates &updates);
bool whenGetDiffChanged( bool whenGetDiffChanged(
ChannelData *channel, ChannelData *channel,
int32 ms, int32 ms,