mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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(
|
bool notifyChange(
|
||||||
std::optional<int> muteForSeconds,
|
std::optional<int> muteForSeconds,
|
||||||
std::optional<bool> silentPosts,
|
std::optional<bool> silentPosts,
|
||||||
std::optional<bool> soundIsNone) {
|
std::optional<Data::NotifySound> sound) {
|
||||||
return _notify.change(muteForSeconds, silentPosts, soundIsNone);
|
return _notify.change(muteForSeconds, silentPosts, sound);
|
||||||
}
|
}
|
||||||
[[nodiscard]] bool notifySettingsUnknown() const {
|
[[nodiscard]] bool notifySettingsUnknown() const {
|
||||||
return _notify.settingsUnknown();
|
return _notify.settingsUnknown();
|
||||||
|
@ -204,8 +204,8 @@ public:
|
||||||
[[nodiscard]] std::optional<bool> notifySilentPosts() const {
|
[[nodiscard]] std::optional<bool> notifySilentPosts() const {
|
||||||
return _notify.silentPosts();
|
return _notify.silentPosts();
|
||||||
}
|
}
|
||||||
[[nodiscard]] std::optional<bool> notifySoundIsNone() const {
|
[[nodiscard]] std::optional<Data::NotifySound> notifySound() const {
|
||||||
return _notify.soundIsNone();
|
return _notify.sound();
|
||||||
}
|
}
|
||||||
[[nodiscard]] MTPinputPeerNotifySettings notifySerialize() const {
|
[[nodiscard]] MTPinputPeerNotifySettings notifySerialize() const {
|
||||||
return _notify.serialize();
|
return _notify.serialize();
|
||||||
|
|
|
@ -56,7 +56,7 @@ void NotifySettings::applyNotifySetting(
|
||||||
return !peer->notifySettingsUnknown()
|
return !peer->notifySettingsUnknown()
|
||||||
&& ((!peer->notifyMuteUntil() && settings.muteUntil())
|
&& ((!peer->notifyMuteUntil() && settings.muteUntil())
|
||||||
|| (!peer->notifySilentPosts() && settings.silentPosts())
|
|| (!peer->notifySilentPosts() && settings.silentPosts())
|
||||||
|| (!peer->notifySoundIsNone() && settings.soundIsNone()));
|
|| (!peer->notifySound() && settings.sound()));
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (notifyPeer.type()) {
|
switch (notifyPeer.type()) {
|
||||||
|
@ -108,8 +108,8 @@ void NotifySettings::updateNotifySettings(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
std::optional<int> muteForSeconds,
|
std::optional<int> muteForSeconds,
|
||||||
std::optional<bool> silentPosts,
|
std::optional<bool> silentPosts,
|
||||||
std::optional<bool> soundIsNone) {
|
std::optional<NotifySound> sound) {
|
||||||
if (peer->notifyChange(muteForSeconds, silentPosts, soundIsNone)) {
|
if (peer->notifyChange(muteForSeconds, silentPosts, sound)) {
|
||||||
updateNotifySettingsLocal(peer);
|
updateNotifySettingsLocal(peer);
|
||||||
peer->session().api().updateNotifySettingsDelayed(peer);
|
peer->session().api().updateNotifySettingsDelayed(peer);
|
||||||
}
|
}
|
||||||
|
@ -234,15 +234,15 @@ bool NotifySettings::silentPosts(not_null<const PeerData*> peer) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotifySettings::soundIsNone(not_null<const PeerData*> peer) const {
|
NotifySound NotifySettings::sound(not_null<const PeerData*> peer) const {
|
||||||
if (const auto soundIsNone = peer->notifySoundIsNone()) {
|
if (const auto sound = peer->notifySound()) {
|
||||||
return *soundIsNone;
|
return *sound;
|
||||||
}
|
}
|
||||||
const auto &settings = defaultNotifySettings(peer);
|
const auto &settings = defaultNotifySettings(peer);
|
||||||
if (const auto soundIsNone = settings.soundIsNone()) {
|
if (const auto sound = settings.sound()) {
|
||||||
return *soundIsNone;
|
return *sound;
|
||||||
}
|
}
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotifySettings::muteUnknown(not_null<const PeerData*> peer) const {
|
bool NotifySettings::muteUnknown(not_null<const PeerData*> peer) const {
|
||||||
|
@ -264,11 +264,11 @@ bool NotifySettings::silentPostsUnknown(
|
||||||
return defaultNotifySettings(peer).settingsUnknown();
|
return defaultNotifySettings(peer).settingsUnknown();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotifySettings::soundIsNoneUnknown(
|
bool NotifySettings::soundUnknown(
|
||||||
not_null<const PeerData*> peer) const {
|
not_null<const PeerData*> peer) const {
|
||||||
if (peer->notifySettingsUnknown()) {
|
if (peer->notifySettingsUnknown()) {
|
||||||
return true;
|
return true;
|
||||||
} else if (const auto nonDefault = peer->notifySoundIsNone()) {
|
} else if (const auto nonDefault = peer->notifySound()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return defaultNotifySettings(peer).settingsUnknown();
|
return defaultNotifySettings(peer).settingsUnknown();
|
||||||
|
@ -277,7 +277,7 @@ bool NotifySettings::soundIsNoneUnknown(
|
||||||
bool NotifySettings::settingsUnknown(not_null<const PeerData*> peer) const {
|
bool NotifySettings::settingsUnknown(not_null<const PeerData*> peer) const {
|
||||||
return muteUnknown(peer)
|
return muteUnknown(peer)
|
||||||
|| silentPostsUnknown(peer)
|
|| silentPostsUnknown(peer)
|
||||||
|| soundIsNoneUnknown(peer);
|
|| soundUnknown(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<> NotifySettings::defaultUserNotifyUpdates() const {
|
rpl::producer<> NotifySettings::defaultUserNotifyUpdates() const {
|
||||||
|
|
|
@ -29,7 +29,7 @@ public:
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
std::optional<int> muteForSeconds,
|
std::optional<int> muteForSeconds,
|
||||||
std::optional<bool> silentPosts = std::nullopt,
|
std::optional<bool> silentPosts = std::nullopt,
|
||||||
std::optional<bool> soundIsNone = std::nullopt);
|
std::optional<NotifySound> sound = std::nullopt);
|
||||||
void resetNotifySettingsToDefault(not_null<PeerData*> peer);
|
void resetNotifySettingsToDefault(not_null<PeerData*> peer);
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<> defaultUserNotifyUpdates() const;
|
[[nodiscard]] rpl::producer<> defaultUserNotifyUpdates() const;
|
||||||
|
@ -40,12 +40,11 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] bool isMuted(not_null<const PeerData*> peer) const;
|
[[nodiscard]] bool isMuted(not_null<const PeerData*> peer) const;
|
||||||
[[nodiscard]] bool silentPosts(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 muteUnknown(not_null<const PeerData*> peer) const;
|
||||||
[[nodiscard]] bool silentPostsUnknown(
|
[[nodiscard]] bool silentPostsUnknown(
|
||||||
not_null<const PeerData*> peer) const;
|
not_null<const PeerData*> peer) const;
|
||||||
[[nodiscard]] bool soundIsNoneUnknown(
|
[[nodiscard]] bool soundUnknown(not_null<const PeerData*> peer) const;
|
||||||
not_null<const PeerData*> peer) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]] bool isMuted(
|
[[nodiscard]] bool isMuted(
|
||||||
|
|
|
@ -199,19 +199,16 @@ bool PeerNotifySettings::change(const MTPPeerNotifySettings &settings) {
|
||||||
bool PeerNotifySettings::change(
|
bool PeerNotifySettings::change(
|
||||||
std::optional<int> muteForSeconds,
|
std::optional<int> muteForSeconds,
|
||||||
std::optional<bool> silentPosts,
|
std::optional<bool> silentPosts,
|
||||||
std::optional<bool> soundIsNone) {
|
std::optional<NotifySound> sound) {
|
||||||
const auto notificationSound = soundIsNone
|
if (!muteForSeconds && !silentPosts && !sound) {
|
||||||
? std::make_optional(NotifySound{ .none = (*soundIsNone) })
|
|
||||||
: std::nullopt;
|
|
||||||
if (!muteForSeconds && !silentPosts && !soundIsNone) {
|
|
||||||
return false;
|
return false;
|
||||||
} else if (_value) {
|
} else if (_value) {
|
||||||
return _value->change(muteForSeconds, silentPosts, notificationSound);
|
return _value->change(muteForSeconds, silentPosts, sound);
|
||||||
}
|
}
|
||||||
using Flag = MTPDpeerNotifySettings::Flag;
|
using Flag = MTPDpeerNotifySettings::Flag;
|
||||||
const auto flags = (muteForSeconds ? Flag::f_mute_until : Flag(0))
|
const auto flags = (muteForSeconds ? Flag::f_mute_until : Flag(0))
|
||||||
| (silentPosts ? Flag::f_silent : 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
|
const auto muteUntil = muteForSeconds
|
||||||
? (base::unixtime::now() + *muteForSeconds)
|
? (base::unixtime::now() + *muteForSeconds)
|
||||||
: 0;
|
: 0;
|
||||||
|
@ -222,7 +219,7 @@ bool PeerNotifySettings::change(
|
||||||
MTP_int(muteUntil),
|
MTP_int(muteUntil),
|
||||||
MTPNotificationSound(),
|
MTPNotificationSound(),
|
||||||
MTPNotificationSound(),
|
MTPNotificationSound(),
|
||||||
SerializeSound(notificationSound)));
|
SerializeSound(sound)));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<TimeId> PeerNotifySettings::muteUntil() const {
|
std::optional<TimeId> PeerNotifySettings::muteUntil() const {
|
||||||
|
@ -241,10 +238,10 @@ std::optional<bool> PeerNotifySettings::silentPosts() const {
|
||||||
: std::nullopt;
|
: std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<bool> PeerNotifySettings::soundIsNone() const {
|
std::optional<NotifySound> PeerNotifySettings::sound() const {
|
||||||
return (!_value || !_value->sound())
|
return _value
|
||||||
? std::nullopt
|
? _value->sound()
|
||||||
: std::make_optional(_value->sound()->none);
|
: std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
MTPinputPeerNotifySettings PeerNotifySettings::serialize() const {
|
MTPinputPeerNotifySettings PeerNotifySettings::serialize() const {
|
||||||
|
|
|
@ -35,12 +35,12 @@ public:
|
||||||
bool change(
|
bool change(
|
||||||
std::optional<int> muteForSeconds,
|
std::optional<int> muteForSeconds,
|
||||||
std::optional<bool> silentPosts,
|
std::optional<bool> silentPosts,
|
||||||
std::optional<bool> soundIsNone);
|
std::optional<NotifySound> sound);
|
||||||
|
|
||||||
bool settingsUnknown() const;
|
bool settingsUnknown() const;
|
||||||
std::optional<TimeId> muteUntil() const;
|
std::optional<TimeId> muteUntil() const;
|
||||||
std::optional<bool> silentPosts() const;
|
std::optional<bool> silentPosts() const;
|
||||||
std::optional<bool> soundIsNone() const;
|
std::optional<NotifySound> sound() const;
|
||||||
MTPinputPeerNotifySettings serialize() const;
|
MTPinputPeerNotifySettings serialize() const;
|
||||||
|
|
||||||
~PeerNotifySettings();
|
~PeerNotifySettings();
|
||||||
|
|
|
@ -230,15 +230,16 @@ void FillMuteMenu(
|
||||||
Args args) {
|
Args args) {
|
||||||
const auto peer = args.peer;
|
const auto peer = args.peer;
|
||||||
|
|
||||||
const auto soundIsNone = peer->owner().notifySettings().soundIsNone(peer);
|
const auto soundIsNone = peer->owner().notifySettings().sound(peer).none;
|
||||||
menu->addAction(
|
menu->addAction(
|
||||||
soundIsNone
|
soundIsNone
|
||||||
? tr::lng_mute_menu_sound_on(tr::now)
|
? tr::lng_mute_menu_sound_on(tr::now)
|
||||||
: tr::lng_mute_menu_sound_off(tr::now),
|
: tr::lng_mute_menu_sound_off(tr::now),
|
||||||
[=] {
|
[=] {
|
||||||
auto ¬ifySettings = peer->owner().notifySettings();
|
auto ¬ifySettings = peer->owner().notifySettings();
|
||||||
const auto soundIsNone = notifySettings.soundIsNone(peer);
|
auto sound = notifySettings.sound(peer);
|
||||||
notifySettings.updateNotifySettings(peer, {}, {}, !soundIsNone);
|
sound.none = !sound.none;
|
||||||
|
notifySettings.updateNotifySettings(peer, {}, {}, sound);
|
||||||
},
|
},
|
||||||
soundIsNone ? &st::menuIconSoundOn : &st::menuIconSoundOff);
|
soundIsNone ? &st::menuIconSoundOn : &st::menuIconSoundOff);
|
||||||
|
|
||||||
|
|
|
@ -180,8 +180,8 @@ System::SkipState System::computeSkipState(
|
||||||
.silent = (forceSilent
|
.silent = (forceSilent
|
||||||
|| !messageNotification
|
|| !messageNotification
|
||||||
|| item->isSilent()
|
|| item->isSilent()
|
||||||
|| history->owner().notifySettings().soundIsNone(
|
|| history->owner().notifySettings().sound(
|
||||||
history->peer)),
|
history->peer).none),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
const auto showForMuted = messageNotification
|
const auto showForMuted = messageNotification
|
||||||
|
|
|
@ -146,7 +146,7 @@ void PeerMenuAddMuteSubmenuAction(
|
||||||
addAction(PeerMenuCallback::Args{
|
addAction(PeerMenuCallback::Args{
|
||||||
.text = tr::lng_context_mute(tr::now),
|
.text = tr::lng_context_mute(tr::now),
|
||||||
.handler = nullptr,
|
.handler = nullptr,
|
||||||
.icon = peer->owner().notifySettings().soundIsNone(peer)
|
.icon = peer->owner().notifySettings().sound(peer).none
|
||||||
? &st::menuIconSilent
|
? &st::menuIconSilent
|
||||||
: &st::menuIconMute,
|
: &st::menuIconMute,
|
||||||
.fillSubmenu = [=](not_null<Ui::PopupMenu*> menu) {
|
.fillSubmenu = [=](not_null<Ui::PopupMenu*> menu) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue