fix: refactor a bit

This commit is contained in:
ZavaruKitsu 2023-07-02 15:36:03 +03:00
parent f12dc74cd1
commit b6b3ad5ff9
13 changed files with 62 additions and 28 deletions

View file

@ -18,6 +18,8 @@ namespace AyuSettings {
rpl::variable<bool> sendReadPacketsReactive; rpl::variable<bool> sendReadPacketsReactive;
rpl::variable<bool> sendOnlinePacketsReactive; rpl::variable<bool> sendOnlinePacketsReactive;
rpl::variable<bool> sendUploadProgressReactive;
rpl::variable<bool> sendOfflinePacketAfterOnlineReactive;
rpl::variable<QString> deletedMarkReactive; rpl::variable<QString> deletedMarkReactive;
rpl::variable<QString> editedMarkReactive; rpl::variable<QString> editedMarkReactive;
@ -27,22 +29,39 @@ namespace AyuSettings {
rpl::lifetime lifetime = rpl::lifetime(); rpl::lifetime lifetime = rpl::lifetime();
bool ghostModeEnabled_util(AyuGramSettings &settingsUtil) {
return (!settingsUtil.sendReadPackets
&& !settingsUtil.sendOnlinePackets
&& !settingsUtil.sendUploadProgress
&& settingsUtil.sendOfflinePacketAfterOnline);
}
void initialize() { void initialize() {
if (settings.has_value()) { if (settings.has_value()) {
return; return;
} }
settings = std::optional(AyuGramSettings()); settings = AyuGramSettings();
sendReadPacketsReactive.value() | rpl::filter([=](bool val) { sendReadPacketsReactive.value() | rpl::filter([=](bool val) {
return (val != settings->sendReadPackets); return (val != settings->sendReadPackets);
}) | rpl::start_with_next([=](bool val) { }) | rpl::start_with_next([=](bool val) {
ghostModeEnabled = !settings->sendReadPackets && !settings->sendOnlinePackets; ghostModeEnabled = ghostModeEnabled_util(settings.value());
}, lifetime); }, lifetime);
sendOnlinePacketsReactive.value() | rpl::filter([=](bool val) { sendOnlinePacketsReactive.value() | rpl::filter([=](bool val) {
return (val != settings->sendOnlinePackets); return (val != settings->sendOnlinePackets);
}) | rpl::start_with_next([=](bool val) { }) | rpl::start_with_next([=](bool val) {
ghostModeEnabled = !settings->sendReadPackets && !settings->sendOnlinePackets; ghostModeEnabled = ghostModeEnabled_util(settings.value());
}, lifetime);
sendUploadProgressReactive.value() | rpl::filter([=](bool val) {
return (val != settings->sendUploadProgress);
}) | rpl::start_with_next([=](bool val) {
ghostModeEnabled = ghostModeEnabled_util(settings.value());
}, lifetime);
sendOfflinePacketAfterOnlineReactive.value() | rpl::filter([=](bool val) {
return (val != settings->sendOfflinePacketAfterOnline);
}) | rpl::start_with_next([=](bool val) {
ghostModeEnabled = ghostModeEnabled_util(settings.value());
}, lifetime); }, lifetime);
} }
@ -54,7 +73,7 @@ namespace AyuSettings {
editedMarkReactive = settings->editedMark; editedMarkReactive = settings->editedMark;
showPeerIdReactive = settings->showPeerId; showPeerIdReactive = settings->showPeerId;
ghostModeEnabled = !settings->sendReadPackets && !settings->sendOnlinePackets; ghostModeEnabled = ghostModeEnabled_util(settings.value());
} }
AyuGramSettings &getInstance() { AyuGramSettings &getInstance() {
@ -102,10 +121,12 @@ namespace AyuSettings {
void AyuGramSettings::set_sendUploadProgress(bool val) { void AyuGramSettings::set_sendUploadProgress(bool val) {
sendUploadProgress = val; sendUploadProgress = val;
sendUploadProgressReactive = val;
} }
void AyuGramSettings::set_sendOfflinePacketAfterOnline(bool val) { void AyuGramSettings::set_sendOfflinePacketAfterOnline(bool val) {
sendOfflinePacketAfterOnline = val; sendOfflinePacketAfterOnline = val;
sendOfflinePacketAfterOnlineReactive = val;
} }
void AyuGramSettings::set_markReadAfterSend(bool val) { void AyuGramSettings::set_markReadAfterSend(bool val) {
@ -167,11 +188,8 @@ namespace AyuSettings {
voiceConfirmation = val; voiceConfirmation = val;
} }
bool AyuGramSettings::get_ghostModeEnabled() const { bool get_ghostModeEnabled() {
return (!sendReadPackets return ghostModeEnabled.current();
&& !sendOnlinePackets
&& !sendUploadProgress
&& sendOfflinePacketAfterOnline);
} }
rpl::producer<QString> get_deletedMarkReactive() { rpl::producer<QString> get_deletedMarkReactive() {

View file

@ -112,8 +112,6 @@ namespace AyuSettings {
void set_GIFConfirmation(bool val); void set_GIFConfirmation(bool val);
void set_voiceConfirmation(bool val); void set_voiceConfirmation(bool val);
bool get_ghostModeEnabled() const;
}; };
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
@ -151,5 +149,7 @@ namespace AyuSettings {
rpl::producer<int> get_showPeerIdReactive(); rpl::producer<int> get_showPeerIdReactive();
// computed fields // computed fields
bool get_ghostModeEnabled();
rpl::producer<bool> get_ghostModeEnabledReactive(); rpl::producer<bool> get_ghostModeEnabledReactive();
} }

View file

@ -36,5 +36,6 @@ namespace AyuState {
} }
void setAllowSendReadPacket(bool val, int resetAfter = 1); void setAllowSendReadPacket(bool val, int resetAfter = 1);
bool getAllowSendPacket(); bool getAllowSendPacket();
} }

View file

@ -15,6 +15,7 @@ class SyncBatch : public SyncEvent {
class SyncBatchArgs { class SyncBatchArgs {
std::vector<SyncEvent> events; std::vector<SyncEvent> events;
}; };
SyncBatchArgs args; SyncBatchArgs args;
}; };
@ -27,6 +28,7 @@ class SyncRead : public SyncEvent {
int untilId; int untilId;
int unread; int unread;
}; };
SyncReadArgs args; SyncReadArgs args;
}; };
@ -37,6 +39,7 @@ class SyncForce : public SyncEvent {
class SyncForceArgs { class SyncForceArgs {
int fromDate; int fromDate;
}; };
SyncForceArgs args; SyncForceArgs args;
}; };
@ -46,6 +49,7 @@ class SyncForceFinish : public SyncEvent {
class SyncForceFinishArgs { class SyncForceFinishArgs {
}; };
SyncForceFinishArgs args; SyncForceFinishArgs args;
}; };

