2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Implement fast confcall migration.

This commit is contained in:
John Preston
2025-04-09 14:18:14 +04:00
parent 2a7aac76d9
commit c72cf46db7
13 changed files with 366 additions and 191 deletions

View File

@@ -374,6 +374,7 @@ auto GroupCall::staleParticipantIds() const
}
void GroupCall::enqueueUpdate(const MTPUpdate &update) {
const auto initial = !_version;
update.match([&](const MTPDupdateGroupCall &updateData) {
updateData.vcall().match([&](const MTPDgroupCall &data) {
const auto version = data.vversion().v;
@@ -427,7 +428,7 @@ void GroupCall::enqueueUpdate(const MTPUpdate &update) {
}, [](const auto &) {
Unexpected("Type in GroupCall::enqueueUpdate.");
});
processQueuedUpdates();
processQueuedUpdates(initial);
}
void GroupCall::discard(const MTPDgroupCallDiscarded &data) {
@@ -562,7 +563,7 @@ void GroupCall::applyEnqueuedUpdate(const MTPUpdate &update) {
Core::App().calls().applyGroupCallUpdateChecked(&session(), update);
}
void GroupCall::processQueuedUpdates() {
void GroupCall::processQueuedUpdates(bool initial) {
if (!_version || _applyingQueuedUpdates) {
return;
}
@@ -574,7 +575,13 @@ void GroupCall::processQueuedUpdates() {
const auto type = entry.first.second;
const auto incremented = (type == QueuedType::VersionedParticipant);
if ((version < _version)
|| (version == _version && incremented)) {
|| (version == _version && incremented && !initial)) {
// There is a case for a new conference call we receive:
// - updateGroupCall, version = 2
// - updateGroupCallParticipants, version = 2, versioned
// In case we were joining together with creation,
// in that case we don't want to skip the participants update,
// so we pass the `initial` flag specifically for that case.
_queuedUpdates.erase(_queuedUpdates.begin());
} else if (version == _version
|| (version == _version + 1 && incremented)) {

View File

@@ -215,7 +215,7 @@ private:
void applyEnqueuedUpdate(const MTPUpdate &update);
void setServerParticipantsCount(int count);
void computeParticipantsCount();
void processQueuedUpdates();
void processQueuedUpdates(bool initial = false);
void processFullCallUsersChats(const MTPphone_GroupCall &call);
void processFullCallFields(const MTPphone_GroupCall &call);
[[nodiscard]] bool requestParticipantsAfterReload(

View File

@@ -1159,6 +1159,36 @@ std::shared_ptr<GroupCall> Session::sharedConferenceCall(
return result;
}
std::shared_ptr<GroupCall> Session::sharedConferenceCallFind(
const MTPUpdates &response) {
const auto list = response.match([&](const MTPDupdates &data) {
return &data.vupdates().v;
}, [&](const MTPDupdatesCombined &data) {
return &data.vupdates().v;
}, [](const auto &) {
return (const QVector<MTPUpdate>*)nullptr;
});
const auto empty = std::shared_ptr<GroupCall>();
if (!list) {
return empty;
}
for (const auto &update : *list) {
const auto call = update.match([&](const MTPDupdateGroupCall &data) {
return data.vcall().match([&](const MTPDgroupCall &data) {
return data.is_conference()
? sharedConferenceCall(
data.vid().v,
data.vaccess_hash().v)
: nullptr;
}, [&](const auto &) { return empty; });
}, [&](const auto &) { return empty; });
if (call) {
return call;
}
}
return empty;
}
void Session::watchForOffline(not_null<UserData*> user, TimeId now) {
if (!now) {
now = base::unixtime::now();

View File

@@ -235,6 +235,8 @@ public:
[[nodiscard]] std::shared_ptr<GroupCall> sharedConferenceCall(
CallId id,
uint64 accessHash);
[[nodiscard]] std::shared_ptr<GroupCall> sharedConferenceCallFind(
const MTPUpdates &response);
void watchForOffline(not_null<UserData*> user, TimeId now = 0);
void maybeStopWatchForOffline(not_null<UserData*> user);