mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 22:27:20 +02:00
Added api ability to load list of available ringtones.
This commit is contained in:
parent
085c6f9c12
commit
1c9b1ea69f
3 changed files with 82 additions and 1 deletions
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "apiwrap.h"
|
||||
#include "base/random.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_session.h"
|
||||
#include "main/main_session.h"
|
||||
#include "storage/file_upload.h"
|
||||
|
@ -112,8 +113,65 @@ void Ringtones::ready(const FullMsgId &msgId, const MTPInputFile &file) {
|
|||
MTP_string(uploadedData.filemime)
|
||||
)).done([=](const MTPDocument &result) {
|
||||
_session->data().processDocument(result);
|
||||
}).fail([](const MTP::Error &error) {
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
_uploadFails.fire_copy(error.type());
|
||||
}).send();
|
||||
}
|
||||
|
||||
void Ringtones::requestList() {
|
||||
if (_list.requestId) {
|
||||
return;
|
||||
}
|
||||
_list.requestId = _api.request(
|
||||
MTPaccount_GetSavedRingtones(MTP_long(_list.hash))
|
||||
).done([=](const MTPaccount_SavedRingtones &result) {
|
||||
result.match([&](const MTPDaccount_savedRingtones &data) {
|
||||
_list.requestId = 0;
|
||||
_list.hash = data.vhash().v;
|
||||
_list.documents.reserve(_list.documents.size()
|
||||
+ data.vringtones().v.size());
|
||||
for (const auto &d : data.vringtones().v) {
|
||||
const auto document = _session->data().processDocument(d);
|
||||
_list.documents.emplace(document->id);
|
||||
}
|
||||
requestList();
|
||||
}, [&](const MTPDaccount_savedRingtonesNotModified &) {
|
||||
_list.requestId = 0;
|
||||
_list.updates.fire({});
|
||||
});
|
||||
}).send();
|
||||
}
|
||||
|
||||
const Ringtones::Ids &Ringtones::list() const {
|
||||
return _list.documents;
|
||||
}
|
||||
|
||||
rpl::producer<> Ringtones::listUpdates() const {
|
||||
return _list.updates.events();
|
||||
}
|
||||
|
||||
rpl::producer<QString> Ringtones::uploadFails() const {
|
||||
return _uploadFails.events();
|
||||
}
|
||||
|
||||
void Ringtones::applyUpdate() {
|
||||
_list.hash = 0;
|
||||
_list.documents.clear();
|
||||
requestList();
|
||||
}
|
||||
|
||||
void Ringtones::remove(DocumentId id) {
|
||||
if (const auto document = _session->data().document(id)) {
|
||||
_api.request(MTPaccount_SaveRingtone(
|
||||
document->mtpInput(),
|
||||
MTP_bool(true)
|
||||
)).done([=] {
|
||||
const auto it = ranges::find(_list.documents, id);
|
||||
if (it != end(_list.documents)) {
|
||||
_list.documents.erase(it);
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Api
|
||||
|
|
|
@ -22,11 +22,21 @@ class Ringtones final {
|
|||
public:
|
||||
explicit Ringtones(not_null<ApiWrap*> api);
|
||||
|
||||
using Ids = std::unordered_set<DocumentId>;
|
||||
|
||||
void requestList();
|
||||
void applyUpdate();
|
||||
void remove(DocumentId id);
|
||||
|
||||
void upload(
|
||||
const QString &filename,
|
||||
const QString &filemime,
|
||||
const QByteArray &content);
|
||||
|
||||
[[nodiscard]] const Ids &list() const;
|
||||
[[nodiscard]] rpl::producer<> listUpdates() const;
|
||||
[[nodiscard]] rpl::producer<QString> uploadFails() const;
|
||||
|
||||
private:
|
||||
struct UploadedData {
|
||||
QString filename;
|
||||
|
@ -38,6 +48,14 @@ private:
|
|||
MTP::Sender _api;
|
||||
|
||||
base::flat_map<FullMsgId, UploadedData> _uploads;
|
||||
rpl::event_stream<QString> _uploadFails;
|
||||
|
||||
struct {
|
||||
uint64 hash = 0;
|
||||
Ids documents;
|
||||
rpl::event_stream<> updates;
|
||||
mtpRequestId requestId;
|
||||
} _list;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "api/api_authorizations.h"
|
||||
#include "api/api_chat_participants.h"
|
||||
#include "api/api_ringtones.h"
|
||||
#include "api/api_text_entities.h"
|
||||
#include "api/api_user_privacy.h"
|
||||
#include "api/api_unread_things.h"
|
||||
|
@ -2374,6 +2375,10 @@ void Updates::feedUpdate(const MTPUpdate &update) {
|
|||
session().data().cloudThemes().applyUpdate(data.vtheme());
|
||||
} break;
|
||||
|
||||
case mtpc_updateSavedRingtones: {
|
||||
session().api().ringtones().applyUpdate();
|
||||
} break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue