/* 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; not_null admin; TimeId date; TimeId expireDate = 0; int usageLimit = 0; int usage = 0; bool permanent = false; bool expired = false; bool revoked = false; }; struct PeerInviteLinks { std::vector links; int count = 0; }; class InviteLinks final { public: explicit InviteLinks(not_null api); using Link = InviteLink; using Links = PeerInviteLinks; void create( not_null peer, Fn done = nullptr, TimeId expireDate = 0, int usageLimit = 0); void edit( not_null peer, const QString &link, TimeId expireDate, int usageLimit, Fn done = nullptr); void revoke( not_null peer, const QString &link, Fn done = nullptr); void setPermanent( not_null peer, const MTPExportedChatInvite &invite); void clearPermanent(not_null peer); void requestLinks(not_null peer); [[nodiscard]] const Links &links(not_null peer) const; void requestMoreLinks( not_null peer, const QString &last, Fn done); private: struct EditKey { not_null peer; QString link; friend inline bool operator<(const EditKey &a, const EditKey &b) { return (a.peer == b.peer) ? (a.link < b.link) : (a.peer < b.peer); } }; [[nodiscard]] Links parseSlice( not_null peer, const MTPmessages_ExportedChatInvites &slice) const; [[nodiscard]] Link parse( not_null peer, const MTPExportedChatInvite &invite) const; [[nodiscard]] Link *lookupPermanent(not_null peer); [[nodiscard]] Link *lookupPermanent(Links &links); [[nodiscard]] const Link *lookupPermanent(const Links &links) const; Link prepend( not_null peer, const MTPExportedChatInvite &invite); void notify(not_null peer); void editPermanentLink( not_null peer, const QString &link); void performEdit( not_null peer, const QString &link, Fn done, bool revoke, TimeId expireDate = 0, int usageLimit = 0); void performCreate( not_null peer, Fn done, bool revokeLegacyPermanent, TimeId expireDate = 0, int usageLimit = 0); const not_null _api; base::flat_map, Links> _firstSlices; base::flat_map, mtpRequestId> _firstSliceRequests; base::flat_map< not_null, std::vector>> _createCallbacks; base::flat_map>> _editCallbacks; }; } // namespace Api