mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
Added public api for sound configuration to data notify settings.
This commit is contained in:
@@ -195,8 +195,8 @@ public:
|
||||
bool notifyChange(
|
||||
std::optional<int> muteForSeconds,
|
||||
std::optional<bool> silentPosts,
|
||||
std::optional<bool> soundIsNone) {
|
||||
return _notify.change(muteForSeconds, silentPosts, soundIsNone);
|
||||
std::optional<Data::NotifySound> sound) {
|
||||
return _notify.change(muteForSeconds, silentPosts, sound);
|
||||
}
|
||||
[[nodiscard]] bool notifySettingsUnknown() const {
|
||||
return _notify.settingsUnknown();
|
||||
@@ -204,8 +204,8 @@ public:
|
||||
[[nodiscard]] std::optional<bool> notifySilentPosts() const {
|
||||
return _notify.silentPosts();
|
||||
}
|
||||
[[nodiscard]] std::optional<bool> notifySoundIsNone() const {
|
||||
return _notify.soundIsNone();
|
||||
[[nodiscard]] std::optional<Data::NotifySound> notifySound() const {
|
||||
return _notify.sound();
|
||||
}
|
||||
[[nodiscard]] MTPinputPeerNotifySettings notifySerialize() const {
|
||||
return _notify.serialize();
|
||||
|
@@ -56,7 +56,7 @@ void NotifySettings::applyNotifySetting(
|
||||
return !peer->notifySettingsUnknown()
|
||||
&& ((!peer->notifyMuteUntil() && settings.muteUntil())
|
||||
|| (!peer->notifySilentPosts() && settings.silentPosts())
|
||||
|| (!peer->notifySoundIsNone() && settings.soundIsNone()));
|
||||
|| (!peer->notifySound() && settings.sound()));
|
||||
};
|
||||
|
||||
switch (notifyPeer.type()) {
|
||||
@@ -108,8 +108,8 @@ void NotifySettings::updateNotifySettings(
|
||||
not_null<PeerData*> peer,
|
||||
std::optional<int> muteForSeconds,
|
||||
std::optional<bool> silentPosts,
|
||||
std::optional<bool> soundIsNone) {
|
||||
if (peer->notifyChange(muteForSeconds, silentPosts, soundIsNone)) {
|
||||
std::optional<NotifySound> sound) {
|
||||
if (peer->notifyChange(muteForSeconds, silentPosts, sound)) {
|
||||
updateNotifySettingsLocal(peer);
|
||||
peer->session().api().updateNotifySettingsDelayed(peer);
|
||||
}
|
||||
@@ -234,15 +234,15 @@ bool NotifySettings::silentPosts(not_null<const PeerData*> peer) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NotifySettings::soundIsNone(not_null<const PeerData*> peer) const {
|
||||
if (const auto soundIsNone = peer->notifySoundIsNone()) {
|
||||
return *soundIsNone;
|
||||
NotifySound NotifySettings::sound(not_null<const PeerData*> peer) const {
|
||||
if (const auto sound = peer->notifySound()) {
|
||||
return *sound;
|
||||
}
|
||||
const auto &settings = defaultNotifySettings(peer);
|
||||
if (const auto soundIsNone = settings.soundIsNone()) {
|
||||
return *soundIsNone;
|
||||
if (const auto sound = settings.sound()) {
|
||||
return *sound;
|
||||
}
|
||||
return false;
|
||||
return {};
|
||||
}
|
||||
|
||||
bool NotifySettings::muteUnknown(not_null<const PeerData*> peer) const {
|
||||
@@ -264,11 +264,11 @@ bool NotifySettings::silentPostsUnknown(
|
||||
return defaultNotifySettings(peer).settingsUnknown();
|
||||
}
|
||||
|
||||
bool NotifySettings::soundIsNoneUnknown(
|
||||
bool NotifySettings::soundUnknown(
|
||||
not_null<const PeerData*> peer) const {
|
||||
if (peer->notifySettingsUnknown()) {
|
||||
return true;
|
||||
} else if (const auto nonDefault = peer->notifySoundIsNone()) {
|
||||
} else if (const auto nonDefault = peer->notifySound()) {
|
||||
return false;
|
||||
}
|
||||
return defaultNotifySettings(peer).settingsUnknown();
|
||||
@@ -277,7 +277,7 @@ bool NotifySettings::soundIsNoneUnknown(
|
||||
bool NotifySettings::settingsUnknown(not_null<const PeerData*> peer) const {
|
||||
return muteUnknown(peer)
|
||||
|| silentPostsUnknown(peer)
|
||||
|| soundIsNoneUnknown(peer);
|
||||
|| soundUnknown(peer);
|
||||
}
|
||||
|
||||
rpl::producer<> NotifySettings::defaultUserNotifyUpdates() const {
|
||||
|
@@ -29,7 +29,7 @@ public:
|
||||
not_null<PeerData*> peer,
|
||||
std::optional<int> muteForSeconds,
|
||||
std::optional<bool> silentPosts = std::nullopt,
|
||||
std::optional<bool> soundIsNone = std::nullopt);
|
||||
std::optional<NotifySound> sound = std::nullopt);
|
||||
void resetNotifySettingsToDefault(not_null<PeerData*> peer);
|
||||
|
||||
[[nodiscard]] rpl::producer<> defaultUserNotifyUpdates() const;
|
||||
@@ -40,12 +40,11 @@ public:
|
||||
|
||||
[[nodiscard]] bool isMuted(not_null<const PeerData*> peer) const;
|
||||
[[nodiscard]] bool silentPosts(not_null<const PeerData*> peer) const;
|
||||
[[nodiscard]] bool soundIsNone(not_null<const PeerData*> peer) const;
|
||||
[[nodiscard]] NotifySound sound(not_null<const PeerData*> peer) const;
|
||||
[[nodiscard]] bool muteUnknown(not_null<const PeerData*> peer) const;
|
||||
[[nodiscard]] bool silentPostsUnknown(
|
||||
not_null<const PeerData*> peer) const;
|
||||
[[nodiscard]] bool soundIsNoneUnknown(
|
||||
not_null<const PeerData*> peer) const;
|
||||
[[nodiscard]] bool soundUnknown(not_null<const PeerData*> peer) const;
|
||||
|
||||
private:
|
||||
[[nodiscard]] bool isMuted(
|
||||
|
@@ -199,19 +199,16 @@ bool PeerNotifySettings::change(const MTPPeerNotifySettings &settings) {
|
||||
bool PeerNotifySettings::change(
|
||||
std::optional<int> muteForSeconds,
|
||||
std::optional<bool> silentPosts,
|
||||
std::optional<bool> soundIsNone) {
|
||||
const auto notificationSound = soundIsNone
|
||||
? std::make_optional(NotifySound{ .none = (*soundIsNone) })
|
||||
: std::nullopt;
|
||||
if (!muteForSeconds && !silentPosts && !soundIsNone) {
|
||||
std::optional<NotifySound> sound) {
|
||||
if (!muteForSeconds && !silentPosts && !sound) {
|
||||
return false;
|
||||
} else if (_value) {
|
||||
return _value->change(muteForSeconds, silentPosts, notificationSound);
|
||||
return _value->change(muteForSeconds, silentPosts, sound);
|
||||
}
|
||||
using Flag = MTPDpeerNotifySettings::Flag;
|
||||
const auto flags = (muteForSeconds ? Flag::f_mute_until : Flag(0))
|
||||
| (silentPosts ? Flag::f_silent : Flag(0))
|
||||
| (notificationSound ? Flag::f_other_sound : Flag(0));
|
||||
| (sound ? Flag::f_other_sound : Flag(0));
|
||||
const auto muteUntil = muteForSeconds
|
||||
? (base::unixtime::now() + *muteForSeconds)
|
||||
: 0;
|
||||
@@ -222,7 +219,7 @@ bool PeerNotifySettings::change(
|
||||
MTP_int(muteUntil),
|
||||
MTPNotificationSound(),
|
||||
MTPNotificationSound(),
|
||||
SerializeSound(notificationSound)));
|
||||
SerializeSound(sound)));
|
||||
}
|
||||
|
||||
std::optional<TimeId> PeerNotifySettings::muteUntil() const {
|
||||
@@ -241,10 +238,10 @@ std::optional<bool> PeerNotifySettings::silentPosts() const {
|
||||
: std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<bool> PeerNotifySettings::soundIsNone() const {
|
||||
return (!_value || !_value->sound())
|
||||
? std::nullopt
|
||||
: std::make_optional(_value->sound()->none);
|
||||
std::optional<NotifySound> PeerNotifySettings::sound() const {
|
||||
return _value
|
||||
? _value->sound()
|
||||
: std::nullopt;
|
||||
}
|
||||
|
||||
MTPinputPeerNotifySettings PeerNotifySettings::serialize() const {
|
||||
|
@@ -35,12 +35,12 @@ public:
|
||||
bool change(
|
||||
std::optional<int> muteForSeconds,
|
||||
std::optional<bool> silentPosts,
|
||||
std::optional<bool> soundIsNone);
|
||||
std::optional<NotifySound> sound);
|
||||
|
||||
bool settingsUnknown() const;
|
||||
std::optional<TimeId> muteUntil() const;
|
||||
std::optional<bool> silentPosts() const;
|
||||
std::optional<bool> soundIsNone() const;
|
||||
std::optional<NotifySound> sound() const;
|
||||
MTPinputPeerNotifySettings serialize() const;
|
||||
|
||||
~PeerNotifySettings();
|
||||
|
Reference in New Issue
Block a user