2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Update link rows in Manage Invite Links.

This commit is contained in:
John Preston
2021-01-19 12:41:22 +04:00
parent 97fb310f54
commit 144bad6c74
3 changed files with 159 additions and 12 deletions

View File

@@ -123,10 +123,16 @@ auto InviteLinks::prepend(
auto &links = i->second;
const auto permanent = lookupPermanent(links);
if (link.permanent) {
auto update = Update{ .peer = peer };
if (permanent) {
update.was = permanent->link;
permanent->revoked = true;
}
editPermanentLink(peer, link.link);
if (permanent) {
update.now = *permanent;
_updates.fire(std::move(update));
}
}
++links.count;
if (permanent && !link.permanent) {
@@ -135,6 +141,7 @@ auto InviteLinks::prepend(
links.links.insert(begin(links.links), link);
}
notify(peer);
_updates.fire(Update{ .peer = peer, .now = link });
return link;
}
@@ -205,6 +212,11 @@ void InviteLinks::performEdit(
for (const auto &callback : *callbacks) {
callback(link);
}
_updates.fire(Update{
.peer = peer,
.was = key.link,
.now = link
});
});
}).fail([=](const RPCError &error) {
_editCallbacks.erase(key);
@@ -298,6 +310,13 @@ rpl::producer<JoinedByLinkSlice> InviteLinks::joinedFirstSliceValue(
}));
}
auto InviteLinks::updates(
not_null<PeerData*> peer) const -> rpl::producer<Update> {
return _updates.events() | rpl::filter([=](const Update &update) {
return update.peer == peer;
});
}
void InviteLinks::requestJoinedFirstSlice(LinkKey key) {
if (_firstJoinedRequests.contains(key)) {
return;
@@ -422,7 +441,6 @@ auto InviteLinks::parse(
.usageLimit = data.vusage_limit().value_or_empty(),
.usage = data.vusage().value_or_empty(),
.permanent = data.is_permanent(),
.expired = data.is_expired(),
.revoked = data.is_revoked(),
};
});

View File

@@ -20,7 +20,6 @@ struct InviteLink {
int usageLimit = 0;
int usage = 0;
bool permanent = false;
bool expired = false;
bool revoked = false;
};
@@ -39,12 +38,19 @@ struct JoinedByLinkSlice {
int count = 0;
};
struct InviteLinkUpdate {
not_null<PeerData*> peer;
QString was;
std::optional<InviteLink> now;
};
class InviteLinks final {
public:
explicit InviteLinks(not_null<ApiWrap*> api);
using Link = InviteLink;
using Links = PeerInviteLinks;
using Update = InviteLinkUpdate;
void create(
not_null<PeerData*> peer,
@@ -77,6 +83,8 @@ public:
not_null<PeerData*> peer,
const QString &link,
int fullCount);
[[nodiscard]] rpl::producer<Update> updates(
not_null<PeerData*> peer) const;
void requestMoreLinks(
not_null<PeerData*> peer,
@@ -152,6 +160,8 @@ private:
std::vector<Fn<void(Link)>>> _createCallbacks;
base::flat_map<LinkKey, std::vector<Fn<void(Link)>>> _editCallbacks;
rpl::event_stream<Update> _updates;
};
} // namespace Api