mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added draft implementation of menu for silent notifications setting.
This commit is contained in:
parent
8b7ea09fa9
commit
3f6c693c3f
1 changed files with 53 additions and 0 deletions
|
@ -11,7 +11,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.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 "menu/menu_check_item.h"
|
||||||
#include "ui/effects/animation_value.h"
|
#include "ui/effects/animation_value.h"
|
||||||
|
#include "ui/widgets/checkbox.h"
|
||||||
#include "ui/widgets/menu/menu_action.h"
|
#include "ui/widgets/menu/menu_action.h"
|
||||||
#include "ui/widgets/popup_menu.h"
|
#include "ui/widgets/popup_menu.h"
|
||||||
#include "styles/style_menu_icons.h"
|
#include "styles/style_menu_icons.h"
|
||||||
|
@ -90,12 +92,63 @@ void MuteItem::paintEvent(QPaintEvent *e) {
|
||||||
icon.paint(p, _itemIconPosition, width(), color);
|
icon.paint(p, _itemIconPosition, width(), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FillSoundMenu(
|
||||||
|
not_null<Ui::PopupMenu*> menu,
|
||||||
|
not_null<PeerData*> peer,
|
||||||
|
rpl::producer<QString> &&soundOnText,
|
||||||
|
rpl::producer<QString> &&soundOffText,
|
||||||
|
Fn<void(bool)> notifySound) {
|
||||||
|
const auto createView = [&](rpl::producer<QString> &&text, bool checked) {
|
||||||
|
auto item = base::make_unique_q<Menu::ItemWithCheck>(
|
||||||
|
menu->menu(),
|
||||||
|
st::popupMenuWithIcons.menu,
|
||||||
|
new QAction(QString(), menu->menu()),
|
||||||
|
nullptr,
|
||||||
|
nullptr);
|
||||||
|
std::move(
|
||||||
|
text
|
||||||
|
) | rpl::start_with_next([action = item->action()](QString text) {
|
||||||
|
action->setText(text);
|
||||||
|
}, item->lifetime());
|
||||||
|
item->init(checked);
|
||||||
|
const auto view = item->checkView();
|
||||||
|
menu->addAction(std::move(item));
|
||||||
|
return view;
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto soundIsNone = peer->owner().notifySoundIsNone(peer);
|
||||||
|
const auto soundOn = createView(std::move(soundOnText), !soundIsNone);
|
||||||
|
const auto soundOff = createView(std::move(soundOffText), soundIsNone);
|
||||||
|
|
||||||
|
soundOn->checkedChanges(
|
||||||
|
) | rpl::start_with_next([=](bool checked) {
|
||||||
|
soundOff->setChecked(!checked, anim::type::normal);
|
||||||
|
notifySound(!checked);
|
||||||
|
}, menu->lifetime());
|
||||||
|
soundOff->checkedChanges(
|
||||||
|
) | rpl::start_with_next([=](bool checked) {
|
||||||
|
soundOn->setChecked(!checked, anim::type::normal);
|
||||||
|
notifySound(checked);
|
||||||
|
}, menu->lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void FillMuteMenu(
|
void FillMuteMenu(
|
||||||
not_null<Ui::PopupMenu*> menu,
|
not_null<Ui::PopupMenu*> menu,
|
||||||
not_null<PeerData*> peer) {
|
not_null<PeerData*> peer) {
|
||||||
|
|
||||||
|
FillSoundMenu(
|
||||||
|
menu,
|
||||||
|
peer,
|
||||||
|
tr::lng_mute_menu_sound_on(),
|
||||||
|
tr::lng_mute_menu_sound_off(),
|
||||||
|
[peer](bool silent) {
|
||||||
|
peer->owner().updateNotifySettings(peer, {}, {}, silent);
|
||||||
|
});
|
||||||
|
|
||||||
|
menu->addSeparator();
|
||||||
|
|
||||||
menu->addAction(
|
menu->addAction(
|
||||||
base::make_unique_q<MuteItem>(menu, menu->st().menu, peer));
|
base::make_unique_q<MuteItem>(menu, menu->st().menu, peer));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue