fix: use MakeConfirmBox

This commit is contained in:
AlexeyZavar 2024-04-19 02:55:33 +03:00
parent 39e3fcb553
commit 1c275caf9d
4 changed files with 16 additions and 101 deletions

View file

@ -132,8 +132,6 @@ set(ayugram_files
ayu/ui/sections/edited/edited_log_item.h
ayu/ui/sections/edited/edited_log_section.cpp
ayu/ui/sections/edited/edited_log_section.h
ayu/ui/boxes/server_read_confirmation_box.cpp
ayu/ui/boxes/server_read_confirmation_box.h
ayu/ui/boxes/edit_deleted_mark.cpp
ayu/ui/boxes/edit_deleted_mark.h
ayu/ui/boxes/edit_edited_mark.cpp

View file

@ -1,66 +0,0 @@
// This is the source code of AyuGram for Desktop.
//
// We do not and cannot prevent the use of our code,
// but be respectful and credit the original author.
//
// Copyright @Radolyn, 2024
#include "server_read_confirmation_box.h"
#include "lang_auto.h"
#include "ayu/ayu_settings.h"
#include "ayu/utils/telegram_helpers.h"
#include "data/data_session.h"
#include "main/main_session.h"
#include "styles/style_layers.h"
#include "window/window_session_controller.h"
namespace AyuUi {
ServerReadConfirmationBox::ServerReadConfirmationBox(
QWidget *,
not_null<Window::SessionController*> controller)
: _controller(controller) {
//
}
void ServerReadConfirmationBox::prepare() {
_text.create(this, tr::ayu_ReadConfirmationBoxQuestion(), st::boxLabel);
auto fullHeight = st::boxPadding.top()
+ _text->height()
+ st::boxPadding.bottom();
setDimensions(st::boxWidth, fullHeight);
addButton(tr::ayu_ReadConfirmationBoxActionText(),
[=, this]
{
ReadAllPeers();
closeBox();
});
addButton(tr::lng_cancel(),
[=, this]
{
closeBox();
});
}
void ServerReadConfirmationBox::resizeEvent(QResizeEvent *e) {
BoxContent::resizeEvent(e);
const auto &padding = st::boxPadding;
_text->moveToLeft(padding.left(), padding.top());
}
void ServerReadConfirmationBox::ReadAllPeers() {
auto settings = &AyuSettings::getInstance();
auto prev = settings->sendReadMessages;
settings->set_sendReadMessages(true);
auto chats = _controller->session().data().chatsList();
MarkAsReadChatList(chats);
settings->set_sendReadMessages(prev);
}
}

View file

@ -1,31 +0,0 @@
// This is the source code of AyuGram for Desktop.
//
// We do not and cannot prevent the use of our code,
// but be respectful and credit the original author.
//
// Copyright @Radolyn, 2024
#pragma once
#include "ui/layers/box_content.h"
#include "window/window_main_menu.h"
namespace AyuUi {
class ServerReadConfirmationBox : public Ui::BoxContent
{
public:
ServerReadConfirmationBox(QWidget *, not_null<Window::SessionController*> controller);
protected:
void prepare() override;
void resizeEvent(QResizeEvent *e) override;
private:
void ReadAllPeers();
not_null<Window::SessionController*> _controller;
object_ptr<Ui::FlatLabel> _text = {nullptr};
};
}

View file

@ -72,7 +72,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
// AyuGram includes
#include "ayu/ayu_settings.h"
#include "ayu/utils/telegram_helpers.h"
#include "ayu/ui/boxes/server_read_confirmation_box.h"
#include "boxes/abstract_box.h"
#include "ayu/features/streamer_mode/streamer_mode.h"
#include "styles/style_ayu_icons.h"
@ -820,12 +819,27 @@ void MainMenu::setupMenu() {
}
if (settings->showSReadToggleInDrawer) {
auto callback = [=](Fn<void()> &&close) {
auto prev = settings->sendReadMessages;
settings->set_sendReadMessages(true);
auto chats = _controller->session().data().chatsList();
MarkAsReadChatList(chats);
settings->set_sendReadMessages(prev);
close();
};
addAction(
tr::ayu_SReadMessages(),
{&st::ayuSReadMenuIcon}
)->setClickedCallback([=]
{
auto box = Box<AyuUi::ServerReadConfirmationBox>(controller);
auto box = Ui::MakeConfirmBox({
.text = tr::ayu_ReadConfirmationBoxQuestion(),
.confirmed = callback,
.confirmText = tr::ayu_ReadConfirmationBoxActionText()
});
Ui::show(std::move(box));
});
}