mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Added public api for sound configuration to data notify settings.
This commit is contained in:
parent
55864edb67
commit
a0b88e8f8b
8 changed files with 37 additions and 40 deletions
|
@ -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();
|
||||
|
|
|
@ -230,15 +230,16 @@ void FillMuteMenu(
|
|||
Args args) {
|
||||
const auto peer = args.peer;
|
||||
|
||||
const auto soundIsNone = peer->owner().notifySettings().soundIsNone(peer);
|
||||
const auto soundIsNone = peer->owner().notifySettings().sound(peer).none;
|
||||
menu->addAction(
|
||||
soundIsNone
|
||||
? tr::lng_mute_menu_sound_on(tr::now)
|
||||
: tr::lng_mute_menu_sound_off(tr::now),
|
||||
[=] {
|
||||
auto ¬ifySettings = peer->owner().notifySettings();
|
||||
const auto soundIsNone = notifySettings.soundIsNone(peer);
|
||||
notifySettings.updateNotifySettings(peer, {}, {}, !soundIsNone);
|
||||
auto sound = notifySettings.sound(peer);
|
||||
sound.none = !sound.none;
|
||||
notifySettings.updateNotifySettings(peer, {}, {}, sound);
|
||||
},
|
||||
soundIsNone ? &st::menuIconSoundOn : &st::menuIconSoundOff);
|
||||
|
||||
|
|
|
@ -180,8 +180,8 @@ System::SkipState System::computeSkipState(
|
|||
.silent = (forceSilent
|
||||
|| !messageNotification
|
||||
|| item->isSilent()
|
||||
|| history->owner().notifySettings().soundIsNone(
|
||||
history->peer)),
|
||||
|| history->owner().notifySettings().sound(
|
||||
history->peer).none),
|
||||
};
|
||||
};
|
||||
const auto showForMuted = messageNotification
|
||||
|
|
|
@ -146,7 +146,7 @@ void PeerMenuAddMuteSubmenuAction(
|
|||
addAction(PeerMenuCallback::Args{
|
||||
.text = tr::lng_context_mute(tr::now),
|
||||
.handler = nullptr,
|
||||
.icon = peer->owner().notifySettings().soundIsNone(peer)
|
||||
.icon = peer->owner().notifySettings().sound(peer).none
|
||||
? &st::menuIconSilent
|
||||
: &st::menuIconMute,
|
||||
.fillSubmenu = [=](not_null<Ui::PopupMenu*> menu) {
|
||||
|
|
Loading…
Add table
Reference in a new issue