View file

@ -32,7 +32,7 @@ json ayu_pipe_wrapper::receive() {
char buff[4096]; char buff[4096];
while (length > 0) { while (length > 0) {
auto readSize = std::min(length, (int)sizeof(buff)); auto readSize = std::min(length, (int) sizeof(buff));
is.read(buff, readSize); is.read(buff, readSize);
sb.sputn(buff, readSize); sb.sputn(buff, readSize);
length -= readSize; length -= readSize;

View file

@ -17,7 +17,9 @@ class ayu_pipe_wrapper {
public: public:
template<class T> template<class T>
void send(T obj); void send(T obj);
json receive(); json receive();
private: private:
nes::basic_pipe_istream<char> is{"AyuSync"}; nes::basic_pipe_istream<char> is{"AyuSync"};
nes::basic_pipe_ostream<char> os{"AyuSync"}; nes::basic_pipe_ostream<char> os{"AyuSync"};

View file

@ -15,12 +15,13 @@ namespace AyuUi {
protected: protected:
void prepare() override; void prepare() override;
void resizeEvent(QResizeEvent *e) override; void resizeEvent(QResizeEvent *e) override;
private: private:
void ReadAllPeers(); void ReadAllPeers();
not_null<Window::SessionController *> _controller; not_null<Window::SessionController *> _controller;
object_ptr<Ui::FlatLabel> _text = { nullptr }; object_ptr<Ui::FlatLabel> _text = {nullptr};
}; };
} }

View file

@ -94,9 +94,9 @@ namespace AyuUi {
object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text) { object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text) {
return MakeConfirmBox({ return MakeConfirmBox({
.text = std::move(text), .text = std::move(text),
.inform = true, .inform = true,
}); });
} }
} // namespace AyuUi } // namespace AyuUi

View file

@ -11,10 +11,11 @@
#include "ui/boxes/confirm_box.h" #include "ui/boxes/confirm_box.h"
namespace AyuUi { namespace AyuUi {
void VoiceConfirmBox(not_null<Ui::GenericBox*> box, Ui::ConfirmBoxArgs &&args); void VoiceConfirmBox(not_null<Ui::GenericBox *> box, Ui::ConfirmBoxArgs &&args);
[[nodiscard]] object_ptr<Ui::GenericBox> MakeConfirmBox( [[nodiscard]] object_ptr<Ui::GenericBox> MakeConfirmBox(
Ui::ConfirmBoxArgs &&args); Ui::ConfirmBoxArgs &&args);
[[nodiscard]] object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text); [[nodiscard]] object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text);
} // namespace Ui } // namespace Ui

