mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Allow customizing default notifications.
This commit is contained in:
parent
b80f5f9706
commit
827e755552
5 changed files with 195 additions and 73 deletions
|
@ -289,6 +289,13 @@ const PeerNotifySettings &NotifySettings::defaultSettings(
|
||||||
return defaultValue(type).settings;
|
return defaultValue(type).settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NotifySettings::isMuted(DefaultNotify type) const {
|
||||||
|
if (const auto until = defaultSettings(type).muteUntil()) {
|
||||||
|
return MutedFromUntil(*until, nullptr);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void NotifySettings::defaultUpdate(
|
void NotifySettings::defaultUpdate(
|
||||||
DefaultNotify type,
|
DefaultNotify type,
|
||||||
MuteValue muteForSeconds,
|
MuteValue muteForSeconds,
|
||||||
|
|
|
@ -85,6 +85,7 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] const PeerNotifySettings &defaultSettings(
|
[[nodiscard]] const PeerNotifySettings &defaultSettings(
|
||||||
DefaultNotify type) const;
|
DefaultNotify type) const;
|
||||||
|
[[nodiscard]] bool isMuted(DefaultNotify type) const;
|
||||||
|
|
||||||
void defaultUpdate(
|
void defaultUpdate(
|
||||||
DefaultNotify type,
|
DefaultNotify type,
|
||||||
|
|
|
@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_thread.h"
|
#include "data/data_thread.h"
|
||||||
#include "data/notify/data_notify_settings.h"
|
#include "data/notify/data_notify_settings.h"
|
||||||
|
#include "data/notify/data_peer_notify_settings.h"
|
||||||
#include "info/profile/info_profile_values.h"
|
#include "info/profile/info_profile_values.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
@ -31,10 +32,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_menu_icons.h"
|
#include "styles/style_menu_icons.h"
|
||||||
|
|
||||||
namespace MuteMenu {
|
namespace MuteMenu {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto kMuteDurSecondsDefault = crl::time(8) * 3600;
|
constexpr auto kMuteDurSecondsDefault = crl::time(8) * 3600;
|
||||||
|
constexpr auto kMuteForeverValue = std::numeric_limits<TimeId>::max();
|
||||||
|
|
||||||
class IconWithText final : public Ui::Menu::Action {
|
class IconWithText final : public Ui::Menu::Action {
|
||||||
public:
|
public:
|
||||||
|
@ -70,7 +71,7 @@ public:
|
||||||
MuteItem(
|
MuteItem(
|
||||||
not_null<RpWidget*> parent,
|
not_null<RpWidget*> parent,
|
||||||
const style::Menu &st,
|
const style::Menu &st,
|
||||||
not_null<Data::Thread*> thread);
|
Descriptor descriptor);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
@ -79,31 +80,30 @@ private:
|
||||||
const QPoint _itemIconPosition;
|
const QPoint _itemIconPosition;
|
||||||
Ui::Animations::Simple _animation;
|
Ui::Animations::Simple _animation;
|
||||||
bool _isMuted = false;
|
bool _isMuted = false;
|
||||||
|
bool _inited;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MuteItem::MuteItem(
|
MuteItem::MuteItem(
|
||||||
not_null<RpWidget*> parent,
|
not_null<RpWidget*> parent,
|
||||||
const style::Menu &st,
|
const style::Menu &st,
|
||||||
not_null<Data::Thread*> thread)
|
Descriptor descriptor)
|
||||||
: Ui::Menu::Action(
|
: Ui::Menu::Action(
|
||||||
parent,
|
parent,
|
||||||
st,
|
st,
|
||||||
Ui::CreateChild<QAction>(parent.get()),
|
Ui::CreateChild<QAction>(parent.get()),
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr)
|
nullptr)
|
||||||
, _itemIconPosition(st.itemIconPosition)
|
, _itemIconPosition(st.itemIconPosition) {
|
||||||
, _isMuted(thread->owner().notifySettings().isMuted(thread)) {
|
descriptor.isMutedValue(
|
||||||
Info::Profile::NotificationsEnabledValue(
|
) | rpl::start_with_next([=](bool isMuted) {
|
||||||
thread
|
|
||||||
) | rpl::start_with_next([=](bool isUnmuted) {
|
|
||||||
const auto isMuted = !isUnmuted;
|
|
||||||
action()->setText(isMuted
|
action()->setText(isMuted
|
||||||
? tr::lng_mute_menu_duration_unmute(tr::now)
|
? tr::lng_mute_menu_duration_unmute(tr::now)
|
||||||
: tr::lng_mute_menu_duration_forever(tr::now));
|
: tr::lng_mute_menu_duration_forever(tr::now));
|
||||||
if (isMuted == _isMuted) {
|
if (_inited && isMuted == _isMuted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
_inited = true;
|
||||||
_isMuted = isMuted;
|
_isMuted = isMuted;
|
||||||
_animation.start(
|
_animation.start(
|
||||||
[=] { update(); },
|
[=] { update(); },
|
||||||
|
@ -112,13 +112,8 @@ MuteItem::MuteItem(
|
||||||
st::defaultPopupMenu.showDuration);
|
st::defaultPopupMenu.showDuration);
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
const auto weak = base::make_weak(thread);
|
|
||||||
setClickedCallback([=] {
|
setClickedCallback([=] {
|
||||||
if (const auto strong = weak.get()) {
|
descriptor.updateMutePeriod(_isMuted ? 0 : kMuteForeverValue);
|
||||||
strong->owner().notifySettings().update(
|
|
||||||
strong,
|
|
||||||
{ .unmute = _isMuted, .forever = !_isMuted });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +135,7 @@ void MuteItem::paintEvent(QPaintEvent *e) {
|
||||||
icon.paint(p, _itemIconPosition, width(), color);
|
icon.paint(p, _itemIconPosition, width(), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MuteBox(not_null<Ui::GenericBox*> box, not_null<Data::Thread*> thread) {
|
void MuteBox(not_null<Ui::GenericBox*> box, Descriptor descriptor) {
|
||||||
struct State {
|
struct State {
|
||||||
int lastSeconds = 0;
|
int lastSeconds = 0;
|
||||||
};
|
};
|
||||||
|
@ -161,14 +156,9 @@ void MuteBox(not_null<Ui::GenericBox*> box, not_null<Data::Thread*> thread) {
|
||||||
: tr::lng_mute_menu_mute();
|
: tr::lng_mute_menu_mute();
|
||||||
}) | rpl::flatten_latest();
|
}) | rpl::flatten_latest();
|
||||||
|
|
||||||
const auto weak = base::make_weak(thread);
|
|
||||||
Ui::ConfirmBox(box, {
|
Ui::ConfirmBox(box, {
|
||||||
.confirmed = [=] {
|
.confirmed = [=] {
|
||||||
if (const auto strong = weak.get()) {
|
descriptor.updateMutePeriod(state->lastSeconds);
|
||||||
strong->owner().notifySettings().update(
|
|
||||||
strong,
|
|
||||||
{ .period = state->lastSeconds });
|
|
||||||
}
|
|
||||||
box->getDelegate()->hideLayer();
|
box->getDelegate()->hideLayer();
|
||||||
},
|
},
|
||||||
.confirmText = std::move(confirmText),
|
.confirmText = std::move(confirmText),
|
||||||
|
@ -178,7 +168,7 @@ void MuteBox(not_null<Ui::GenericBox*> box, not_null<Data::Thread*> thread) {
|
||||||
|
|
||||||
void PickMuteBox(
|
void PickMuteBox(
|
||||||
not_null<Ui::GenericBox*> box,
|
not_null<Ui::GenericBox*> box,
|
||||||
not_null<Data::Thread*> thread) {
|
Descriptor descriptor) {
|
||||||
struct State {
|
struct State {
|
||||||
base::unique_qptr<Ui::PopupMenu> menu;
|
base::unique_qptr<Ui::PopupMenu> menu;
|
||||||
};
|
};
|
||||||
|
@ -191,17 +181,12 @@ void PickMuteBox(
|
||||||
|
|
||||||
const auto pickerCallback = TimePickerBox(box, seconds, phrases, 0);
|
const auto pickerCallback = TimePickerBox(box, seconds, phrases, 0);
|
||||||
|
|
||||||
const auto weak = base::make_weak(thread);
|
|
||||||
Ui::ConfirmBox(box, {
|
Ui::ConfirmBox(box, {
|
||||||
.confirmed = [=] {
|
.confirmed = [=] {
|
||||||
const auto muteFor = pickerCallback();
|
const auto muteFor = pickerCallback();
|
||||||
if (const auto strong = weak.get()) {
|
descriptor.updateMutePeriod(muteFor);
|
||||||
strong->owner().notifySettings().update(
|
descriptor.session->settings().addMutePeriod(muteFor);
|
||||||
strong,
|
descriptor.session->saveSettings();
|
||||||
{ .period = muteFor });
|
|
||||||
strong->session().settings().addMutePeriod(muteFor);
|
|
||||||
strong->session().saveSettings();
|
|
||||||
}
|
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
},
|
},
|
||||||
.confirmText = tr::lng_mute_menu_mute(),
|
.confirmText = tr::lng_mute_menu_mute(),
|
||||||
|
@ -220,11 +205,7 @@ void PickMuteBox(
|
||||||
st::popupMenuWithIcons);
|
st::popupMenuWithIcons);
|
||||||
state->menu->addAction(
|
state->menu->addAction(
|
||||||
tr::lng_manage_messages_ttl_after_custom(tr::now),
|
tr::lng_manage_messages_ttl_after_custom(tr::now),
|
||||||
[=] {
|
[=] { box->getDelegate()->show(Box(MuteBox, descriptor)); },
|
||||||
if (const auto strong = weak.get()) {
|
|
||||||
box->getDelegate()->show(Box(MuteBox, strong));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
&st::menuIconCustomize);
|
&st::menuIconCustomize);
|
||||||
state->menu->setDestroyedCallback(crl::guard(top, [=] {
|
state->menu->setDestroyedCallback(crl::guard(top, [=] {
|
||||||
top->setForceRippled(false);
|
top->setForceRippled(false);
|
||||||
|
@ -236,46 +217,124 @@ void PickMuteBox(
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
Descriptor ThreadDescriptor(not_null<Data::Thread*> thread) {
|
||||||
|
const auto weak = base::make_weak(thread);
|
||||||
|
const auto isMutedValue = [=]() -> rpl::producer<bool> {
|
||||||
|
if (const auto strong = weak.get()) {
|
||||||
|
return Info::Profile::NotificationsEnabledValue(
|
||||||
|
strong
|
||||||
|
) | rpl::map(!rpl::mappers::_1);
|
||||||
|
}
|
||||||
|
return rpl::single(false);
|
||||||
|
};
|
||||||
|
const auto currentSound = [=] {
|
||||||
|
const auto strong = weak.get();
|
||||||
|
return strong
|
||||||
|
? strong->owner().notifySettings().sound(strong)
|
||||||
|
: std::optional<Data::NotifySound>();
|
||||||
|
};
|
||||||
|
const auto updateSound = crl::guard(weak, [=](Data::NotifySound sound) {
|
||||||
|
thread->owner().notifySettings().update(thread, {}, {}, sound);
|
||||||
|
});
|
||||||
|
const auto updateMutePeriod = crl::guard(weak, [=](TimeId mute) {
|
||||||
|
const auto settings = &thread->owner().notifySettings();
|
||||||
|
if (!mute) {
|
||||||
|
settings->update(thread, { .unmute = true });
|
||||||
|
} else if (mute == kMuteForeverValue) {
|
||||||
|
settings->update(thread, { .forever = true });
|
||||||
|
} else {
|
||||||
|
settings->update(thread, { .period = mute });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
.session = &thread->session(),
|
||||||
|
.isMutedValue = isMutedValue,
|
||||||
|
.currentSound = currentSound,
|
||||||
|
.updateSound = updateSound,
|
||||||
|
.updateMutePeriod = updateMutePeriod,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Descriptor DefaultDescriptor(
|
||||||
|
not_null<Main::Session*> session,
|
||||||
|
Data::DefaultNotify type) {
|
||||||
|
const auto settings = &session->data().notifySettings();
|
||||||
|
const auto isMutedValue = [=]() -> rpl::producer<bool> {
|
||||||
|
return rpl::single(
|
||||||
|
rpl::empty
|
||||||
|
) | rpl::then(
|
||||||
|
settings->defaultUpdates(type)
|
||||||
|
) | rpl::map([=] {
|
||||||
|
return settings->isMuted(type);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const auto currentSound = [=] {
|
||||||
|
return settings->defaultSettings(type).sound();
|
||||||
|
};
|
||||||
|
const auto updateSound = [=](Data::NotifySound sound) {
|
||||||
|
settings->defaultUpdate(type, {}, {}, sound);
|
||||||
|
};
|
||||||
|
const auto updateMutePeriod = [=](TimeId mute) {
|
||||||
|
if (!mute) {
|
||||||
|
settings->defaultUpdate(type, { .unmute = true });
|
||||||
|
} else if (mute == kMuteForeverValue) {
|
||||||
|
settings->defaultUpdate(type, { .forever = true });
|
||||||
|
} else {
|
||||||
|
settings->defaultUpdate(type, { .period = mute });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
.session = session,
|
||||||
|
.isMutedValue = isMutedValue,
|
||||||
|
.currentSound = currentSound,
|
||||||
|
.updateSound = updateSound,
|
||||||
|
.updateMutePeriod = updateMutePeriod,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void FillMuteMenu(
|
void FillMuteMenu(
|
||||||
not_null<Ui::PopupMenu*> menu,
|
not_null<Ui::PopupMenu*> menu,
|
||||||
not_null<Data::Thread*> thread,
|
Descriptor descriptor,
|
||||||
std::shared_ptr<Ui::Show> show) {
|
std::shared_ptr<Ui::Show> show) {
|
||||||
const auto weak = base::make_weak(thread);
|
const auto session = descriptor.session;
|
||||||
const auto with = [=](Fn<void(not_null<Data::Thread*> thread)> handler) {
|
const auto soundSelect = [=] {
|
||||||
return [=] {
|
if (const auto currentSound = descriptor.currentSound()) {
|
||||||
if (const auto strong = weak.get()) {
|
show->showBox(Box(
|
||||||
handler(strong);
|
RingtonesBox,
|
||||||
}
|
session,
|
||||||
};
|
*currentSound,
|
||||||
|
descriptor.updateSound));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
menu->addAction(
|
menu->addAction(
|
||||||
tr::lng_mute_menu_sound_select(tr::now),
|
tr::lng_mute_menu_sound_select(tr::now),
|
||||||
with([=](not_null<Data::Thread*> thread) {
|
soundSelect,
|
||||||
show->showBox(Box(ThreadRingtonesBox, thread));
|
|
||||||
}),
|
|
||||||
&st::menuIconSoundSelect);
|
&st::menuIconSoundSelect);
|
||||||
|
|
||||||
const auto notifySettings = &thread->owner().notifySettings();
|
const auto notifySettings = &session->data().notifySettings();
|
||||||
const auto soundIsNone = notifySettings->sound(thread).none;
|
const auto soundIsNone = descriptor.currentSound().value_or(
|
||||||
|
Data::NotifySound()
|
||||||
|
).none;
|
||||||
|
const auto toggleSound = [=] {
|
||||||
|
if (auto sound = descriptor.currentSound()) {
|
||||||
|
sound->none = !soundIsNone;
|
||||||
|
descriptor.updateSound(*sound);
|
||||||
|
}
|
||||||
|
};
|
||||||
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)),
|
||||||
with([=](not_null<Data::Thread*> thread) {
|
toggleSound,
|
||||||
auto sound = notifySettings->sound(thread);
|
|
||||||
sound.none = !sound.none;
|
|
||||||
notifySettings->update(thread, {}, {}, sound);
|
|
||||||
}),
|
|
||||||
soundIsNone ? &st::menuIconSoundOn : &st::menuIconSoundOff);
|
soundIsNone ? &st::menuIconSoundOn : &st::menuIconSoundOff);
|
||||||
|
|
||||||
const auto &st = menu->st().menu;
|
const auto &st = menu->st().menu;
|
||||||
const auto iconTextPosition = st.itemIconPosition
|
const auto iconTextPosition = st.itemIconPosition
|
||||||
+ st::menuIconMuteForAnyTextPosition;
|
+ st::menuIconMuteForAnyTextPosition;
|
||||||
for (const auto muteFor : thread->session().settings().mutePeriods()) {
|
for (const auto muteFor : session->settings().mutePeriods()) {
|
||||||
const auto callback = with([=](not_null<Data::Thread*> thread) {
|
const auto callback = [=, update = descriptor.updateMutePeriod] {
|
||||||
notifySettings->update(thread, { .period = muteFor });
|
update(muteFor);
|
||||||
});
|
};
|
||||||
|
|
||||||
auto item = base::make_unique_q<IconWithText>(
|
auto item = base::make_unique_q<IconWithText>(
|
||||||
menu,
|
menu,
|
||||||
|
@ -295,20 +354,17 @@ void FillMuteMenu(
|
||||||
|
|
||||||
menu->addAction(
|
menu->addAction(
|
||||||
tr::lng_mute_menu_duration(tr::now),
|
tr::lng_mute_menu_duration(tr::now),
|
||||||
with([=](not_null<Data::Thread*> thread) {
|
[=] { show->showBox(Box(PickMuteBox, descriptor)); },
|
||||||
DEBUG_LOG(("Mute Info: PickMuteBox called."));
|
|
||||||
show->showBox(Box(PickMuteBox, thread));
|
|
||||||
}),
|
|
||||||
&st::menuIconMuteFor);
|
&st::menuIconMuteFor);
|
||||||
|
|
||||||
menu->addAction(
|
menu->addAction(
|
||||||
base::make_unique_q<MuteItem>(menu, menu->st().menu, thread));
|
base::make_unique_q<MuteItem>(menu, menu->st().menu, descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupMuteMenu(
|
void SetupMuteMenu(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
rpl::producer<> triggers,
|
rpl::producer<> triggers,
|
||||||
Fn<Data::Thread*()> makeThread,
|
Fn<std::optional<Descriptor>()> makeDescriptor,
|
||||||
std::shared_ptr<Ui::Show> show) {
|
std::shared_ptr<Ui::Show> show) {
|
||||||
struct State {
|
struct State {
|
||||||
base::unique_qptr<Ui::PopupMenu> menu;
|
base::unique_qptr<Ui::PopupMenu> menu;
|
||||||
|
@ -319,11 +375,11 @@ void SetupMuteMenu(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
if (state->menu) {
|
if (state->menu) {
|
||||||
return;
|
return;
|
||||||
} else if (const auto thread = makeThread()) {
|
} else if (const auto descriptor = makeDescriptor()) {
|
||||||
state->menu = base::make_unique_q<Ui::PopupMenu>(
|
state->menu = base::make_unique_q<Ui::PopupMenu>(
|
||||||
parent,
|
parent,
|
||||||
st::popupMenuWithIcons);
|
st::popupMenuWithIcons);
|
||||||
FillMuteMenu(state->menu.get(), thread, show);
|
FillMuteMenu(state->menu.get(), *descriptor, show);
|
||||||
state->menu->popup(QCursor::pos());
|
state->menu->popup(QCursor::pos());
|
||||||
}
|
}
|
||||||
}, parent->lifetime());
|
}, parent->lifetime());
|
||||||
|
|
|
@ -9,8 +9,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
class Thread;
|
class Thread;
|
||||||
|
struct NotifySound;
|
||||||
|
enum class DefaultNotify;
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
||||||
|
namespace Main {
|
||||||
|
class Session;
|
||||||
|
} // namespace Main
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class PopupMenu;
|
class PopupMenu;
|
||||||
class RpWidget;
|
class RpWidget;
|
||||||
|
@ -19,15 +25,48 @@ class Show;
|
||||||
|
|
||||||
namespace MuteMenu {
|
namespace MuteMenu {
|
||||||
|
|
||||||
|
struct Descriptor {
|
||||||
|
not_null<Main::Session*> session;
|
||||||
|
Fn<rpl::producer<bool>()> isMutedValue;
|
||||||
|
Fn<std::optional<Data::NotifySound>()> currentSound;
|
||||||
|
Fn<void(Data::NotifySound)> updateSound;
|
||||||
|
Fn<void(TimeId)> updateMutePeriod;
|
||||||
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] Descriptor ThreadDescriptor(not_null<Data::Thread*> thread);
|
||||||
|
[[nodiscard]] Descriptor DefaultDescriptor(
|
||||||
|
not_null<Main::Session*> session,
|
||||||
|
Data::DefaultNotify type);
|
||||||
|
|
||||||
void FillMuteMenu(
|
void FillMuteMenu(
|
||||||
not_null<Ui::PopupMenu*> menu,
|
not_null<Ui::PopupMenu*> menu,
|
||||||
not_null<Data::Thread*> thread,
|
Descriptor descriptor,
|
||||||
std::shared_ptr<Ui::Show> show);
|
std::shared_ptr<Ui::Show> show);
|
||||||
|
|
||||||
void SetupMuteMenu(
|
void SetupMuteMenu(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
rpl::producer<> triggers,
|
rpl::producer<> triggers,
|
||||||
Fn<Data::Thread*()> makeThread,
|
Fn<std::optional<Descriptor>()> makeDescriptor,
|
||||||
std::shared_ptr<Ui::Show> show);
|
std::shared_ptr<Ui::Show> show);
|
||||||
|
|
||||||
|
inline void FillMuteMenu(
|
||||||
|
not_null<Ui::PopupMenu*> menu,
|
||||||
|
not_null<Data::Thread*> thread,
|
||||||
|
std::shared_ptr<Ui::Show> show) {
|
||||||
|
FillMuteMenu(menu, ThreadDescriptor(thread), std::move(show));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void SetupMuteMenu(
|
||||||
|
not_null<Ui::RpWidget*> parent,
|
||||||
|
rpl::producer<> triggers,
|
||||||
|
Fn<Data::Thread*()> makeThread,
|
||||||
|
std::shared_ptr<Ui::Show> show) {
|
||||||
|
SetupMuteMenu(parent, std::move(triggers), [=] {
|
||||||
|
const auto thread = makeThread();
|
||||||
|
return thread
|
||||||
|
? ThreadDescriptor(thread)
|
||||||
|
: std::optional<Descriptor>();
|
||||||
|
}, std::move(show));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace MuteMenu
|
} // namespace MuteMenu
|
||||||
|
|
|
@ -380,7 +380,26 @@ void SetupChecks(
|
||||||
tr::lng_notification_enable(),
|
tr::lng_notification_enable(),
|
||||||
st::settingsButton,
|
st::settingsButton,
|
||||||
{ &st::menuIconNotifications }));
|
{ &st::menuIconNotifications }));
|
||||||
enabled->toggleOn(NotificationsEnabledForTypeValue(session, type));
|
enabled->toggleOn(
|
||||||
|
NotificationsEnabledForTypeValue(session, type),
|
||||||
|
true);
|
||||||
|
|
||||||
|
enabled->setAcceptBoth();
|
||||||
|
MuteMenu::SetupMuteMenu(
|
||||||
|
enabled,
|
||||||
|
enabled->clicks(
|
||||||
|
) | rpl::filter([=](Qt::MouseButton button) {
|
||||||
|
if (button == Qt::RightButton) {
|
||||||
|
return true;
|
||||||
|
} else if (settings->isMuted(type)) {
|
||||||
|
settings->defaultUpdate(type, { .unmute = true });
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}) | rpl::to_empty,
|
||||||
|
[=] { return MuteMenu::DefaultDescriptor(session, type); },
|
||||||
|
controller->uiShow());
|
||||||
|
|
||||||
const auto soundWrap = container->add(
|
const auto soundWrap = container->add(
|
||||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||||
|
|
Loading…
Add table
Reference in a new issue