2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-30 22:16:14 +00:00

Choose newly uploaded ringtone in the box.

This commit is contained in:
John Preston
2022-04-06 19:19:50 +04:00
parent d9f6a5206e
commit c71ba2b8e7
4 changed files with 90 additions and 36 deletions

View File

@@ -112,7 +112,9 @@ void Ringtones::ready(const FullMsgId &msgId, const MTPInputFile &file) {
MTP_string(uploadedData.filename),
MTP_string(uploadedData.filemime)
)).done([=](const MTPDocument &result) {
_session->data().processDocument(result);
const auto document = _session->data().processDocument(result);
_list.documents.insert(_list.documents.begin(), document->id);
_uploadDones.fire_copy(document->id);
}).fail([=](const MTP::Error &error) {
_uploadFails.fire_copy(error.type());
}).send();
@@ -128,11 +130,11 @@ void Ringtones::requestList() {
_list.requestId = 0;
result.match([&](const MTPDaccount_savedRingtones &data) {
_list.hash = data.vhash().v;
_list.documents.reserve(_list.documents.size()
+ data.vringtones().v.size());
_list.documents.clear();
_list.documents.reserve(data.vringtones().v.size());
for (const auto &d : data.vringtones().v) {
const auto document = _session->data().processDocument(d);
_list.documents.emplace(document->id);
_list.documents.emplace_back(document->id);
}
requestList();
_list.updates.fire({});
@@ -155,6 +157,10 @@ rpl::producer<QString> Ringtones::uploadFails() const {
return _uploadFails.events();
}
rpl::producer<DocumentId> Ringtones::uploadDones() const {
return _uploadDones.events();
}
void Ringtones::applyUpdate() {
_list.hash = 0;
_list.documents.clear();

View File

@@ -22,7 +22,7 @@ class Ringtones final {
public:
explicit Ringtones(not_null<ApiWrap*> api);
using Ids = std::unordered_set<DocumentId>;
using Ids = std::vector<DocumentId>;
void requestList();
void applyUpdate();
@@ -36,6 +36,7 @@ public:
[[nodiscard]] const Ids &list() const;
[[nodiscard]] rpl::producer<> listUpdates() const;
[[nodiscard]] rpl::producer<QString> uploadFails() const;
[[nodiscard]] rpl::producer<DocumentId> uploadDones() const;
private:
struct UploadedData {
@@ -49,6 +50,7 @@ private:
base::flat_map<FullMsgId, UploadedData> _uploads;
rpl::event_stream<QString> _uploadFails;
rpl::event_stream<DocumentId> _uploadDones;
struct {
uint64 hash = 0;