2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Update API scheme on layer 142.

This commit is contained in:
John Preston
2022-04-15 17:32:34 +04:00
parent 36b8d03b1d
commit a752c4d9f3
10 changed files with 89 additions and 44 deletions

View File

@@ -123,9 +123,9 @@ void InviteLinks::performCreate(
)).done([=](const MTPExportedChatInvite &result) {
const auto callbacks = _createCallbacks.take(peer);
const auto link = prepend(peer, peer->session().user(), result);
if (callbacks) {
if (link && callbacks) {
for (const auto &callback : *callbacks) {
callback(link);
callback(*link);
}
}
}).fail([=] {
@@ -155,15 +155,18 @@ auto InviteLinks::lookupMyPermanent(const Links &links) const -> const Link* {
auto InviteLinks::prepend(
not_null<PeerData*> peer,
not_null<UserData*> admin,
const MTPExportedChatInvite &invite) -> Link {
const MTPExportedChatInvite &invite) -> std::optional<Link> {
const auto link = parse(peer, invite);
if (!link) {
return link;
}
if (admin->isSelf()) {
prependMyToFirstSlice(peer, admin, link);
prependMyToFirstSlice(peer, admin, *link);
}
_updates.fire(Update{
.peer = peer,
.admin = admin,
.now = link
.now = *link
});
return link;
}
@@ -281,6 +284,9 @@ void InviteLinks::performEdit(
result.match([&](const auto &data) {
_api->session().data().processUsers(data.vusers());
const auto link = parse(peer, data.vinvite());
if (!link) {
return;
}
auto i = _firstSlices.find(peer);
if (i != end(_firstSlices)) {
const auto j = ranges::find(
@@ -288,18 +294,18 @@ void InviteLinks::performEdit(
key.link,
&Link::link);
if (j != end(i->second.links)) {
if (link.revoked && !j->revoked) {
if (link->revoked && !j->revoked) {
i->second.links.erase(j);
if (i->second.count > 0) {
--i->second.count;
}
} else {
*j = link;
*j = *link;
}
}
}
for (const auto &callback : *callbacks) {
callback(link);
callback(*link);
}
_updates.fire(Update{
.peer = peer,
@@ -617,7 +623,11 @@ void InviteLinks::setMyPermanent(
not_null<PeerData*> peer,
const MTPExportedChatInvite &invite) {
auto link = parse(peer, invite);
if (!link.permanent) {
if (!link) {
LOG(("API Error: "
"InviteLinks::setPermanent called with non-link."));
return;
} else if (!link->permanent) {
LOG(("API Error: "
"InviteLinks::setPermanent called with non-permanent link."));
return;
@@ -632,13 +642,13 @@ void InviteLinks::setMyPermanent(
.admin = peer->session().user(),
};
if (const auto permanent = lookupMyPermanent(links)) {
if (permanent->link == link.link) {
if (permanent->usage != link.usage) {
permanent->usage = link.usage;
if (permanent->link == link->link) {
if (permanent->usage != link->usage) {
permanent->usage = link->usage;
_updates.fire(Update{
.peer = peer,
.admin = peer->session().user(),
.was = link.link,
.was = link->link,
.now = *permanent
});
}
@@ -652,9 +662,9 @@ void InviteLinks::setMyPermanent(
--links.count;
}
}
links.links.insert(begin(links.links), link);
links.links.insert(begin(links.links), *link);
editPermanentLink(peer, link.link);
editPermanentLink(peer, link->link);
notify(peer);
if (updateOldPermanent.now) {
@@ -722,9 +732,10 @@ auto InviteLinks::parseSlice(
peer->session().data().processUsers(data.vusers());
result.count = data.vcount().v;
for (const auto &invite : data.vinvites().v) {
const auto link = parse(peer, invite);
if (!permanent || link.link != permanent->link) {
result.links.push_back(link);
if (const auto link = parse(peer, invite)) {
if (!permanent || link->link != permanent->link) {
result.links.push_back(*link);
}
}
}
});
@@ -733,9 +744,9 @@ auto InviteLinks::parseSlice(
auto InviteLinks::parse(
not_null<PeerData*> peer,
const MTPExportedChatInvite &invite) const -> Link {
const MTPExportedChatInvite &invite) const -> std::optional<Link> {
return invite.match([&](const MTPDchatInviteExported &data) {
return Link{
return std::optional<Link>(Link{
.link = qs(data.vlink()),
.label = qs(data.vtitle().value_or_empty()),
.admin = peer->session().data().user(data.vadmin_id()),
@@ -748,7 +759,9 @@ auto InviteLinks::parse(
.requestApproval = data.is_request_needed(),
.permanent = data.is_permanent(),
.revoked = data.is_revoked(),
};
});
}, [&](const MTPDchatInvitePublicJoinRequests &data) {
return std::optional<Link>();
});
}

View File

@@ -157,13 +157,13 @@ private:
[[nodiscard]] Links parseSlice(
not_null<PeerData*> peer,
const MTPmessages_ExportedChatInvites &slice) const;
[[nodiscard]] Link parse(
[[nodiscard]] std::optional<Link> parse(
not_null<PeerData*> peer,
const MTPExportedChatInvite &invite) const;
[[nodiscard]] Link *lookupMyPermanent(not_null<PeerData*> peer);
[[nodiscard]] Link *lookupMyPermanent(Links &links);
[[nodiscard]] const Link *lookupMyPermanent(const Links &links) const;
Link prepend(
std::optional<Link> prepend(
not_null<PeerData*> peer,
not_null<UserData*> admin,
const MTPExportedChatInvite &invite);

View File

@@ -1988,7 +1988,7 @@ void Updates::feedUpdate(const MTPUpdate &update) {
const auto botId = UserId(d.vbot_id().v);
if (const auto user = peer->asUser()) {
if (user->isBot() && user->id == peerFromUser(botId)) {
if (Data::UpdateBotCommands(user->botInfo->commands, d.vcommands())) {
if (Data::UpdateBotCommands(user->botInfo->commands, &d.vcommands())) {
session().data().botCommandsChanged(user);
}
}
@@ -2015,7 +2015,7 @@ void Updates::feedUpdate(const MTPUpdate &update) {
const auto &d = update.c_updateBotMenuButton();
if (const auto bot = session().data().userLoaded(d.vbot_id())) {
if (const auto info = bot->botInfo.get(); info && info->inited) {
if (Data::ApplyBotMenuButton(info, d.vbutton())) {
if (Data::ApplyBotMenuButton(info, &d.vbutton())) {
session().data().botCommandsChanged(bot);
}
}