mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Slightly optimized name of methods in data notify settings.
This commit is contained in:
parent
c04a0e42a7
commit
9950452e57
13 changed files with 60 additions and 75 deletions
|
@ -1908,7 +1908,7 @@ void Updates::feedUpdate(const MTPUpdate &update) {
|
|||
|
||||
case mtpc_updateNotifySettings: {
|
||||
auto &d = update.c_updateNotifySettings();
|
||||
session().data().notifySettings().applyNotifySetting(
|
||||
session().data().notifySettings().apply(
|
||||
d.vpeer(),
|
||||
d.vnotify_settings());
|
||||
} break;
|
||||
|
|
|
@ -2095,20 +2095,20 @@ void ApiWrap::applyNotifySettings(
|
|||
auto ¬ifySettings = _session->data().notifySettings();
|
||||
switch (notifyPeer.type()) {
|
||||
case mtpc_inputNotifyUsers:
|
||||
notifySettings.applyNotifySetting(MTP_notifyUsers(), settings);
|
||||
notifySettings.apply(MTP_notifyUsers(), settings);
|
||||
break;
|
||||
case mtpc_inputNotifyChats:
|
||||
notifySettings.applyNotifySetting(MTP_notifyChats(), settings);
|
||||
notifySettings.apply(MTP_notifyChats(), settings);
|
||||
break;
|
||||
case mtpc_inputNotifyBroadcasts:
|
||||
notifySettings.applyNotifySetting(
|
||||
notifySettings.apply(
|
||||
MTP_notifyBroadcasts(),
|
||||
settings);
|
||||
break;
|
||||
case mtpc_inputNotifyPeer: {
|
||||
auto &peer = notifyPeer.c_inputNotifyPeer().vpeer();
|
||||
const auto apply = [&](PeerId peerId) {
|
||||
notifySettings.applyNotifySetting(
|
||||
notifySettings.apply(
|
||||
MTP_notifyPeer(peerToMTP(peerId)),
|
||||
settings);
|
||||
};
|
||||
|
|
|
@ -76,9 +76,7 @@ void MuteSettingsBox::prepare() {
|
|||
|
||||
_save = [=] {
|
||||
const auto muteForSeconds = group->value() * 3600;
|
||||
_peer->owner().notifySettings().updateNotifySettings(
|
||||
_peer,
|
||||
muteForSeconds);
|
||||
_peer->owner().notifySettings().update(_peer, muteForSeconds);
|
||||
closeBox();
|
||||
};
|
||||
addButton(tr::lng_box_ok(), _save);
|
||||
|
|
|
@ -222,11 +222,7 @@ void RingtonesBox(
|
|||
: (value == kNoSoundValue)
|
||||
? Data::NotifySound{ .none = true }
|
||||
: Data::NotifySound{ .id = state->documentIds[value] };
|
||||
peer->owner().notifySettings().updateNotifySettings(
|
||||
peer,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
sound);
|
||||
peer->owner().notifySettings().update(peer, {}, {}, sound);
|
||||
box->closeBox();
|
||||
});
|
||||
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||
|
|
|
@ -33,7 +33,7 @@ NotifySettings::NotifySettings(not_null<Session*> owner)
|
|||
, _unmuteByFinishedTimer([=] { unmuteByFinished(); }) {
|
||||
}
|
||||
|
||||
void NotifySettings::requestNotifySettings(not_null<PeerData*> peer) {
|
||||
void NotifySettings::request(not_null<PeerData*> peer) {
|
||||
if (peer->notifySettingsUnknown()) {
|
||||
peer->session().api().requestNotifySettings(
|
||||
MTP_inputNotifyPeer(peer->input));
|
||||
|
@ -47,7 +47,7 @@ void NotifySettings::requestNotifySettings(not_null<PeerData*> peer) {
|
|||
}
|
||||
}
|
||||
|
||||
void NotifySettings::applyNotifySetting(
|
||||
void NotifySettings::apply(
|
||||
const MTPNotifyPeer ¬ifyPeer,
|
||||
const MTPPeerNotifySettings &settings) {
|
||||
const auto goodForUpdate = [&](
|
||||
|
@ -61,34 +61,34 @@ void NotifySettings::applyNotifySetting(
|
|||
|
||||
switch (notifyPeer.type()) {
|
||||
case mtpc_notifyUsers: {
|
||||
if (_defaultUserNotifySettings.change(settings)) {
|
||||
_defaultUserNotifyUpdates.fire({});
|
||||
if (_defaultUser.change(settings)) {
|
||||
_defaultUserUpdates.fire({});
|
||||
|
||||
_owner->enumerateUsers([&](not_null<UserData*> user) {
|
||||
if (goodForUpdate(user, _defaultUserNotifySettings)) {
|
||||
updateNotifySettingsLocal(user);
|
||||
if (goodForUpdate(user, _defaultUser)) {
|
||||
updateLocal(user);
|
||||
}
|
||||
});
|
||||
}
|
||||
} break;
|
||||
case mtpc_notifyChats: {
|
||||
if (_defaultChatNotifySettings.change(settings)) {
|
||||
_defaultChatNotifyUpdates.fire({});
|
||||
if (_defaultChat.change(settings)) {
|
||||
_defaultChatUpdates.fire({});
|
||||
|
||||
_owner->enumerateGroups([&](not_null<PeerData*> peer) {
|
||||
if (goodForUpdate(peer, _defaultChatNotifySettings)) {
|
||||
updateNotifySettingsLocal(peer);
|
||||
if (goodForUpdate(peer, _defaultChat)) {
|
||||
updateLocal(peer);
|
||||
}
|
||||
});
|
||||
}
|
||||
} break;
|
||||
case mtpc_notifyBroadcasts: {
|
||||
if (_defaultBroadcastNotifySettings.change(settings)) {
|
||||
_defaultBroadcastNotifyUpdates.fire({});
|
||||
if (_defaultBroadcast.change(settings)) {
|
||||
_defaultBroadcastUpdates.fire({});
|
||||
|
||||
_owner->enumerateChannels([&](not_null<ChannelData*> channel) {
|
||||
if (goodForUpdate(channel, _defaultBroadcastNotifySettings)) {
|
||||
updateNotifySettingsLocal(channel);
|
||||
if (goodForUpdate(channel, _defaultBroadcast)) {
|
||||
updateLocal(channel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -97,25 +97,25 @@ void NotifySettings::applyNotifySetting(
|
|||
const auto &data = notifyPeer.c_notifyPeer();
|
||||
if (const auto peer = _owner->peerLoaded(peerFromMTP(data.vpeer()))) {
|
||||
if (peer->notifyChange(settings)) {
|
||||
updateNotifySettingsLocal(peer);
|
||||
updateLocal(peer);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void NotifySettings::updateNotifySettings(
|
||||
void NotifySettings::update(
|
||||
not_null<PeerData*> peer,
|
||||
std::optional<int> muteForSeconds,
|
||||
std::optional<bool> silentPosts,
|
||||
std::optional<NotifySound> sound) {
|
||||
if (peer->notifyChange(muteForSeconds, silentPosts, sound)) {
|
||||
updateNotifySettingsLocal(peer);
|
||||
updateLocal(peer);
|
||||
peer->session().api().updateNotifySettingsDelayed(peer);
|
||||
}
|
||||
}
|
||||
|
||||
void NotifySettings::resetNotifySettingsToDefault(not_null<PeerData*> peer) {
|
||||
void NotifySettings::resetToDefault(not_null<PeerData*> peer) {
|
||||
const auto empty = MTP_peerNotifySettings(
|
||||
MTP_flags(0),
|
||||
MTPBool(),
|
||||
|
@ -125,7 +125,7 @@ void NotifySettings::resetNotifySettingsToDefault(not_null<PeerData*> peer) {
|
|||
MTPNotificationSound(),
|
||||
MTPNotificationSound());
|
||||
if (peer->notifyChange(empty)) {
|
||||
updateNotifySettingsLocal(peer);
|
||||
updateLocal(peer);
|
||||
peer->session().api().updateNotifySettingsDelayed(peer);
|
||||
}
|
||||
}
|
||||
|
@ -133,13 +133,13 @@ void NotifySettings::resetNotifySettingsToDefault(not_null<PeerData*> peer) {
|
|||
const PeerNotifySettings &NotifySettings::defaultNotifySettings(
|
||||
not_null<const PeerData*> peer) const {
|
||||
return peer->isUser()
|
||||
? _defaultUserNotifySettings
|
||||
? _defaultUser
|
||||
: (peer->isChat() || peer->isMegagroup())
|
||||
? _defaultChatNotifySettings
|
||||
: _defaultBroadcastNotifySettings;
|
||||
? _defaultChat
|
||||
: _defaultBroadcast;
|
||||
}
|
||||
|
||||
void NotifySettings::updateNotifySettingsLocal(not_null<PeerData*> peer) {
|
||||
void NotifySettings::updateLocal(not_null<PeerData*> peer) {
|
||||
const auto history = _owner->historyLoaded(peer->id);
|
||||
auto changesIn = crl::time(0);
|
||||
const auto muted = isMuted(peer, &changesIn);
|
||||
|
@ -281,15 +281,15 @@ bool NotifySettings::settingsUnknown(not_null<const PeerData*> peer) const {
|
|||
}
|
||||
|
||||
rpl::producer<> NotifySettings::defaultUserNotifyUpdates() const {
|
||||
return _defaultUserNotifyUpdates.events();
|
||||
return _defaultUserUpdates.events();
|
||||
}
|
||||
|
||||
rpl::producer<> NotifySettings::defaultChatNotifyUpdates() const {
|
||||
return _defaultChatNotifyUpdates.events();
|
||||
return _defaultChatUpdates.events();
|
||||
}
|
||||
|
||||
rpl::producer<> NotifySettings::defaultBroadcastNotifyUpdates() const {
|
||||
return _defaultBroadcastNotifyUpdates.events();
|
||||
return _defaultBroadcastUpdates.events();
|
||||
}
|
||||
|
||||
rpl::producer<> NotifySettings::defaultNotifyUpdates(
|
||||
|
|
|
@ -21,16 +21,16 @@ class NotifySettings final {
|
|||
public:
|
||||
NotifySettings(not_null<Session*> owner);
|
||||
|
||||
void requestNotifySettings(not_null<PeerData*> peer);
|
||||
void applyNotifySetting(
|
||||
void request(not_null<PeerData*> peer);
|
||||
void apply(
|
||||
const MTPNotifyPeer ¬ifyPeer,
|
||||
const MTPPeerNotifySettings &settings);
|
||||
void updateNotifySettings(
|
||||
void update(
|
||||
not_null<PeerData*> peer,
|
||||
std::optional<int> muteForSeconds,
|
||||
std::optional<bool> silentPosts = std::nullopt,
|
||||
std::optional<NotifySound> sound = std::nullopt);
|
||||
void resetNotifySettingsToDefault(not_null<PeerData*> peer);
|
||||
void resetToDefault(not_null<PeerData*> peer);
|
||||
|
||||
[[nodiscard]] rpl::producer<> defaultUserNotifyUpdates() const;
|
||||
[[nodiscard]] rpl::producer<> defaultChatNotifyUpdates() const;
|
||||
|
@ -57,16 +57,16 @@ private:
|
|||
|
||||
void unmuteByFinished();
|
||||
void unmuteByFinishedDelayed(crl::time delay);
|
||||
void updateNotifySettingsLocal(not_null<PeerData*> peer);
|
||||
void updateLocal(not_null<PeerData*> peer);
|
||||
|
||||
const not_null<Session*> _owner;
|
||||
|
||||
PeerNotifySettings _defaultUserNotifySettings;
|
||||
PeerNotifySettings _defaultChatNotifySettings;
|
||||
PeerNotifySettings _defaultBroadcastNotifySettings;
|
||||
rpl::event_stream<> _defaultUserNotifyUpdates;
|
||||
rpl::event_stream<> _defaultChatNotifyUpdates;
|
||||
rpl::event_stream<> _defaultBroadcastNotifyUpdates;
|
||||
PeerNotifySettings _defaultUser;
|
||||
PeerNotifySettings _defaultChat;
|
||||
PeerNotifySettings _defaultBroadcast;
|
||||
rpl::event_stream<> _defaultUserUpdates;
|
||||
rpl::event_stream<> _defaultChatUpdates;
|
||||
rpl::event_stream<> _defaultBroadcastUpdates;
|
||||
std::unordered_set<not_null<const PeerData*>> _mutedPeers;
|
||||
base::Timer _unmuteByFinishedTimer;
|
||||
|
||||
|
|
|
@ -2554,7 +2554,7 @@ void History::applyDialog(
|
|||
}
|
||||
}
|
||||
}
|
||||
owner().notifySettings().applyNotifySetting(
|
||||
owner().notifySettings().apply(
|
||||
MTP_notifyPeer(data.vpeer()),
|
||||
data.vnotify_settings());
|
||||
|
||||
|
|
|
@ -2238,7 +2238,7 @@ void HistoryWidget::showHistory(
|
|||
|
||||
if (_peer->isChannel()) {
|
||||
updateNotifyControls();
|
||||
session().data().notifySettings().requestNotifySettings(_peer);
|
||||
session().data().notifySettings().request(_peer);
|
||||
refreshSilentToggle();
|
||||
} else if (_peer->isRepliesChat()) {
|
||||
updateNotifyControls();
|
||||
|
@ -3852,9 +3852,7 @@ void HistoryWidget::toggleMuteUnmute() {
|
|||
const auto muteForSeconds = _history->mute()
|
||||
? 0
|
||||
: Data::PeerNotifySettings::kDefaultMutePeriod;
|
||||
session().data().notifySettings().updateNotifySettings(
|
||||
_peer,
|
||||
muteForSeconds);
|
||||
session().data().notifySettings().update(_peer, muteForSeconds);
|
||||
}
|
||||
|
||||
void HistoryWidget::reportSelectedMessages() {
|
||||
|
|
|
@ -474,7 +474,7 @@ void ContactStatus::setupUnarchiveHandler(not_null<PeerData*> peer) {
|
|||
_bar.entity()->unarchiveClicks(
|
||||
) | rpl::start_with_next([=] {
|
||||
Window::ToggleHistoryArchived(peer->owner().history(peer), false);
|
||||
peer->owner().notifySettings().resetNotifySettingsToDefault(peer);
|
||||
peer->owner().notifySettings().resetToDefault(peer);
|
||||
if (const auto settings = peer->settings()) {
|
||||
const auto flags = PeerSetting::AutoArchived
|
||||
| PeerSetting::BlockContact
|
||||
|
|
|
@ -112,7 +112,7 @@ MuteItem::MuteItem(
|
|||
}, lifetime());
|
||||
|
||||
setClickedCallback([=] {
|
||||
peer->owner().notifySettings().updateNotifySettings(
|
||||
peer->owner().notifySettings().update(
|
||||
peer,
|
||||
_isMuted ? 0 : Data::PeerNotifySettings::kDefaultMutePeriod);
|
||||
});
|
||||
|
@ -154,9 +154,7 @@ void MuteBox(not_null<Ui::GenericBox*> box, not_null<PeerData*> peer) {
|
|||
: tr::lng_mute_menu_mute();
|
||||
}) | rpl::flatten_latest();
|
||||
const auto confirm = box->addButton(std::move(confirmText), [=] {
|
||||
peer->owner().notifySettings().updateNotifySettings(
|
||||
peer,
|
||||
state->lastSeconds);
|
||||
peer->owner().notifySettings().update(peer, state->lastSeconds);
|
||||
box->getDelegate()->hideLayer();
|
||||
});
|
||||
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||
|
@ -194,7 +192,7 @@ void PickMuteBox(not_null<Ui::GenericBox*> box, not_null<PeerData*> peer) {
|
|||
|
||||
box->addButton(tr::lng_mute_menu_mute(), [=] {
|
||||
const auto muteFor = pickerCallback();
|
||||
peer->owner().notifySettings().updateNotifySettings(peer, muteFor);
|
||||
peer->owner().notifySettings().update(peer, muteFor);
|
||||
peer->session().settings().addMutePeriod(muteFor);
|
||||
peer->session().saveSettings();
|
||||
box->closeBox();
|
||||
|
@ -245,7 +243,7 @@ void FillMuteMenu(
|
|||
auto ¬ifySettings = peer->owner().notifySettings();
|
||||
auto sound = notifySettings.sound(peer);
|
||||
sound.none = !sound.none;
|
||||
notifySettings.updateNotifySettings(peer, {}, {}, sound);
|
||||
notifySettings.update(peer, {}, {}, sound);
|
||||
},
|
||||
soundIsNone ? &st::menuIconSoundOn : &st::menuIconSoundOff);
|
||||
|
||||
|
@ -254,9 +252,7 @@ void FillMuteMenu(
|
|||
+ st::menuIconMuteForAnyTextPosition;
|
||||
for (const auto &muteFor : peer->session().settings().mutePeriods()) {
|
||||
const auto callback = [=] {
|
||||
peer->owner().notifySettings().updateNotifySettings(
|
||||
peer,
|
||||
muteFor);
|
||||
peer->owner().notifySettings().update(peer, muteFor);
|
||||
};
|
||||
|
||||
auto item = base::make_unique_q<IconWithText>(
|
||||
|
|
|
@ -865,10 +865,7 @@ void SilentToggle::mouseReleaseEvent(QMouseEvent *e) {
|
|||
setChecked(!_checked);
|
||||
RippleButton::mouseReleaseEvent(e);
|
||||
Ui::Tooltip::Show(0, this);
|
||||
_channel->owner().notifySettings().updateNotifySettings(
|
||||
_channel,
|
||||
std::nullopt,
|
||||
_checked);
|
||||
_channel->owner().notifySettings().update(_channel, {}, _checked);
|
||||
}
|
||||
|
||||
QString SilentToggle::tooltipText() const {
|
||||
|
|
|
@ -198,13 +198,13 @@ System::SkipState System::computeSkipState(
|
|||
}
|
||||
|
||||
if (messageNotification) {
|
||||
history->owner().notifySettings().requestNotifySettings(
|
||||
history->owner().notifySettings().request(
|
||||
history->peer);
|
||||
} else if (notifyBy->blockStatus() == PeerData::BlockStatus::Unknown) {
|
||||
notifyBy->updateFull();
|
||||
}
|
||||
if (notifyBy) {
|
||||
history->owner().notifySettings().requestNotifySettings(notifyBy);
|
||||
history->owner().notifySettings().request(notifyBy);
|
||||
}
|
||||
|
||||
if (messageNotification
|
||||
|
|
|
@ -131,7 +131,7 @@ void PeerMenuAddMuteSubmenuAction(
|
|||
not_null<Window::SessionController*> controller,
|
||||
not_null<PeerData*> peer,
|
||||
const PeerMenuCallback &addAction) {
|
||||
peer->owner().notifySettings().requestNotifySettings(peer);
|
||||
peer->owner().notifySettings().request(peer);
|
||||
const auto isMuted = peer->owner().notifySettings().isMuted(peer);
|
||||
if (isMuted) {
|
||||
const auto text = tr::lng_context_unmute(tr::now)
|
||||
|
@ -139,7 +139,7 @@ void PeerMenuAddMuteSubmenuAction(
|
|||
+ Ui::FormatMuteForTiny(peer->notifyMuteUntil().value_or(0)
|
||||
- base::unixtime::now());
|
||||
addAction(text, [=] {
|
||||
peer->owner().notifySettings().updateNotifySettings(peer, 0);
|
||||
peer->owner().notifySettings().update(peer, 0);
|
||||
}, &st::menuIconUnmute);
|
||||
} else {
|
||||
const auto show = std::make_shared<Window::Show>(controller);
|
||||
|
@ -1426,7 +1426,7 @@ void PeerMenuAddMuteAction(
|
|||
not_null<PeerData*> peer,
|
||||
const PeerMenuCallback &addAction) {
|
||||
// There is no async to make weak from controller.
|
||||
peer->owner().notifySettings().requestNotifySettings(peer);
|
||||
peer->owner().notifySettings().request(peer);
|
||||
const auto muteText = [](bool isUnmuted) {
|
||||
return isUnmuted
|
||||
? tr::lng_context_mute(tr::now)
|
||||
|
@ -1438,7 +1438,7 @@ void PeerMenuAddMuteAction(
|
|||
Box<MuteSettingsBox>(peer),
|
||||
Ui::LayerOption::CloseOther);
|
||||
} else {
|
||||
peer->owner().notifySettings().updateNotifySettings(peer, 0);
|
||||
peer->owner().notifySettings().update(peer, 0);
|
||||
}
|
||||
}, (peer->owner().notifySettings().isMuted(peer)
|
||||
? &st::menuIconUnmute
|
||||
|
|
Loading…
Add table
Reference in a new issue