api_ringtones.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "mtproto/sender.h"
  9. class ApiWrap;
  10. class PeerData;
  11. namespace Main {
  12. class Session;
  13. } // namespace Main
  14. namespace Api {
  15. class Ringtones final {
  16. public:
  17. explicit Ringtones(not_null<ApiWrap*> api);
  18. using Ids = std::vector<DocumentId>;
  19. void requestList();
  20. void applyUpdate();
  21. void remove(DocumentId id);
  22. void upload(
  23. const QString &filename,
  24. const QString &filemime,
  25. const QByteArray &content);
  26. [[nodiscard]] const Ids &list() const;
  27. [[nodiscard]] rpl::producer<> listUpdates() const;
  28. [[nodiscard]] rpl::producer<QString> uploadFails() const;
  29. [[nodiscard]] rpl::producer<DocumentId> uploadDones() const;
  30. [[nodiscard]] int64 maxSize() const;
  31. [[nodiscard]] int maxSavedCount() const;
  32. [[nodiscard]] crl::time maxDuration() const;
  33. private:
  34. struct UploadedData {
  35. QString filename;
  36. QString filemime;
  37. QByteArray content;
  38. };
  39. void ready(const FullMsgId &msgId, const MTPInputFile &file);
  40. const not_null<Main::Session*> _session;
  41. MTP::Sender _api;
  42. base::flat_map<FullMsgId, UploadedData> _uploads;
  43. rpl::event_stream<QString> _uploadFails;
  44. rpl::event_stream<DocumentId> _uploadDones;
  45. struct {
  46. uint64 hash = 0;
  47. Ids documents;
  48. rpl::event_stream<> updates;
  49. mtpRequestId requestId = 0;
  50. } _list;
  51. };
  52. } // namespace Api