mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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_ringtones.h"
|
||||||
|
|
||||||
|
#include "api/api_toggling_media.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "base/random.h"
|
#include "base/random.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
#include "data/data_document_media.h"
|
#include "data/data_document_media.h"
|
||||||
|
#include "data/data_file_origin.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/notify/data_notify_settings.h"
|
#include "data/notify/data_notify_settings.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
@ -175,15 +177,16 @@ void Ringtones::applyUpdate() {
|
||||||
|
|
||||||
void Ringtones::remove(DocumentId id) {
|
void Ringtones::remove(DocumentId id) {
|
||||||
if (const auto document = _session->data().document(id)) {
|
if (const auto document = _session->data().document(id)) {
|
||||||
_api.request(MTPaccount_SaveRingtone(
|
ToggleSavedRingtone(
|
||||||
document->mtpInput(),
|
document,
|
||||||
MTP_bool(true)
|
Data::FileOriginRingtones(),
|
||||||
)).done([=] {
|
crl::guard(&document->session(), [=] {
|
||||||
const auto it = ranges::find(_list.documents, id);
|
const auto it = ranges::find(_list.documents, id);
|
||||||
if (it != end(_list.documents)) {
|
if (it != end(_list.documents)) {
|
||||||
_list.documents.erase(it);
|
_list.documents.erase(it);
|
||||||
}
|
}
|
||||||
}).send();
|
}),
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,7 @@ void ToggleExistingMedia(
|
||||||
const auto usedFileReference = document->fileReference();
|
const auto usedFileReference = document->fileReference();
|
||||||
api->request(std::move(
|
api->request(std::move(
|
||||||
toggleRequest
|
toggleRequest
|
||||||
)).done([=](const MTPBool &result) {
|
)).done(done).fail([=](const MTP::Error &error) {
|
||||||
if (mtpIsTrue(result)) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
}).fail([=](const MTP::Error &error) {
|
|
||||||
if (error.code() == 400
|
if (error.code() == 400
|
||||||
&& error.type().startsWith(u"FILE_REFERENCE_"_q)) {
|
&& error.type().startsWith(u"FILE_REFERENCE_"_q)) {
|
||||||
auto refreshed = [=](const Data::UpdatedFileReferences &d) {
|
auto refreshed = [=](const Data::UpdatedFileReferences &d) {
|
||||||
|
@ -114,4 +110,16 @@ void ToggleSavedGif(
|
||||||
std::move(done));
|
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
|
} // namespace Api
|
||||||
|
|
|
@ -28,4 +28,10 @@ void ToggleSavedGif(
|
||||||
Data::FileOrigin origin,
|
Data::FileOrigin origin,
|
||||||
bool saved);
|
bool saved);
|
||||||
|
|
||||||
|
void ToggleSavedRingtone(
|
||||||
|
not_null<DocumentData*> document,
|
||||||
|
Data::FileOrigin origin,
|
||||||
|
Fn<void()> &&done,
|
||||||
|
bool saved);
|
||||||
|
|
||||||
} // namespace Api
|
} // namespace Api
|
||||||
|
|
|
@ -2050,9 +2050,10 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
||||||
showContextInFolder(document);
|
showContextInFolder(document);
|
||||||
}, &st::menuIconShowInFolder);
|
}, &st::menuIconShowInFolder);
|
||||||
}
|
}
|
||||||
if (!hasCopyRestriction(item)) {
|
if (item && !hasCopyRestriction(item)) {
|
||||||
HistoryView::AddSaveSoundForNotifications(
|
HistoryView::AddSaveSoundForNotifications(
|
||||||
_menu,
|
_menu,
|
||||||
|
item,
|
||||||
document,
|
document,
|
||||||
controller);
|
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, [=] {
|
_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),
|
std::move(callback),
|
||||||
&st::menuIconStickers);
|
&st::menuIconStickers);
|
||||||
}
|
}
|
||||||
if (!list->hasCopyRestriction(item)) {
|
if (item && !list->hasCopyRestriction(item)) {
|
||||||
AddSaveSoundForNotifications(menu, document, list->controller());
|
const auto controller = list->controller();
|
||||||
|
AddSaveSoundForNotifications(menu, item, document, controller);
|
||||||
}
|
}
|
||||||
AddSaveDocumentAction(menu, item, document, list);
|
AddSaveDocumentAction(menu, item, document, list);
|
||||||
}
|
}
|
||||||
|
@ -1078,6 +1079,7 @@ void AddPollActions(
|
||||||
|
|
||||||
void AddSaveSoundForNotifications(
|
void AddSaveSoundForNotifications(
|
||||||
not_null<Ui::PopupMenu*> menu,
|
not_null<Ui::PopupMenu*> menu,
|
||||||
|
not_null<HistoryItem*> item,
|
||||||
not_null<DocumentData*> document,
|
not_null<DocumentData*> document,
|
||||||
not_null<Window::SessionController*> controller) {
|
not_null<Window::SessionController*> controller) {
|
||||||
const auto &ringtones = document->session().api().ringtones();
|
const auto &ringtones = document->session().api().ringtones();
|
||||||
|
@ -1098,17 +1100,15 @@ void AddSaveSoundForNotifications(
|
||||||
}
|
}
|
||||||
const auto toastParent = Window::Show(controller).toastParent();
|
const auto toastParent = Window::Show(controller).toastParent();
|
||||||
menu->addAction(tr::lng_context_save_custom_sound(tr::now), [=] {
|
menu->addAction(tr::lng_context_save_custom_sound(tr::now), [=] {
|
||||||
document->session().api().request(MTPaccount_SaveRingtone(
|
Api::ToggleSavedRingtone(
|
||||||
document->mtpInput(),
|
document,
|
||||||
MTP_bool(false)
|
item->fullId(),
|
||||||
)).done([=] {
|
[=] {
|
||||||
Ui::Toast::Show(
|
Ui::Toast::Show(
|
||||||
toastParent,
|
toastParent,
|
||||||
tr::lng_ringtones_toast_added(tr::now));
|
tr::lng_ringtones_toast_added(tr::now));
|
||||||
}).fail([](const MTP::Error &error) {
|
},
|
||||||
LOG(("API Error: Saving ringtone failed with %1 message."
|
true);
|
||||||
).arg(error.type()));
|
|
||||||
}).send();
|
|
||||||
}, &st::menuIconSoundAdd);
|
}, &st::menuIconSoundAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ void AddPollActions(
|
||||||
Context context);
|
Context context);
|
||||||
void AddSaveSoundForNotifications(
|
void AddSaveSoundForNotifications(
|
||||||
not_null<Ui::PopupMenu*> menu,
|
not_null<Ui::PopupMenu*> menu,
|
||||||
|
not_null<HistoryItem*> item,
|
||||||
not_null<DocumentData*> document,
|
not_null<DocumentData*> document,
|
||||||
not_null<Window::SessionController*> controller);
|
not_null<Window::SessionController*> controller);
|
||||||
void AddWhoReactedAction(
|
void AddWhoReactedAction(
|
||||||
|
|
Loading…
Add table
Reference in a new issue