mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-04-01 14:50:24 +00:00
Fix custom notification sounds for all chats.
This commit is contained in:
parent
e3f65d2346
commit
8b89cfc4cb
Telegram/SourceFiles/data/notify
@ -161,25 +161,7 @@ void NotifySettings::updateLocal(not_null<PeerData*> peer) {
|
||||
} else {
|
||||
_mutedPeers.erase(peer);
|
||||
}
|
||||
|
||||
if (const auto sound = peer->notifySound(); sound && sound->id) {
|
||||
if (const auto doc = _owner->document(sound->id); !doc->isNull()) {
|
||||
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)) {
|
||||
cacheSound(id);
|
||||
}
|
||||
_ringtones.pendingLifetime.destroy();
|
||||
}, _ringtones.pendingLifetime);
|
||||
_owner->session().api().ringtones().requestList();
|
||||
}
|
||||
}
|
||||
}
|
||||
cacheSound(peer->notifySound());
|
||||
}
|
||||
|
||||
void NotifySettings::cacheSound(DocumentId id) {
|
||||
@ -196,6 +178,28 @@ void NotifySettings::cacheSound(not_null<DocumentData*> document) {
|
||||
document->save(Data::FileOriginRingtones(), QString());
|
||||
}
|
||||
|
||||
void NotifySettings::cacheSound(const std::optional<NotifySound> &sound) {
|
||||
if (!sound || !sound->id) {
|
||||
return;
|
||||
} else if (const auto doc = _owner->document(sound->id); !doc->isNull()) {
|
||||
cacheSound(doc);
|
||||
return;
|
||||
}
|
||||
_ringtones.pendingIds.push_back(sound->id);
|
||||
if (_ringtones.pendingLifetime) {
|
||||
return;
|
||||
}
|
||||
// Not requested yet.
|
||||
_owner->session().api().ringtones().listUpdates(
|
||||
) | rpl::start_with_next([=] {
|
||||
for (const auto id : base::take(_ringtones.pendingIds)) {
|
||||
cacheSound(id);
|
||||
}
|
||||
_ringtones.pendingLifetime.destroy();
|
||||
}, _ringtones.pendingLifetime);
|
||||
_owner->session().api().ringtones().requestList();
|
||||
}
|
||||
|
||||
void NotifySettings::updateLocal(DefaultNotify type) {
|
||||
defaultValue(type).updates.fire({});
|
||||
|
||||
@ -220,6 +224,7 @@ void NotifySettings::updateLocal(DefaultNotify type) {
|
||||
_owner->enumerateBroadcasts(callback);
|
||||
break;
|
||||
}
|
||||
cacheSound(defaultValue(type).settings.sound());
|
||||
}
|
||||
|
||||
std::shared_ptr<DocumentMedia> NotifySettings::lookupRingtone(
|
||||
|
@ -71,6 +71,8 @@ private:
|
||||
rpl::event_stream<> updates;
|
||||
};
|
||||
|
||||
void cacheSound(const std::optional<NotifySound> &sound);
|
||||
|
||||
[[nodiscard]] bool isMuted(
|
||||
not_null<const PeerData*> peer,
|
||||
crl::time *changesIn) const;
|
||||
|
Loading…
Reference in New Issue
Block a user