mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-31 12:14:34 +00:00
Added ability to save audio from chat as custom notification sound.
This commit is contained in:
parent
41784eb56a
commit
7b307a9e54
BIN
Telegram/Resources/icons/menu/sound_add.png
Normal file
BIN
Telegram/Resources/icons/menu/sound_add.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 675 B |
BIN
Telegram/Resources/icons/menu/sound_add@2x.png
Normal file
BIN
Telegram/Resources/icons/menu/sound_add@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
Telegram/Resources/icons/menu/sound_add@3x.png
Normal file
BIN
Telegram/Resources/icons/menu/sound_add@3x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
@ -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
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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<Ui::PopupMenu*> menu,
|
||||
not_null<DocumentData*> document,
|
||||
not_null<Window::SessionController*> 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<Ui::PopupMenu*> menu,
|
||||
not_null<QWidget*> context,
|
||||
|
@ -60,6 +60,10 @@ void AddPollActions(
|
||||
not_null<PollData*> poll,
|
||||
not_null<HistoryItem*> item,
|
||||
Context context);
|
||||
void AddSaveSoundForNotifications(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
not_null<DocumentData*> document,
|
||||
not_null<Window::SessionController*> controller);
|
||||
void AddWhoReactedAction(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
not_null<QWidget*> context,
|
||||
|
@ -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 }};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user