mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 22:54:01 +02:00
Added ability to set custom mute time.
This commit is contained in:
parent
73b4a8b75a
commit
d8ee50c6fe
9 changed files with 191 additions and 6 deletions
BIN
Telegram/Resources/icons/menu/mute_for.png
Normal file
BIN
Telegram/Resources/icons/menu/mute_for.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 728 B |
BIN
Telegram/Resources/icons/menu/mute_for@2x.png
Normal file
BIN
Telegram/Resources/icons/menu/mute_for@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
Telegram/Resources/icons/menu/mute_for@3x.png
Normal file
BIN
Telegram/Resources/icons/menu/mute_for@3x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
|
@ -904,6 +904,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_mute_box_title" = "Mute notifications for...";
|
||||
"lng_mute_box_no_notifications" = "No notifications";
|
||||
"lng_mute_box_silent_notifications" = "Silent notifications";
|
||||
"lng_mute_box_days#one" = "{count} day";
|
||||
"lng_mute_box_days#other" = "{count} days";
|
||||
"lng_mute_box_hours#one" = "{count} hour";
|
||||
"lng_mute_box_hours#other" = "{count} hours";
|
||||
"lng_mute_box_minutes#one" = "{count} minute";
|
||||
"lng_mute_box_minutes#other" = "{count} minutes";
|
||||
|
||||
"lng_mute_duration_hours#one" = "For {count} hour";
|
||||
"lng_mute_duration_hours#other" = "For {count} hours";
|
||||
|
|
|
@ -989,6 +989,16 @@ scheduleTimeSeparator: FlatLabel(defaultFlatLabel) {
|
|||
}
|
||||
scheduleTimeSeparatorPadding: margins(2px, 0px, 2px, 0px);
|
||||
|
||||
muteBoxTimeField: InputField(scheduleDateField) {
|
||||
textMargins: margins(0px, 0px, 0px, 0px);
|
||||
placeholderMargins: margins(0px, 0px, 0px, 0px);
|
||||
placeholderScale: 0.;
|
||||
heightMin: 30px;
|
||||
textAlign: align(left);
|
||||
font: font(14px);
|
||||
}
|
||||
muteBoxTimeFieldPadding: margins(5px, 0px, 5px, 0px);
|
||||
|
||||
boxAttentionDividerLabel: FlatLabel(boxDividerLabel) {
|
||||
textFg: boxTextFgError;
|
||||
}
|
||||
|
|
|
@ -379,7 +379,7 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupMuteToggle() {
|
|||
MuteMenu::SetupMuteMenu(
|
||||
result.data(),
|
||||
result->clicks() | rpl::to_empty,
|
||||
peer);
|
||||
{ peer, std::make_shared<Window::Show>(_controller) });
|
||||
object_ptr<FloatingIcon>(
|
||||
result,
|
||||
st::infoIconNotifications,
|
||||
|
|
|
@ -7,15 +7,21 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "menu/menu_mute.h"
|
||||
|
||||
#include "base/qt_signal_producer.h"
|
||||
#include "data/data_peer.h"
|
||||
#include "data/data_session.h"
|
||||
#include "info/profile/info_profile_values.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "menu/menu_check_item.h"
|
||||
#include "ui/effects/animation_value.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/fields/time_part_input_with_placeholder.h"
|
||||
#include "ui/widgets/menu/menu_action.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_info.h" // infoTopBarMenu
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
|
||||
namespace MuteMenu {
|
||||
|
@ -132,11 +138,162 @@ void FillSoundMenu(
|
|||
}, menu->lifetime());
|
||||
}
|
||||
|
||||
void MuteBox(not_null<Ui::GenericBox*> box, not_null<PeerData*> peer) {
|
||||
using TimeField = Ui::TimePartWithPlaceholder;
|
||||
const auto putNext = [](not_null<TimeField*> field, QChar ch) {
|
||||
field->setCursorPosition(0);
|
||||
if (ch.unicode()) {
|
||||
field->setText(ch + field->getLastText());
|
||||
field->setCursorPosition(1);
|
||||
}
|
||||
field->onTextEdited();
|
||||
field->setFocus();
|
||||
};
|
||||
|
||||
const auto erasePrevious = [](not_null<TimeField*> field) {
|
||||
const auto text = field->getLastText();
|
||||
if (!text.isEmpty()) {
|
||||
field->setCursorPosition(text.size() - 1);
|
||||
field->setText(text.mid(0, text.size() - 1));
|
||||
}
|
||||
field->setFocus();
|
||||
};
|
||||
|
||||
struct State {
|
||||
not_null<TimeField*> day;
|
||||
not_null<TimeField*> hour;
|
||||
not_null<TimeField*> minute;
|
||||
|
||||
base::unique_qptr<Ui::PopupMenu> menu;
|
||||
|
||||
rpl::variable<bool> noSoundChanges;
|
||||
int valueInSeconds = 0;
|
||||
};
|
||||
|
||||
const auto content = box->addRow(
|
||||
object_ptr<Ui::FixedHeightWidget>(box, st::scheduleHeight));
|
||||
|
||||
const auto state = box->lifetime().make_state<State>(State{
|
||||
.day = Ui::CreateChild<TimeField>(
|
||||
content,
|
||||
st::muteBoxTimeField,
|
||||
rpl::never<QString>(),
|
||||
QString::number(0)),
|
||||
.hour = Ui::CreateChild<TimeField>(
|
||||
content,
|
||||
st::muteBoxTimeField,
|
||||
rpl::never<QString>(),
|
||||
QString::number(0)),
|
||||
.minute = Ui::CreateChild<TimeField>(
|
||||
content,
|
||||
st::muteBoxTimeField,
|
||||
rpl::never<QString>(),
|
||||
QString::number(0)),
|
||||
.noSoundChanges = false,
|
||||
});
|
||||
|
||||
const auto day = Ui::MakeWeak(state->day);
|
||||
const auto hour = Ui::MakeWeak(state->hour);
|
||||
const auto minute = Ui::MakeWeak(state->minute);
|
||||
|
||||
day->setPhrase(tr::lng_mute_box_days);
|
||||
day->setMaxValue(31);
|
||||
day->setWheelStep(1);
|
||||
day->putNext() | rpl::start_with_next([=](QChar ch) {
|
||||
putNext(hour, ch);
|
||||
}, box->lifetime());
|
||||
|
||||
hour->setPhrase(tr::lng_mute_box_hours);
|
||||
hour->setMaxValue(23);
|
||||
hour->setWheelStep(1);
|
||||
hour->putNext() | rpl::start_with_next([=](QChar ch) {
|
||||
putNext(minute, ch);
|
||||
}, box->lifetime());
|
||||
hour->erasePrevious() | rpl::start_with_next([=] {
|
||||
erasePrevious(day);
|
||||
}, box->lifetime());
|
||||
|
||||
minute->setPhrase(tr::lng_mute_box_minutes);
|
||||
minute->setMaxValue(59);
|
||||
minute->setWheelStep(10);
|
||||
minute->erasePrevious() | rpl::start_with_next([=] {
|
||||
erasePrevious(hour);
|
||||
}, box->lifetime());
|
||||
|
||||
content->sizeValue(
|
||||
) | rpl::start_with_next([=](const QSize &s) {
|
||||
const auto inputWidth = s.width() / 3;
|
||||
auto rect = QRect(
|
||||
0,
|
||||
(s.height() - day->height()) / 2,
|
||||
inputWidth,
|
||||
day->height());
|
||||
for (const auto &input : { day, hour, minute }) {
|
||||
input->setGeometry(rect - st::muteBoxTimeFieldPadding);
|
||||
rect.translate(inputWidth, 0);
|
||||
}
|
||||
}, box->lifetime());
|
||||
|
||||
box->setTitle(tr::lng_mute_box_title());
|
||||
|
||||
const auto topButton = box->addTopButton(st::infoTopBarMenu);
|
||||
topButton->setClickedCallback([=] {
|
||||
if (state->menu) {
|
||||
return;
|
||||
}
|
||||
state->menu = base::make_unique_q<Ui::PopupMenu>(
|
||||
topButton,
|
||||
st::popupMenuWithIcons);
|
||||
FillSoundMenu(
|
||||
state->menu.get(),
|
||||
peer,
|
||||
tr::lng_mute_box_no_notifications(),
|
||||
tr::lng_mute_box_silent_notifications(),
|
||||
[=](bool silent) {
|
||||
state->noSoundChanges = silent;
|
||||
});
|
||||
state->menu->popup(QCursor::pos());
|
||||
return;
|
||||
});
|
||||
|
||||
const auto updateValueInSeconds = [=] {
|
||||
state->valueInSeconds = 0
|
||||
+ day->getLastText().toUInt() * 3600 * 24
|
||||
+ hour->getLastText().toUInt() * 3600
|
||||
+ minute->getLastText().toUInt() * 60;
|
||||
};
|
||||
|
||||
using Field = Ui::MaskedInputField;
|
||||
auto confirmText = rpl::merge(
|
||||
base::qt_signal_producer(day.data(), &Field::changed),
|
||||
base::qt_signal_producer(hour.data(), &Field::changed),
|
||||
base::qt_signal_producer(minute.data(), &Field::changed),
|
||||
state->noSoundChanges.value() | rpl::to_empty
|
||||
) | rpl::map([=] {
|
||||
updateValueInSeconds();
|
||||
return !state->valueInSeconds
|
||||
? tr::lng_mute_menu_unmute()
|
||||
: state->noSoundChanges.current()
|
||||
? tr::lng_mute_box_silent_notifications()
|
||||
: tr::lng_mute_menu_mute();
|
||||
}) | rpl::flatten_latest();
|
||||
const auto confirm = box->addButton(std::move(confirmText), [=] {
|
||||
peer->owner().updateNotifySettings(
|
||||
peer,
|
||||
state->valueInSeconds,
|
||||
std::nullopt,
|
||||
state->noSoundChanges.current());
|
||||
box->closeBox();
|
||||
});
|
||||
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void FillMuteMenu(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
not_null<PeerData*> peer) {
|
||||
Args args) {
|
||||
const auto peer = args.peer;
|
||||
|
||||
FillSoundMenu(
|
||||
menu,
|
||||
|
@ -149,6 +306,11 @@ void FillMuteMenu(
|
|||
|
||||
menu->addSeparator();
|
||||
|
||||
menu->addAction(
|
||||
tr::lng_mute_menu_duration(tr::now),
|
||||
[=, show = args.show] { show->showBox(Box(MuteBox, peer)); },
|
||||
&st::menuIconMuteFor);
|
||||
|
||||
menu->addAction(
|
||||
base::make_unique_q<MuteItem>(menu, menu->st().menu, peer));
|
||||
}
|
||||
|
@ -156,7 +318,7 @@ void FillMuteMenu(
|
|||
void SetupMuteMenu(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
rpl::producer<> triggers,
|
||||
not_null<PeerData*> peer) {
|
||||
Args args) {
|
||||
struct State {
|
||||
base::unique_qptr<Ui::PopupMenu> menu;
|
||||
};
|
||||
|
@ -170,7 +332,7 @@ void SetupMuteMenu(
|
|||
state->menu = base::make_unique_q<Ui::PopupMenu>(
|
||||
parent,
|
||||
st::popupMenuWithIcons);
|
||||
FillMuteMenu(state->menu.get(), peer);
|
||||
FillMuteMenu(state->menu.get(), args);
|
||||
state->menu->popup(QCursor::pos());
|
||||
}, parent->lifetime());
|
||||
}
|
||||
|
|
|
@ -12,17 +12,23 @@ class PeerData;
|
|||
namespace Ui {
|
||||
class PopupMenu;
|
||||
class RpWidget;
|
||||
class Show;
|
||||
} // namespace Ui
|
||||
|
||||
namespace MuteMenu {
|
||||
|
||||
struct Args {
|
||||
not_null<PeerData*> peer;
|
||||
std::shared_ptr<Ui::Show> show;
|
||||
};
|
||||
|
||||
void FillMuteMenu(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
not_null<PeerData*> peer);
|
||||
Args args);
|
||||
|
||||
void SetupMuteMenu(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
rpl::producer<> triggers,
|
||||
not_null<PeerData*> peer);
|
||||
Args args);
|
||||
|
||||
} // namespace MuteMenu
|
||||
|
|
|
@ -93,6 +93,7 @@ menuIconFake: icon {{ "menu/fake", menuIconColor }};
|
|||
menuIconPersonal: icon {{ "menu/personal", menuIconColor }};
|
||||
menuIconPorn: icon {{ "menu/porn", menuIconColor }};
|
||||
menuIconViolence: icon {{ "menu/violence", menuIconColor }};
|
||||
menuIconMuteFor: icon {{ "menu/mute_for", menuIconColor }};
|
||||
menuIconSilent: icon {{ "menu/silent", menuIconColor }};
|
||||
|
||||
mediaMenuIconStickers: icon {{ "menu/stickers", mediaviewMenuFg }};
|
||||
|
|
Loading…
Add table
Reference in a new issue