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

Improve update handling for legacy chats.

This commit is contained in:
John Preston
2019-01-13 12:03:34 +04:00
parent 215856adc3
commit 67d12fa6d2
28 changed files with 650 additions and 797 deletions

View File

@@ -430,9 +430,8 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
const auto chat = result->asChat();
const auto canAddMembers = chat->canAddMembers();
if (chat->version < data.vversion.v) {
chat->version = data.vversion.v;
if (chat->version() < data.vversion.v) {
chat->setVersion(data.vversion.v);
chat->invalidateParticipants();
}
@@ -561,8 +560,8 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
channel->inputChannel = MTP_inputChannel(data.vid, data.vaccess_hash);
channel->access = data.vaccess_hash.v;
channel->date = data.vdate.v;
if (channel->version < data.vversion.v) {
channel->version = data.vversion.v;
if (channel->version() < data.vversion.v) {
channel->setVersion(data.vversion.v);
}
channel->setUnavailableReason(data.is_restricted()
? ExtractUnavailableReason(qs(data.vrestriction_reason))
@@ -657,6 +656,25 @@ PeerData *Session::processChats(const MTPVector<MTPChat> &data) {
return result;
}
void Session::applyMaximumChatVersions(const MTPVector<MTPChat> &data) {
for (const auto &chat : data.v) {
chat.match([&](const MTPDchat &data) {
if (const auto chat = chatLoaded(data.vid.v)) {
if (data.vversion.v < chat->version()) {
chat->setVersion(data.vversion.v);
}
}
}, [&](const MTPDchannel &data) {
if (const auto channel = channelLoaded(data.vid.v)) {
if (data.vversion.v < channel->version()) {
channel->setVersion(data.vversion.v);
}
}
}, [](const auto &) {
});
}
}
PeerData *Session::peerByUsername(const QString &username) const {
const auto uname = username.trimmed();
for (const auto &[peerId, peer] : _peers) {
@@ -2372,7 +2390,7 @@ not_null<PollData*> Session::poll(const MTPDmessageMediaPoll &data) {
return result;
}
void Session::applyPollUpdate(const MTPDupdateMessagePoll &update) {
void Session::applyUpdate(const MTPDupdateMessagePoll &update) {
const auto updated = [&] {
const auto i = _polls.find(update.vpoll_id.v);
return (i == end(_polls))
@@ -2386,6 +2404,51 @@ void Session::applyPollUpdate(const MTPDupdateMessagePoll &update) {
}
}
void Session::applyUpdate(const MTPDupdateChatParticipants &update) {
const auto chatId = update.vparticipants.match([](const auto &update) {
return update.vchat_id.v;
});
if (const auto chat = chatLoaded(chatId)) {
ApplyChatUpdate(chat, update);
for (const auto user : chat->participants) {
if (user->botInfo && !user->botInfo->inited) {
_session->api().requestFullPeer(user);
}
}
}
}
void Session::applyUpdate(const MTPDupdateChatParticipantAdd &update) {
if (const auto chat = chatLoaded(update.vchat_id.v)) {
ApplyChatUpdate(chat, update);
}
}
void Session::applyUpdate(const MTPDupdateChatParticipantDelete &update) {
if (const auto chat = chatLoaded(update.vchat_id.v)) {
ApplyChatUpdate(chat, update);
}
}
void Session::applyUpdate(const MTPDupdateChatParticipantAdmin &update) {
if (const auto chat = chatLoaded(update.vchat_id.v)) {
ApplyChatUpdate(chat, update);
}
}
void Session::applyUpdate(const MTPDupdateChatDefaultBannedRights &update) {
if (const auto peer = peerLoaded(peerFromMTP(update.vpeer))) {
if (const auto chat = peer->asChat()) {
ApplyChatUpdate(chat, update);
} else if (const auto channel = peer->asChannel()) {
ApplyChannelUpdate(channel, update);
} else {
LOG(("API Error: "
"User received in updateChatDefaultBannedRights."));
}
}
}
not_null<LocationData*> Session::location(const LocationCoords &coords) {
auto i = _locations.find(coords);
if (i == _locations.cend()) {