mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 15:17:07 +02:00
Added support of sound notification setting to Data::Session.
This commit is contained in:
parent
93d4581443
commit
f32215f77d
6 changed files with 81 additions and 20 deletions
Telegram/SourceFiles
|
@ -60,10 +60,12 @@ public:
|
|||
bool change(const MTPDpeerNotifySettings &data);
|
||||
bool change(
|
||||
std::optional<int> muteForSeconds,
|
||||
std::optional<bool> silentPosts);
|
||||
std::optional<bool> silentPosts,
|
||||
std::optional<NotifySound> sound);
|
||||
|
||||
std::optional<TimeId> muteUntil() const;
|
||||
std::optional<bool> silentPosts() const;
|
||||
std::optional<NotifySound> sound() const;
|
||||
MTPinputPeerNotifySettings serialize() const;
|
||||
|
||||
private:
|
||||
|
@ -101,7 +103,8 @@ bool NotifySettingsValue::change(const MTPDpeerNotifySettings &data) {
|
|||
|
||||
bool NotifySettingsValue::change(
|
||||
std::optional<int> muteForSeconds,
|
||||
std::optional<bool> silentPosts) {
|
||||
std::optional<bool> silentPosts,
|
||||
std::optional<NotifySound> sound) {
|
||||
const auto now = base::unixtime::now();
|
||||
const auto notMuted = muteForSeconds
|
||||
? !(*muteForSeconds)
|
||||
|
@ -114,9 +117,12 @@ bool NotifySettingsValue::change(
|
|||
const auto newSilentPosts = silentPosts
|
||||
? base::make_optional(*silentPosts)
|
||||
: _silent;
|
||||
const auto newSound = sound
|
||||
? base::make_optional(*sound)
|
||||
: _sound;
|
||||
return change(
|
||||
newMute,
|
||||
_sound,
|
||||
newSound,
|
||||
_showPreviews,
|
||||
newSilentPosts);
|
||||
}
|
||||
|
@ -147,6 +153,10 @@ std::optional<bool> NotifySettingsValue::silentPosts() const {
|
|||
return _silent;
|
||||
}
|
||||
|
||||
std::optional<NotifySound> NotifySettingsValue::sound() const {
|
||||
return _sound;
|
||||
}
|
||||
|
||||
MTPinputPeerNotifySettings NotifySettingsValue::serialize() const {
|
||||
using Flag = MTPDinputPeerNotifySettings::Flag;
|
||||
const auto flag = [](auto &&optional, Flag flag) {
|
||||
|
@ -188,15 +198,20 @@ bool NotifySettings::change(const MTPPeerNotifySettings &settings) {
|
|||
|
||||
bool NotifySettings::change(
|
||||
std::optional<int> muteForSeconds,
|
||||
std::optional<bool> silentPosts) {
|
||||
if (!muteForSeconds && !silentPosts) {
|
||||
std::optional<bool> silentPosts,
|
||||
std::optional<bool> soundIsNone) {
|
||||
const auto notificationSound = soundIsNone
|
||||
? std::make_optional(NotifySound{ .none = (*soundIsNone) })
|
||||
: std::nullopt;
|
||||
if (!muteForSeconds && !silentPosts && !soundIsNone) {
|
||||
return false;
|
||||
} else if (_value) {
|
||||
return _value->change(muteForSeconds, silentPosts);
|
||||
return _value->change(muteForSeconds, silentPosts, notificationSound);
|
||||
}
|
||||
using Flag = MTPDpeerNotifySettings::Flag;
|
||||
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));
|
||||
const auto muteUntil = muteForSeconds
|
||||
? (base::unixtime::now() + *muteForSeconds)
|
||||
: 0;
|
||||
|
@ -207,7 +222,7 @@ bool NotifySettings::change(
|
|||
MTP_int(muteUntil),
|
||||
MTPNotificationSound(),
|
||||
MTPNotificationSound(),
|
||||
MTPNotificationSound()));
|
||||
SerializeSound(notificationSound)));
|
||||
}
|
||||
|
||||
std::optional<TimeId> NotifySettings::muteUntil() const {
|
||||
|
@ -226,6 +241,12 @@ std::optional<bool> NotifySettings::silentPosts() const {
|
|||
: std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<bool> NotifySettings::soundIsNone() const {
|
||||
return (!_value || !_value->sound())
|
||||
? std::nullopt
|
||||
: std::make_optional(_value->sound()->none);
|
||||
}
|
||||
|
||||
MTPinputPeerNotifySettings NotifySettings::serialize() const {
|
||||
return _value
|
||||
? _value->serialize()
|
||||
|
|
|
@ -34,11 +34,13 @@ public:
|
|||
bool change(const MTPPeerNotifySettings &settings);
|
||||
bool change(
|
||||
std::optional<int> muteForSeconds,
|
||||
std::optional<bool> silentPosts);
|
||||
std::optional<bool> silentPosts,
|
||||
std::optional<bool> soundIsNone);
|
||||
|
||||
bool settingsUnknown() const;
|
||||
std::optional<TimeId> muteUntil() const;
|
||||
std::optional<bool> silentPosts() const;
|
||||
std::optional<bool> soundIsNone() const;
|
||||
MTPinputPeerNotifySettings serialize() const;
|
||||
|
||||
~NotifySettings();
|
||||
|
|
|
@ -194,8 +194,9 @@ public:
|
|||
}
|
||||
bool notifyChange(
|
||||
std::optional<int> muteForSeconds,
|
||||
std::optional<bool> silentPosts) {
|
||||
return _notify.change(muteForSeconds, silentPosts);
|
||||
std::optional<bool> silentPosts,
|
||||
std::optional<bool> soundIsNone) {
|
||||
return _notify.change(muteForSeconds, silentPosts, soundIsNone);
|
||||
}
|
||||
[[nodiscard]] bool notifySettingsUnknown() const {
|
||||
return _notify.settingsUnknown();
|
||||
|
@ -203,6 +204,9 @@ public:
|
|||
[[nodiscard]] std::optional<bool> notifySilentPosts() const {
|
||||
return _notify.silentPosts();
|
||||
}
|
||||
[[nodiscard]] std::optional<bool> notifySoundIsNone() const {
|
||||
return _notify.soundIsNone();
|
||||
}
|
||||
[[nodiscard]] MTPinputPeerNotifySettings notifySerialize() const {
|
||||
return _notify.serialize();
|
||||
}
|
||||
|
|
|
@ -3896,7 +3896,8 @@ void Session::applyNotifySetting(
|
|||
const NotifySettings &settings) {
|
||||
return !peer->notifySettingsUnknown()
|
||||
&& ((!peer->notifyMuteUntil() && settings.muteUntil())
|
||||
|| (!peer->notifySilentPosts() && settings.silentPosts()));
|
||||
|| (!peer->notifySilentPosts() && settings.silentPosts())
|
||||
|| (!peer->notifySoundIsNone() && settings.soundIsNone()));
|
||||
};
|
||||
|
||||
switch (notifyPeer.type()) {
|
||||
|
@ -3947,8 +3948,9 @@ void Session::applyNotifySetting(
|
|||
void Session::updateNotifySettings(
|
||||
not_null<PeerData*> peer,
|
||||
std::optional<int> muteForSeconds,
|
||||
std::optional<bool> silentPosts) {
|
||||
if (peer->notifyChange(muteForSeconds, silentPosts)) {
|
||||
std::optional<bool> silentPosts,
|
||||
std::optional<bool> soundIsNone) {
|
||||
if (peer->notifyChange(muteForSeconds, silentPosts, soundIsNone)) {
|
||||
updateNotifySettingsLocal(peer);
|
||||
_session->api().updateNotifySettingsDelayed(peer);
|
||||
}
|
||||
|
@ -3969,6 +3971,10 @@ void Session::resetNotifySettingsToDefault(not_null<PeerData*> peer) {
|
|||
}
|
||||
}
|
||||
|
||||
bool Session::notifyIsMuted(not_null<const PeerData*> peer) const {
|
||||
return notifyIsMuted(peer, nullptr);
|
||||
}
|
||||
|
||||
bool Session::notifyIsMuted(
|
||||
not_null<const PeerData*> peer,
|
||||
crl::time *changesIn) const {
|
||||
|
@ -4003,6 +4009,17 @@ bool Session::notifySilentPosts(not_null<const PeerData*> peer) const {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Session::notifySoundIsNone(not_null<const PeerData*> peer) const {
|
||||
if (const auto soundIsNone = peer->notifySoundIsNone()) {
|
||||
return *soundIsNone;
|
||||
}
|
||||
const auto &settings = defaultNotifySettings(peer);
|
||||
if (const auto soundIsNone = settings.soundIsNone()) {
|
||||
return *soundIsNone;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Session::notifyMuteUnknown(not_null<const PeerData*> peer) const {
|
||||
if (peer->notifySettingsUnknown()) {
|
||||
return true;
|
||||
|
@ -4022,8 +4039,19 @@ bool Session::notifySilentPostsUnknown(
|
|||
return defaultNotifySettings(peer).settingsUnknown();
|
||||
}
|
||||
|
||||
bool Session::notifySoundIsNoneUnknown(not_null<const PeerData*> peer) const {
|
||||
if (peer->notifySettingsUnknown()) {
|
||||
return true;
|
||||
} else if (const auto nonDefault = peer->notifySoundIsNone()) {
|
||||
return false;
|
||||
}
|
||||
return defaultNotifySettings(peer).settingsUnknown();
|
||||
}
|
||||
|
||||
bool Session::notifySettingsUnknown(not_null<const PeerData*> peer) const {
|
||||
return notifyMuteUnknown(peer) || notifySilentPostsUnknown(peer);
|
||||
return notifyMuteUnknown(peer)
|
||||
|| notifySilentPostsUnknown(peer)
|
||||
|| notifySoundIsNoneUnknown(peer);
|
||||
}
|
||||
|
||||
rpl::producer<> Session::defaultUserNotifyUpdates() const {
|
||||
|
|
|
@ -666,14 +666,15 @@ public:
|
|||
void updateNotifySettings(
|
||||
not_null<PeerData*> peer,
|
||||
std::optional<int> muteForSeconds,
|
||||
std::optional<bool> silentPosts = std::nullopt);
|
||||
std::optional<bool> silentPosts = std::nullopt,
|
||||
std::optional<bool> soundIsNone = std::nullopt);
|
||||
void resetNotifySettingsToDefault(not_null<PeerData*> peer);
|
||||
bool notifyIsMuted(
|
||||
not_null<const PeerData*> peer,
|
||||
crl::time *changesIn = nullptr) const;
|
||||
bool notifyIsMuted(not_null<const PeerData*> peer) const;
|
||||
bool notifySilentPosts(not_null<const PeerData*> peer) const;
|
||||
bool notifySoundIsNone(not_null<const PeerData*> peer) const;
|
||||
bool notifyMuteUnknown(not_null<const PeerData*> peer) const;
|
||||
bool notifySilentPostsUnknown(not_null<const PeerData*> peer) const;
|
||||
bool notifySoundIsNoneUnknown(not_null<const PeerData*> peer) const;
|
||||
bool notifySettingsUnknown(not_null<const PeerData*> peer) const;
|
||||
rpl::producer<> defaultUserNotifyUpdates() const;
|
||||
rpl::producer<> defaultChatNotifyUpdates() const;
|
||||
|
@ -711,6 +712,10 @@ public:
|
|||
private:
|
||||
using Messages = std::unordered_map<MsgId, not_null<HistoryItem*>>;
|
||||
|
||||
bool notifyIsMuted(
|
||||
not_null<const PeerData*> peer,
|
||||
crl::time *changesIn) const;
|
||||
|
||||
void suggestStartExport();
|
||||
|
||||
void setupMigrationViewer();
|
||||
|
|
|
@ -178,7 +178,8 @@ System::SkipState System::computeSkipState(
|
|||
.value = value,
|
||||
.silent = (forceSilent
|
||||
|| !messageNotification
|
||||
|| item->isSilent()),
|
||||
|| item->isSilent()
|
||||
|| history->owner().notifySoundIsNone(history->peer)),
|
||||
};
|
||||
};
|
||||
const auto showForMuted = messageNotification
|
||||
|
|
Loading…
Add table
Reference in a new issue