2021-01-14 09:05:14 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
class ApiWrap;
|
|
|
|
|
|
|
|
namespace Api {
|
|
|
|
|
|
|
|
struct InviteLink {
|
|
|
|
QString link;
|
2021-10-28 12:18:49 +00:00
|
|
|
QString label;
|
2021-01-14 09:05:14 +00:00
|
|
|
not_null<UserData*> admin;
|
2021-01-18 16:13:58 +00:00
|
|
|
TimeId date = 0;
|
|
|
|
TimeId startDate = 0;
|
2021-01-14 09:05:14 +00:00
|
|
|
TimeId expireDate = 0;
|
|
|
|
int usageLimit = 0;
|
|
|
|
int usage = 0;
|
2021-10-12 18:44:35 +00:00
|
|
|
int requested = 0;
|
2021-10-12 08:39:07 +00:00
|
|
|
bool requestApproval = false;
|
2021-01-14 13:13:43 +00:00
|
|
|
bool permanent = false;
|
2021-01-14 09:05:14 +00:00
|
|
|
bool revoked = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PeerInviteLinks {
|
|
|
|
std::vector<InviteLink> links;
|
|
|
|
int count = 0;
|
|
|
|
};
|
|
|
|
|
2021-01-15 15:27:34 +00:00
|
|
|
struct JoinedByLinkUser {
|
|
|
|
not_null<UserData*> user;
|
|
|
|
TimeId date = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct JoinedByLinkSlice {
|
|
|
|
std::vector<JoinedByLinkUser> users;
|
|
|
|
int count = 0;
|
|
|
|
};
|
|
|
|
|
2021-01-19 08:41:22 +00:00
|
|
|
struct InviteLinkUpdate {
|
|
|
|
not_null<PeerData*> peer;
|
2021-02-05 13:22:02 +00:00
|
|
|
not_null<UserData*> admin;
|
2021-01-19 08:41:22 +00:00
|
|
|
QString was;
|
|
|
|
std::optional<InviteLink> now;
|
|
|
|
};
|
2021-02-02 10:43:38 +00:00
|
|
|
|
|
|
|
[[nodiscard]] JoinedByLinkSlice ParseJoinedByLinkSlice(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const MTPmessages_ChatInviteImporters &slice);
|
2021-01-19 10:56:01 +00:00
|
|
|
|
2021-01-14 09:05:14 +00:00
|
|
|
class InviteLinks final {
|
|
|
|
public:
|
|
|
|
explicit InviteLinks(not_null<ApiWrap*> api);
|
|
|
|
|
|
|
|
using Link = InviteLink;
|
|
|
|
using Links = PeerInviteLinks;
|
2021-01-19 08:41:22 +00:00
|
|
|
using Update = InviteLinkUpdate;
|
2021-01-14 09:05:14 +00:00
|
|
|
|
|
|
|
void create(
|
|
|
|
not_null<PeerData*> peer,
|
2021-01-14 13:13:43 +00:00
|
|
|
Fn<void(Link)> done = nullptr,
|
2021-10-28 12:18:49 +00:00
|
|
|
const QString &label = QString(),
|
2021-01-14 09:05:14 +00:00
|
|
|
TimeId expireDate = 0,
|
2021-10-12 08:39:07 +00:00
|
|
|
int usageLimit = 0,
|
|
|
|
bool requestApproval = false);
|
2021-01-14 09:05:14 +00:00
|
|
|
void edit(
|
|
|
|
not_null<PeerData*> peer,
|
2021-02-05 13:22:02 +00:00
|
|
|
not_null<UserData*> admin,
|
2021-01-14 09:05:14 +00:00
|
|
|
const QString &link,
|
2021-10-28 12:18:49 +00:00
|
|
|
const QString &label,
|
2021-01-14 09:05:14 +00:00
|
|
|
TimeId expireDate,
|
2021-01-14 13:13:43 +00:00
|
|
|
int usageLimit,
|
2021-10-12 08:39:07 +00:00
|
|
|
bool requestApproval,
|
2021-01-14 13:13:43 +00:00
|
|
|
Fn<void(Link)> done = nullptr);
|
|
|
|
void revoke(
|
|
|
|
not_null<PeerData*> peer,
|
2021-02-05 13:22:02 +00:00
|
|
|
not_null<UserData*> admin,
|
2021-01-14 13:13:43 +00:00
|
|
|
const QString &link,
|
|
|
|
Fn<void(Link)> done = nullptr);
|
2021-01-18 16:13:58 +00:00
|
|
|
void revokePermanent(
|
|
|
|
not_null<PeerData*> peer,
|
2021-02-05 13:22:02 +00:00
|
|
|
not_null<UserData*> admin,
|
|
|
|
const QString &link,
|
2021-02-02 10:43:38 +00:00
|
|
|
Fn<void()> done = nullptr);
|
2021-01-19 10:26:00 +00:00
|
|
|
void destroy(
|
|
|
|
not_null<PeerData*> peer,
|
2021-02-05 13:22:02 +00:00
|
|
|
not_null<UserData*> admin,
|
2021-01-19 10:26:00 +00:00
|
|
|
const QString &link,
|
|
|
|
Fn<void()> done = nullptr);
|
|
|
|
void destroyAllRevoked(
|
|
|
|
not_null<PeerData*> peer,
|
2021-02-05 13:22:02 +00:00
|
|
|
not_null<UserData*> admin,
|
2021-01-19 10:26:00 +00:00
|
|
|
Fn<void()> done = nullptr);
|
2021-01-14 13:13:43 +00:00
|
|
|
|
2021-02-05 13:22:02 +00:00
|
|
|
void setMyPermanent(
|
2021-01-14 13:13:43 +00:00
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const MTPExportedChatInvite &invite);
|
2021-02-05 13:22:02 +00:00
|
|
|
void clearMyPermanent(not_null<PeerData*> peer);
|
2021-01-14 09:05:14 +00:00
|
|
|
|
2021-02-05 13:22:02 +00:00
|
|
|
void requestMyLinks(not_null<PeerData*> peer);
|
|
|
|
[[nodiscard]] const Links &myLinks(not_null<PeerData*> peer) const;
|
2021-01-14 09:05:14 +00:00
|
|
|
|
2021-10-12 18:44:35 +00:00
|
|
|
void processRequest(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const QString &link,
|
|
|
|
not_null<UserData*> user,
|
|
|
|
bool approved,
|
|
|
|
Fn<void()> done,
|
|
|
|
Fn<void()> fail);
|
|
|
|
void applyExternalUpdate(not_null<PeerData*> peer, InviteLink updated);
|
|
|
|
|
2021-01-15 15:27:34 +00:00
|
|
|
[[nodiscard]] rpl::producer<JoinedByLinkSlice> joinedFirstSliceValue(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const QString &link,
|
|
|
|
int fullCount);
|
2021-01-19 10:56:01 +00:00
|
|
|
[[nodiscard]] std::optional<JoinedByLinkSlice> joinedFirstSliceLoaded(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const QString &link) const;
|
2021-01-19 08:41:22 +00:00
|
|
|
[[nodiscard]] rpl::producer<Update> updates(
|
2021-02-05 14:36:37 +00:00
|
|
|
not_null<PeerData*> peer,
|
|
|
|
not_null<UserData*> admin) const;
|
2021-01-19 10:26:00 +00:00
|
|
|
[[nodiscard]] rpl::producer<> allRevokedDestroyed(
|
2021-02-05 14:36:37 +00:00
|
|
|
not_null<PeerData*> peer,
|
|
|
|
not_null<UserData*> admin) const;
|
2021-01-15 15:27:34 +00:00
|
|
|
|
2021-01-14 09:05:14 +00:00
|
|
|
void requestMoreLinks(
|
|
|
|
not_null<PeerData*> peer,
|
2021-02-05 13:22:02 +00:00
|
|
|
not_null<UserData*> admin,
|
2021-01-19 10:56:01 +00:00
|
|
|
TimeId lastDate,
|
|
|
|
const QString &lastLink,
|
2021-01-19 07:14:50 +00:00
|
|
|
bool revoked,
|
2021-01-14 09:05:14 +00:00
|
|
|
Fn<void(Links)> done);
|
|
|
|
|
|
|
|
private:
|
2021-01-15 15:27:34 +00:00
|
|
|
struct LinkKey {
|
2021-01-14 09:05:14 +00:00
|
|
|
not_null<PeerData*> peer;
|
|
|
|
QString link;
|
|
|
|
|
2021-01-15 15:27:34 +00:00
|
|
|
friend inline bool operator<(const LinkKey &a, const LinkKey &b) {
|
2021-01-14 09:05:14 +00:00
|
|
|
return (a.peer == b.peer)
|
|
|
|
? (a.link < b.link)
|
|
|
|
: (a.peer < b.peer);
|
|
|
|
}
|
2021-01-15 15:27:34 +00:00
|
|
|
friend inline bool operator==(const LinkKey &a, const LinkKey &b) {
|
|
|
|
return (a.peer == b.peer) && (a.link == b.link);
|
|
|
|
}
|
2021-01-14 09:05:14 +00:00
|
|
|
};
|
2021-10-12 18:44:35 +00:00
|
|
|
struct ProcessRequest {
|
|
|
|
Fn<void()> done;
|
|
|
|
Fn<void()> fail;
|
|
|
|
};
|
2021-01-14 09:05:14 +00:00
|
|
|
|
2021-02-02 10:43:38 +00:00
|
|
|
[[nodiscard]] Links parseSlice(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const MTPmessages_ExportedChatInvites &slice) const;
|
2021-01-14 13:13:43 +00:00
|
|
|
[[nodiscard]] Link parse(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const MTPExportedChatInvite &invite) const;
|
2021-02-05 17:35:29 +00:00
|
|
|
[[nodiscard]] Link *lookupMyPermanent(not_null<PeerData*> peer);
|
|
|
|
[[nodiscard]] Link *lookupMyPermanent(Links &links);
|
|
|
|
[[nodiscard]] const Link *lookupMyPermanent(const Links &links) const;
|
2021-01-14 13:13:43 +00:00
|
|
|
Link prepend(
|
|
|
|
not_null<PeerData*> peer,
|
2021-02-05 13:22:02 +00:00
|
|
|
not_null<UserData*> admin,
|
2021-01-14 13:13:43 +00:00
|
|
|
const MTPExportedChatInvite &invite);
|
2021-02-05 17:35:29 +00:00
|
|
|
void prependMyToFirstSlice(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
not_null<UserData*> admin,
|
|
|
|
const Link &link);
|
2021-01-14 13:13:43 +00:00
|
|
|
void notify(not_null<PeerData*> peer);
|
|
|
|
|
|
|
|
void editPermanentLink(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const QString &link);
|
|
|
|
|
|
|
|
void performEdit(
|
|
|
|
not_null<PeerData*> peer,
|
2021-02-05 13:22:02 +00:00
|
|
|
not_null<UserData*> admin,
|
2021-01-14 13:13:43 +00:00
|
|
|
const QString &link,
|
|
|
|
Fn<void(Link)> done,
|
|
|
|
bool revoke,
|
2021-10-28 12:18:49 +00:00
|
|
|
const QString &label = QString(),
|
2021-01-14 13:13:43 +00:00
|
|
|
TimeId expireDate = 0,
|
2021-10-12 08:39:07 +00:00
|
|
|
int usageLimit = 0,
|
|
|
|
bool requestApproval = false);
|
2021-01-14 13:13:43 +00:00
|
|
|
void performCreate(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
Fn<void(Link)> done,
|
|
|
|
bool revokeLegacyPermanent,
|
2021-10-28 12:18:49 +00:00
|
|
|
const QString &label = QString(),
|
2021-01-14 13:13:43 +00:00
|
|
|
TimeId expireDate = 0,
|
2021-10-12 08:39:07 +00:00
|
|
|
int usageLimit = 0,
|
|
|
|
bool requestApproval = false);
|
2021-01-14 09:05:14 +00:00
|
|
|
|
2021-01-15 15:27:34 +00:00
|
|
|
void requestJoinedFirstSlice(LinkKey key);
|
2021-01-19 10:56:01 +00:00
|
|
|
[[nodiscard]] std::optional<JoinedByLinkSlice> lookupJoinedFirstSlice(
|
2021-01-15 15:27:34 +00:00
|
|
|
LinkKey key) const;
|
|
|
|
|
2021-01-14 09:05:14 +00:00
|
|
|
const not_null<ApiWrap*> _api;
|
|
|
|
|
|
|
|
base::flat_map<not_null<PeerData*>, Links> _firstSlices;
|
|
|
|
base::flat_map<not_null<PeerData*>, mtpRequestId> _firstSliceRequests;
|
|
|
|
|
2021-01-15 15:27:34 +00:00
|
|
|
base::flat_map<LinkKey, JoinedByLinkSlice> _firstJoined;
|
|
|
|
base::flat_map<LinkKey, mtpRequestId> _firstJoinedRequests;
|
|
|
|
rpl::event_stream<LinkKey> _joinedFirstSliceLoaded;
|
|
|
|
|
2021-01-14 13:13:43 +00:00
|
|
|
base::flat_map<
|
|
|
|
not_null<PeerData*>,
|
|
|
|
std::vector<Fn<void(Link)>>> _createCallbacks;
|
2021-01-15 15:27:34 +00:00
|
|
|
base::flat_map<LinkKey, std::vector<Fn<void(Link)>>> _editCallbacks;
|
2021-01-19 10:26:00 +00:00
|
|
|
base::flat_map<LinkKey, std::vector<Fn<void()>>> _deleteCallbacks;
|
|
|
|
base::flat_map<
|
|
|
|
not_null<PeerData*>,
|
|
|
|
std::vector<Fn<void()>>> _deleteRevokedCallbacks;
|
2021-01-14 09:05:14 +00:00
|
|
|
|
2021-10-12 18:44:35 +00:00
|
|
|
base::flat_map<
|
|
|
|
std::pair<not_null<PeerData*>, not_null<UserData*>>,
|
|
|
|
ProcessRequest> _processRequests;
|
|
|
|
|
2021-01-19 08:41:22 +00:00
|
|
|
rpl::event_stream<Update> _updates;
|
2021-02-05 14:36:37 +00:00
|
|
|
|
|
|
|
struct AllRevokedDestroyed {
|
|
|
|
not_null<PeerData*> peer;
|
|
|
|
not_null<UserData*> admin;
|
|
|
|
};
|
|
|
|
rpl::event_stream<AllRevokedDestroyed> _allRevokedDestroyed;
|
2021-01-19 08:41:22 +00:00
|
|
|
|
2021-01-14 09:05:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Api
|