mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Fix ringtones downloaded to disk.
This commit is contained in:
parent
6adb3e7200
commit
7d678e5fa7
1 changed files with 29 additions and 8 deletions
|
@ -88,6 +88,25 @@ constexpr auto kSystemAlertDuration = crl::time(0);
|
|||
return text;
|
||||
}
|
||||
|
||||
[[nodiscard]] QByteArray ReadRingtoneBytes(
|
||||
const std::shared_ptr<Data::DocumentMedia> &media) {
|
||||
const auto result = media->bytes();
|
||||
if (!result.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
const auto &location = media->owner()->location();
|
||||
if (!location.isEmpty() && location.accessEnable()) {
|
||||
const auto guard = gsl::finally([&] {
|
||||
location.accessDisable();
|
||||
});
|
||||
auto f = QFile(location.name());
|
||||
if (f.open(QIODevice::ReadOnly)) {
|
||||
return f.readAll();
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const char kOptionGNotification[] = "gnotification";
|
||||
|
@ -801,14 +820,16 @@ not_null<Media::Audio::Track*> System::lookupSound(
|
|||
return i->second.get();
|
||||
}
|
||||
const auto ¬ifySettings = owner->notifySettings();
|
||||
const auto custom = notifySettings.lookupRingtone(id);
|
||||
if (custom && !custom->bytes().isEmpty()) {
|
||||
const auto j = _customSoundTracks.emplace(
|
||||
id,
|
||||
Media::Audio::Current().createTrack()
|
||||
).first;
|
||||
j->second->fillFromData(bytes::make_vector(custom->bytes()));
|
||||
return j->second.get();
|
||||
if (const auto custom = notifySettings.lookupRingtone(id)) {
|
||||
const auto bytes = ReadRingtoneBytes(custom);
|
||||
if (!bytes.isEmpty()) {
|
||||
const auto j = _customSoundTracks.emplace(
|
||||
id,
|
||||
Media::Audio::Current().createTrack()
|
||||
).first;
|
||||
j->second->fillFromData(bytes::make_vector(bytes));
|
||||
return j->second.get();
|
||||
}
|
||||
}
|
||||
ensureSoundCreated();
|
||||
return _soundTrack.get();
|
||||
|
|
Loading…
Add table
Reference in a new issue