mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-17 06:37:24 +02:00
Moved out saving of ringtones to api toggling media module.
This commit is contained in:
parent
ea30918d35
commit
cf6b995c50
6 changed files with 47 additions and 28 deletions
|
@ -7,11 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "api/api_ringtones.h"
|
||||
|
||||
#include "api/api_toggling_media.h"
|
||||
#include "apiwrap.h"
|
||||
#include "base/random.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_document_media.h"
|
||||
#include "data/data_file_origin.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/notify/data_notify_settings.h"
|
||||
#include "main/main_session.h"
|
||||
|
@ -175,15 +177,16 @@ void Ringtones::applyUpdate() {
|
|||
|
||||
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();
|
||||
ToggleSavedRingtone(
|
||||
document,
|
||||
Data::FileOriginRingtones(),
|
||||
crl::guard(&document->session(), [=] {
|
||||
const auto it = ranges::find(_list.documents, id);
|
||||
if (it != end(_list.documents)) {
|
||||
_list.documents.erase(it);
|
||||
}
|
||||
}),
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,11 +29,7 @@ void ToggleExistingMedia(
|
|||
const auto usedFileReference = document->fileReference();
|
||||
api->request(std::move(
|
||||
toggleRequest
|
||||
)).done([=](const MTPBool &result) {
|
||||
if (mtpIsTrue(result)) {
|
||||
done();
|
||||
}
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
)).done(done).fail([=](const MTP::Error &error) {
|
||||
if (error.code() == 400
|
||||
&& error.type().startsWith(u"FILE_REFERENCE_"_q)) {
|
||||
auto refreshed = [=](const Data::UpdatedFileReferences &d) {
|
||||
|
@ -114,4 +110,16 @@ void ToggleSavedGif(
|
|||
std::move(done));
|
||||
}
|
||||
|
||||
void ToggleSavedRingtone(
|
||||
not_null<DocumentData*> document,
|
||||
Data::FileOrigin origin,
|
||||
Fn<void()> &&done,
|
||||
bool saved) {
|
||||
ToggleExistingMedia(
|
||||
document,
|
||||
std::move(origin),
|
||||
MTPaccount_SaveRingtone(document->mtpInput(), MTP_bool(!saved)),
|
||||
std::move(done));
|
||||
}
|
||||
|
||||
} // namespace Api
|
||||
|
|
|
@ -28,4 +28,10 @@ void ToggleSavedGif(
|
|||
Data::FileOrigin origin,
|
||||
bool saved);
|
||||
|
||||
void ToggleSavedRingtone(
|
||||
not_null<DocumentData*> document,
|
||||
Data::FileOrigin origin,
|
||||
Fn<void()> &&done,
|
||||
bool saved);
|
||||
|
||||
} // namespace Api
|
||||
|
|
|
@ -2050,9 +2050,10 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
|||
showContextInFolder(document);
|
||||
}, &st::menuIconShowInFolder);
|
||||
}
|
||||
if (!hasCopyRestriction(item)) {
|
||||
if (item && !hasCopyRestriction(item)) {
|
||||
HistoryView::AddSaveSoundForNotifications(
|
||||
_menu,
|
||||
item,
|
||||
document,
|
||||
controller);
|
||||
_menu->addAction(lnkIsVideo ? tr::lng_context_save_video(tr::now) : (lnkIsVoice ? tr::lng_context_save_audio(tr::now) : (lnkIsAudio ? tr::lng_context_save_audio_file(tr::now) : tr::lng_context_save_file(tr::now))), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] {
|
||||
|
|
|
@ -296,8 +296,9 @@ void AddDocumentActions(
|
|||
std::move(callback),
|
||||
&st::menuIconStickers);
|
||||
}
|
||||
if (!list->hasCopyRestriction(item)) {
|
||||
AddSaveSoundForNotifications(menu, document, list->controller());
|
||||
if (item && !list->hasCopyRestriction(item)) {
|
||||
const auto controller = list->controller();
|
||||
AddSaveSoundForNotifications(menu, item, document, controller);
|
||||
}
|
||||
AddSaveDocumentAction(menu, item, document, list);
|
||||
}
|
||||
|
@ -1078,6 +1079,7 @@ void AddPollActions(
|
|||
|
||||
void AddSaveSoundForNotifications(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
not_null<HistoryItem*> item,
|
||||
not_null<DocumentData*> document,
|
||||
not_null<Window::SessionController*> controller) {
|
||||
const auto &ringtones = document->session().api().ringtones();
|
||||
|
@ -1098,17 +1100,15 @@ void AddSaveSoundForNotifications(
|
|||
}
|
||||
const auto toastParent = Window::Show(controller).toastParent();
|
||||
menu->addAction(tr::lng_context_save_custom_sound(tr::now), [=] {
|
||||
document->session().api().request(MTPaccount_SaveRingtone(
|
||||
document->mtpInput(),
|
||||
MTP_bool(false)
|
||||
)).done([=] {
|
||||
Ui::Toast::Show(
|
||||
toastParent,
|
||||
tr::lng_ringtones_toast_added(tr::now));
|
||||
}).fail([](const MTP::Error &error) {
|
||||
LOG(("API Error: Saving ringtone failed with %1 message."
|
||||
).arg(error.type()));
|
||||
}).send();
|
||||
Api::ToggleSavedRingtone(
|
||||
document,
|
||||
item->fullId(),
|
||||
[=] {
|
||||
Ui::Toast::Show(
|
||||
toastParent,
|
||||
tr::lng_ringtones_toast_added(tr::now));
|
||||
},
|
||||
true);
|
||||
}, &st::menuIconSoundAdd);
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ void AddPollActions(
|
|||
Context context);
|
||||
void AddSaveSoundForNotifications(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
not_null<HistoryItem*> item,
|
||||
not_null<DocumentData*> document,
|
||||
not_null<Window::SessionController*> controller);
|
||||
void AddWhoReactedAction(
|
||||
|
|
Loading…
Add table
Reference in a new issue