View file

@ -26,16 +26,23 @@ namespace Settings {
private: private:
void SetupGhostEssentials(not_null<Ui::VerticalLayout *> container); void SetupGhostEssentials(not_null<Ui::VerticalLayout *> container);
void SetupSpyEssentials(not_null<Ui::VerticalLayout *> container);
void SetupQoLToggles(not_null<Ui::VerticalLayout *> container);
void SetupCustomization(not_null<Ui::VerticalLayout *> container, not_null<Window::SessionController *> controller);
void SetupShowPeerId(not_null<Ui::VerticalLayout *> container, not_null<Window::SessionController *> controller); void SetupSpyEssentials(not_null<Ui::VerticalLayout *> container);
void SetupQoLToggles(not_null<Ui::VerticalLayout *> container);
void
SetupCustomization(not_null<Ui::VerticalLayout *> container, not_null<Window::SessionController *> controller);
void
SetupShowPeerId(not_null<Ui::VerticalLayout *> container, not_null<Window::SessionController *> controller);
void SetupRecentStickersLimitSlider(not_null<Ui::VerticalLayout *> container); void SetupRecentStickersLimitSlider(not_null<Ui::VerticalLayout *> container);
void SetupBetaFunctions(not_null<Ui::VerticalLayout *> container); void SetupBetaFunctions(not_null<Ui::VerticalLayout *> container);
void SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container, not_null<Window::SessionController *> null); void SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container, not_null<Window::SessionController *> null);
void setupContent(not_null<Window::SessionController *> controller); void setupContent(not_null<Window::SessionController *> controller);
}; };

View file

@ -14,7 +14,7 @@
constexpr auto kMaxChannelId = -1000000000000; constexpr auto kMaxChannelId = -1000000000000;
QString IDString(not_null<PeerData*> peer) { QString IDString(not_null<PeerData *> peer) {
auto resultId = QString::number(peerIsUser(peer->id) auto resultId = QString::number(peerIsUser(peer->id)
? peerToUser(peer->id).bare ? peerToUser(peer->id).bare
: peerIsChat(peer->id) : peerIsChat(peer->id)
@ -35,6 +35,6 @@ QString IDString(not_null<PeerData*> peer) {
return resultId; return resultId;
} }
rpl::producer<TextWithEntities> IDValue(not_null<PeerData*> peer) { rpl::producer<TextWithEntities> IDValue(not_null<PeerData *> peer) {
return rpl::single(IDString(peer)) | Ui::Text::ToWithEntities(); return rpl::single(IDString(peer)) | Ui::Text::ToWithEntities();
} }

View file

@ -8,5 +8,6 @@
#pragma once #pragma once
QString IDString(not_null<PeerData*> peer); QString IDString(not_null<PeerData *> peer);
rpl::producer<TextWithEntities> IDValue(not_null<PeerData*> peer);
rpl::producer<TextWithEntities> IDValue(not_null<PeerData *> peer);

View file

@ -92,8 +92,7 @@ void Tray::rebuildMenu() {
auto turnGhostModeText = _textUpdates.events( auto turnGhostModeText = _textUpdates.events(
) | rpl::map([=] { ) | rpl::map([=] {
auto settings = &AyuSettings::getInstance(); bool ghostModeEnabled = AyuSettings::get_ghostModeEnabled();
bool ghostModeEnabled = settings->get_ghostModeEnabled();
return ghostModeEnabled return ghostModeEnabled
? tr::ayu_DisableGhostMode(tr::now) ? tr::ayu_DisableGhostMode(tr::now)
@ -102,7 +101,7 @@ void Tray::rebuildMenu() {
_tray.addAction(std::move(turnGhostModeText), [=] { _tray.addAction(std::move(turnGhostModeText), [=] {
auto settings = &AyuSettings::getInstance(); auto settings = &AyuSettings::getInstance();
bool ghostMode = !settings->get_ghostModeEnabled(); bool ghostMode = !AyuSettings::get_ghostModeEnabled();
settings->set_sendReadPackets(!ghostMode); settings->set_sendReadPackets(!ghostMode);
settings->set_sendOnlinePackets(!ghostMode); settings->set_sendOnlinePackets(!ghostMode);