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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -15,12 +15,13 @@ namespace AyuUi {
protected:
void prepare() override;
void resizeEvent(QResizeEvent *e) override;
private:
void ReadAllPeers();
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) {
return MakeConfirmBox({
.text = std::move(text),
.inform = true,
});
.text = std::move(text),
.inform = true,
});
}
} // namespace AyuUi

View file

@ -11,10 +11,11 @@
#include "ui/boxes/confirm_box.h"
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(
Ui::ConfirmBoxArgs &&args);
[[nodiscard]] object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text);
} // namespace Ui

View file

@ -26,16 +26,23 @@ namespace Settings {
private:
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 SetupBetaFunctions(not_null<Ui::VerticalLayout *> container);
void SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container, not_null<Window::SessionController *> null);
void setupContent(not_null<Window::SessionController *> controller);
};

View file

@ -14,7 +14,7 @@
constexpr auto kMaxChannelId = -1000000000000;
QString IDString(not_null<PeerData*> peer) {
QString IDString(not_null<PeerData *> peer) {
auto resultId = QString::number(peerIsUser(peer->id)
? peerToUser(peer->id).bare
: peerIsChat(peer->id)
@ -35,6 +35,6 @@ QString IDString(not_null<PeerData*> peer) {
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();
}

View file

@ -8,5 +8,6 @@
#pragma once
QString IDString(not_null<PeerData*> peer);
rpl::producer<TextWithEntities> IDValue(not_null<PeerData*> peer);
QString IDString(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(
) | rpl::map([=] {
auto settings = &AyuSettings::getInstance();
bool ghostModeEnabled = settings->get_ghostModeEnabled();
bool ghostModeEnabled = AyuSettings::get_ghostModeEnabled();
return ghostModeEnabled
? tr::ayu_DisableGhostMode(tr::now)
@ -102,7 +101,7 @@ void Tray::rebuildMenu() {
_tray.addAction(std::move(turnGhostModeText), [=] {
auto settings = &AyuSettings::getInstance();
bool ghostMode = !settings->get_ghostModeEnabled();
bool ghostMode = !AyuSettings::get_ghostModeEnabled();
settings->set_sendReadPackets(!ghostMode);
settings->set_sendOnlinePackets(!ghostMode);