mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 22:55:11 +00:00
Play ringtones on click in select box.
This commit is contained in:
@@ -163,24 +163,16 @@ void NotifySettings::updateLocal(not_null<PeerData*> peer) {
|
||||
}
|
||||
|
||||
if (const auto sound = peer->notifySound(); sound && sound->id) {
|
||||
const auto cache = [=](DocumentId id) {
|
||||
if (const auto document = _owner->document(id)) {
|
||||
const auto view = document->createMediaView();
|
||||
_ringtones.views.emplace(id, view);
|
||||
document->forceToCache(true);
|
||||
document->save(Data::FileOriginRingtones(), QString());
|
||||
}
|
||||
};
|
||||
if (const auto doc = _owner->document(sound->id); !doc->isNull()) {
|
||||
cache(sound->id);
|
||||
cacheSound(doc);
|
||||
} else {
|
||||
_ringtones.pendingIds.push_back(sound->id);
|
||||
if (!_ringtones.pendingLifetime) {
|
||||
// Not requested yet.
|
||||
_owner->session().api().ringtones().listUpdates(
|
||||
) | rpl::start_with_next([=] {
|
||||
for (const auto &id : base::take(_ringtones.pendingIds)) {
|
||||
cache(id);
|
||||
for (const auto id : base::take(_ringtones.pendingIds)) {
|
||||
cacheSound(id);
|
||||
}
|
||||
_ringtones.pendingLifetime.destroy();
|
||||
}, _ringtones.pendingLifetime);
|
||||
@@ -190,6 +182,20 @@ void NotifySettings::updateLocal(not_null<PeerData*> peer) {
|
||||
}
|
||||
}
|
||||
|
||||
void NotifySettings::cacheSound(DocumentId id) {
|
||||
cacheSound(_owner->document(id));
|
||||
}
|
||||
|
||||
void NotifySettings::cacheSound(not_null<DocumentData*> document) {
|
||||
if (document->isNull()) {
|
||||
return;
|
||||
}
|
||||
const auto view = document->createMediaView();
|
||||
_ringtones.views.emplace(document->id, view);
|
||||
document->forceToCache(true);
|
||||
document->save(Data::FileOriginRingtones(), QString());
|
||||
}
|
||||
|
||||
void NotifySettings::updateLocal(DefaultNotify type) {
|
||||
defaultValue(type).updates.fire({});
|
||||
|
||||
|
@@ -39,7 +39,10 @@ public:
|
||||
std::optional<NotifySound> sound = std::nullopt);
|
||||
void resetToDefault(not_null<PeerData*> peer);
|
||||
|
||||
std::shared_ptr<DocumentMedia> lookupRingtone(DocumentId id) const;
|
||||
void cacheSound(DocumentId id);
|
||||
void cacheSound(not_null<DocumentData*> document);
|
||||
[[nodiscard]] std::shared_ptr<DocumentMedia> lookupRingtone(
|
||||
DocumentId id) const;
|
||||
|
||||
[[nodiscard]] rpl::producer<> defaultUpdates(DefaultNotify type) const;
|
||||
[[nodiscard]] rpl::producer<> defaultUpdates(
|
||||
|
Reference in New Issue
Block a user