mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-04 13:27:50 +00:00
Replaced hardcoded limitations for ringtones with server values.
This commit is contained in:
parent
7eacd26d70
commit
a49eda44d9
@ -3133,8 +3133,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
"lng_ringtones_box_about" = "Click on any short voice note or mp3 file in chat and select \"Save for Notifications\". It will appear here.";
|
||||
"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!";
|
||||
"lng_ringtones_error_max_size" = "Sorry, but your file is too big. The maximum size for ringtones is {size}.";
|
||||
"lng_ringtones_error_max_duration" = "Sorry, but your file is too long. The maximum duration for ringtones is {duration}.";
|
||||
|
||||
// Wnd specific
|
||||
|
||||
|
@ -16,6 +16,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_file_origin.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/notify/data_notify_settings.h"
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_app_config.h"
|
||||
#include "main/main_session.h"
|
||||
#include "storage/file_upload.h"
|
||||
#include "storage/localimageloader.h"
|
||||
@ -190,4 +192,22 @@ void Ringtones::remove(DocumentId id) {
|
||||
}
|
||||
}
|
||||
|
||||
int Ringtones::maxSize() const {
|
||||
return int(base::SafeRound(_session->account().appConfig().get<double>(
|
||||
"ringtone_size_max",
|
||||
100 * 1024)));
|
||||
}
|
||||
|
||||
int Ringtones::maxSavedCount() const {
|
||||
return int(base::SafeRound(_session->account().appConfig().get<double>(
|
||||
"ringtone_saved_count_max",
|
||||
100)));
|
||||
}
|
||||
|
||||
int Ringtones::maxDuration() const {
|
||||
return int(base::SafeRound(_session->account().appConfig().get<double>(
|
||||
"ringtone_duration_max",
|
||||
5)));
|
||||
}
|
||||
|
||||
} // namespace Api
|
||||
|
@ -38,6 +38,10 @@ public:
|
||||
[[nodiscard]] rpl::producer<QString> uploadFails() const;
|
||||
[[nodiscard]] rpl::producer<DocumentId> uploadDones() const;
|
||||
|
||||
[[nodiscard]] int maxSize() const;
|
||||
[[nodiscard]] int maxSavedCount() const;
|
||||
[[nodiscard]] int maxDuration() const;
|
||||
|
||||
private:
|
||||
struct UploadedData {
|
||||
QString filename;
|
||||
|
@ -12,11 +12,11 @@ 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 "base/timer_rpl.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "core/application.h"
|
||||
#include "core/file_utilities.h"
|
||||
#include "core/mime_type.h"
|
||||
#include "core/application.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_document_media.h"
|
||||
#include "data/data_document_resolver.h"
|
||||
@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "media/audio/media_audio.h"
|
||||
#include "settings/settings_common.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
@ -195,10 +196,20 @@ void RingtonesBox(
|
||||
|
||||
session->api().ringtones().uploadFails(
|
||||
) | rpl::start_with_next([=](const QString &error) {
|
||||
if ((error == u"RINGTONE_DURATION_TOO_LONG"_q)
|
||||
|| (error == u"RINGTONE_SIZE_TOO_BIG"_q)) {
|
||||
box->getDelegate()->show(
|
||||
Ui::MakeInformBox(tr::lng_ringtones_box_error()));
|
||||
if ((error == u"RINGTONE_DURATION_TOO_LONG"_q)) {
|
||||
box->getDelegate()->show(Ui::MakeInformBox(
|
||||
tr::lng_ringtones_error_max_duration(
|
||||
tr::now,
|
||||
lt_duration,
|
||||
Ui::FormatMuteFor(
|
||||
session->api().ringtones().maxDuration()))));
|
||||
} else if ((error == u"RINGTONE_SIZE_TOO_BIG"_q)) {
|
||||
box->getDelegate()->show(Ui::MakeInformBox(
|
||||
tr::lng_ringtones_error_max_size(
|
||||
tr::now,
|
||||
lt_size,
|
||||
Ui::FormatSizeText(
|
||||
session->api().ringtones().maxSize()))));
|
||||
} else if (error == u"RINGTONE_MIME_INVALID"_q) {
|
||||
box->getDelegate()->show(
|
||||
Ui::MakeInformBox(tr::lng_edit_media_invalid_file()));
|
||||
@ -291,6 +302,15 @@ void RingtonesBox(
|
||||
mime = Core::MimeTypeForData(content).name();
|
||||
name = "audio";
|
||||
}
|
||||
const auto &ringtones = session->api().ringtones();
|
||||
if (int(content.size()) > ringtones.maxSize()) {
|
||||
box->getDelegate()->show(Ui::MakeInformBox(
|
||||
tr::lng_ringtones_error_max_size(
|
||||
tr::now,
|
||||
lt_size,
|
||||
Ui::FormatSizeText(ringtones.maxSize()))));
|
||||
return;
|
||||
}
|
||||
|
||||
session->api().ringtones().upload(name, mime, content);
|
||||
};
|
||||
|
@ -69,8 +69,6 @@ namespace HistoryView {
|
||||
namespace {
|
||||
|
||||
constexpr auto kRescheduleLimit = 20;
|
||||
constexpr auto kMaxDurationForRingtone = 10;
|
||||
constexpr auto kMaxSizeForRingtone = 1024 * 500;
|
||||
|
||||
bool HasEditMessageAction(
|
||||
const ContextMenuRequest &request,
|
||||
@ -1083,16 +1081,18 @@ void AddSaveSoundForNotifications(
|
||||
not_null<DocumentData*> document,
|
||||
not_null<Window::SessionController*> controller) {
|
||||
const auto &ringtones = document->session().api().ringtones();
|
||||
if (document->size > kMaxSizeForRingtone) {
|
||||
if (document->size > ringtones.maxSize()) {
|
||||
return;
|
||||
} else if (ranges::contains(ringtones.list(), document->id)) {
|
||||
return;
|
||||
} else if (int(ringtones.list().size()) >= ringtones.maxSavedCount()) {
|
||||
return;
|
||||
} else if (const auto song = document->song()) {
|
||||
if (song->duration > kMaxDurationForRingtone) {
|
||||
if (song->duration > ringtones.maxDuration()) {
|
||||
return;
|
||||
}
|
||||
} else if (const auto voice = document->voice()) {
|
||||
if (voice->duration > kMaxDurationForRingtone) {
|
||||
if (voice->duration > ringtones.maxDuration()) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user