diff --git a/Telegram/Resources/icons/menu/sound_add.png b/Telegram/Resources/icons/menu/sound_add.png new file mode 100644 index 000000000..f2d02e3d3 Binary files /dev/null and b/Telegram/Resources/icons/menu/sound_add.png differ diff --git a/Telegram/Resources/icons/menu/sound_add@2x.png b/Telegram/Resources/icons/menu/sound_add@2x.png new file mode 100644 index 000000000..a310c1bd8 Binary files /dev/null and b/Telegram/Resources/icons/menu/sound_add@2x.png differ diff --git a/Telegram/Resources/icons/menu/sound_add@3x.png b/Telegram/Resources/icons/menu/sound_add@3x.png new file mode 100644 index 000000000..736d44807 Binary files /dev/null and b/Telegram/Resources/icons/menu/sound_add@3x.png differ diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 8e05e06fa..9d1c4e6c5 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1891,6 +1891,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_context_set_as_quick" = "Set As Quick"; "lng_context_delete_from_disk" = "Delete from disk"; "lng_context_delete_all_files" = "Delete all files"; +"lng_context_save_custom_sound" = "Save for notifications"; "lng_downloads_section" = "Downloads"; "lng_downloads_view_in_chat" = "View in chat"; @@ -3128,6 +3129,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_ringtones_box_default" = "Default"; "lng_ringtones_box_no_sound" = "No sound"; "lng_ringtones_box_error" = "Sorry, but your file is too big."; +"lng_ringtones_toast_added" = "Sound added!"; // Wnd specific diff --git a/Telegram/SourceFiles/boxes/ringtones_box.cpp b/Telegram/SourceFiles/boxes/ringtones_box.cpp index 6139feafa..e7d65fb0d 100644 --- a/Telegram/SourceFiles/boxes/ringtones_box.cpp +++ b/Telegram/SourceFiles/boxes/ringtones_box.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/base_file_utilities.h" #include "base/call_delayed.h" #include "base/event_filter.h" +#include "base/unixtime.h" #include "core/file_utilities.h" #include "core/mime_type.h" #include "data/data_document.h" @@ -135,12 +136,12 @@ void RingtonesBox( addToGroup( container, kDefaultValue, - tr::lng_ringtones_box_default({}), + tr::lng_ringtones_box_default(tr::now), false); addToGroup( container, kNoSoundValue, - tr::lng_ringtones_box_no_sound({}), + tr::lng_ringtones_box_no_sound(tr::now), noSound); const auto custom = container->add( @@ -157,7 +158,20 @@ void RingtonesBox( for (const auto &id : peer->session().api().ringtones().list()) { const auto chosen = (checkedId.id && checkedId.id == id); const auto document = peer->session().data().document(id); - addToGroup(custom, value++, document->filename(), chosen); + const auto text = [&] { + if (!document->filename().isEmpty()) { + return document->filename(); + } + const auto date = langDateTime( + base::unixtime::parse(document->date)); + const auto base = document->isVoiceMessage() + ? (tr::lng_in_dlg_audio(tr::now) + ' ') + : document->isAudioFile() + ? (tr::lng_in_dlg_audio_file(tr::now) + ' ') + : QString(); + return base + date; + }(); + addToGroup(custom, value++, text, chosen); state->documentIds.push_back(id); } diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 5fcc14d3f..a8065e779 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2051,6 +2051,10 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { }, &st::menuIconShowInFolder); } if (!hasCopyRestriction(item)) { + HistoryView::AddSaveSoundForNotifications( + _menu, + 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, [=] { saveDocumentToFile(itemId, document); }), &st::menuIconDownload); diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 32f93e15c..2f46f5967 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_attached_stickers.h" #include "api/api_editing.h" #include "api/api_polls.h" +#include "api/api_ringtones.h" #include "api/api_who_reacted.h" #include "api/api_toggling_media.h" // Api::ToggleFavedSticker #include "base/unixtime.h" @@ -68,6 +69,8 @@ namespace HistoryView { namespace { constexpr auto kRescheduleLimit = 20; +constexpr auto kMaxDurationForRingtone = 10; +constexpr auto kMaxSizeForRingtone = 1024 * 500; bool HasEditMessageAction( const ContextMenuRequest &request, @@ -293,6 +296,9 @@ void AddDocumentActions( std::move(callback), &st::menuIconStickers); } + if (!list->hasCopyRestriction(item)) { + AddSaveSoundForNotifications(menu, document, list->controller()); + } AddSaveDocumentAction(menu, item, document, list); } @@ -1070,6 +1076,42 @@ void AddPollActions( } } +void AddSaveSoundForNotifications( + not_null menu, + not_null document, + not_null controller) { + const auto &ringtones = document->session().api().ringtones(); + if (document->size > kMaxSizeForRingtone) { + return; + } else if (ranges::contains(ringtones.list(), document->id)) { + return; + } else if (const auto song = document->song()) { + if (song->duration > kMaxDurationForRingtone) { + return; + } + } else if (const auto voice = document->voice()) { + if (voice->duration > kMaxDurationForRingtone) { + return; + } + } else { + return; + } + 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(); + }, &st::menuIconSoundAdd); +} + void AddWhoReactedAction( not_null menu, not_null context, diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.h b/Telegram/SourceFiles/history/view/history_view_context_menu.h index 0861ebb27..814eb60e3 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.h +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.h @@ -60,6 +60,10 @@ void AddPollActions( not_null poll, not_null item, Context context); +void AddSaveSoundForNotifications( + not_null menu, + not_null document, + not_null controller); void AddWhoReactedAction( not_null menu, not_null context, diff --git a/Telegram/SourceFiles/ui/menu_icons.style b/Telegram/SourceFiles/ui/menu_icons.style index fc8f15fc3..3636500ee 100644 --- a/Telegram/SourceFiles/ui/menu_icons.style +++ b/Telegram/SourceFiles/ui/menu_icons.style @@ -108,6 +108,7 @@ menuIconCustomize: icon {{ "menu/customize", menuIconColor }}; menuIconSoundOn: icon {{ "menu/sound_enable", menuIconColor }}; menuIconSoundOff: icon {{ "menu/sound_disable", menuIconColor }}; menuIconSoundSelect: icon {{ "menu/sound_select", menuIconColor }}; +menuIconSoundAdd: icon {{ "menu/sound_add", menuIconColor }}; menuIconFile: icon {{ "menu/file", menuIconColor }}; menuIconPhoto: icon {{ "menu/image", menuIconColor }};