2
0
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:
John Preston
2022-04-07 11:34:29 +04:00
parent f5164fe3e4
commit d35b8f82a3
7 changed files with 107 additions and 23 deletions

View File

@@ -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({});

View File

@@ -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(