feat: reformat ayu files with resharper

This commit is contained in:
ZavaruKitsu 2023-07-09 18:09:01 +00:00
parent 85e8c75ad1
commit 32a2de1bef
35 changed files with 1866 additions and 1590 deletions

View file

@ -8,43 +8,53 @@
#include "ayu_lang.h"
#include "qjsondocument.h"
#include "lang/lang_instance.h"
#include "core/application.h"
#include "core/core_settings.h"
#include "lang/lang_instance.h"
CustomLangPack *CustomLangPack::instance = nullptr;
CustomLangPack* CustomLangPack::instance = nullptr;
CustomLangPack::CustomLangPack() = default;
void CustomLangPack::initInstance() {
void CustomLangPack::initInstance()
{
if (!instance)
instance = new CustomLangPack;
}
CustomLangPack *CustomLangPack::currentInstance() {
CustomLangPack* CustomLangPack::currentInstance()
{
return instance;
}
void CustomLangPack::fetchCustomLangPack(const QString &langPackId, const QString &langPackBaseId) {
void CustomLangPack::fetchCustomLangPack(const QString& langPackId, const QString& langPackBaseId)
{
LOG(("Current Language pack ID: %1, Base ID: %2").arg(langPackId, langPackBaseId));
auto finalLangPackId = langPackId;
if (finalLangPackId == qsl("pt-br")) { // meh
if (finalLangPackId == qsl("pt-br"))
{
// meh
finalLangPackId = qsl("pt");
}
const auto proxy = Core::App().settings().proxy().isEnabled() ? Core::App().settings().proxy().selected()
const auto proxy = Core::App().settings().proxy().isEnabled()
? Core::App().settings().proxy().selected()
: MTP::ProxyData();
if (proxy.type == MTP::ProxyData::Type::Socks5 || proxy.type == MTP::ProxyData::Type::Http) {
QNetworkProxy LocaleProxy = MTP::ToNetworkProxy(MTP::ToDirectIpProxy(proxy));
if (proxy.type == MTP::ProxyData::Type::Socks5 || proxy.type == MTP::ProxyData::Type::Http)
{
QNetworkProxy LocaleProxy = ToNetworkProxy(ToDirectIpProxy(proxy));
networkManager.setProxy(LocaleProxy);
}
QUrl url;
if (!finalLangPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) {
if (!finalLangPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback)
{
url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/Languages/l10n_main/values/langs/%1/Shared.json").arg(
finalLangPackId));
} else {
}
else
{
url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/Languages/l10n_main/values/langs/%1/Shared.json").arg(
needFallback ? langPackBaseId : finalLangPackId));
}
@ -55,25 +65,32 @@ void CustomLangPack::fetchCustomLangPack(const QString &langPackId, const QStrin
needFallback ? (langPackBaseId.isEmpty() ? finalLangPackId : langPackBaseId) : finalLangPackId));
}
void CustomLangPack::fetchFinished() {
void CustomLangPack::fetchFinished()
{
if (!_chkReply) return;
QString langPackBaseId = Lang::GetInstance().baseId();
QString langPackId = Lang::GetInstance().id();
auto statusCode = _chkReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (statusCode == 404 && !langPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) {
if (statusCode == 404 && !langPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback)
{
LOG(("AyuGram Language pack not found! Fallback to main language: %1...").arg(langPackBaseId));
needFallback = true;
_chkReply->disconnect();
fetchCustomLangPack("", langPackBaseId);
} else {
}
else
{
QByteArray result = _chkReply->readAll().trimmed();
QJsonParseError error{};
QJsonDocument str = QJsonDocument::fromJson(result, &error);
if (error.error == QJsonParseError::NoError) {
if (error.error == QJsonParseError::NoError)
{
parseLangFile(str);
} else {
}
else
{
LOG(("Incorrect JSON File. Fallback to default language: English..."));
loadDefaultLangFile();
}
@ -82,19 +99,24 @@ void CustomLangPack::fetchFinished() {
}
}
void CustomLangPack::fetchError(QNetworkReply::NetworkError e) {
void CustomLangPack::fetchError(QNetworkReply::NetworkError e)
{
LOG(("Network error: %1").arg(e));
if (e == QNetworkReply::NetworkError::ContentNotFoundError) {
if (e == QNetworkReply::NetworkError::ContentNotFoundError)
{
QString langPackBaseId = Lang::GetInstance().baseId();
QString langPackId = Lang::GetInstance().id();
if (!langPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) {
if (!langPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback)
{
LOG(("AyuGram Language pack not found! Fallback to main language: %1...").arg(langPackBaseId));
needFallback = true;
_chkReply->disconnect();
fetchCustomLangPack("", langPackBaseId);
} else {
}
else
{
LOG(("AyuGram Language pack not found! Fallback to default language: English..."));
loadDefaultLangFile();
_chkReply = nullptr;
@ -102,12 +124,15 @@ void CustomLangPack::fetchError(QNetworkReply::NetworkError e) {
}
}
void CustomLangPack::loadDefaultLangFile() {
void CustomLangPack::loadDefaultLangFile()
{
QFile file(":/localization/en.json");
if (file.open(QIODevice::ReadOnly)) {
if (file.open(QIODevice::ReadOnly))
{
QJsonDocument str = QJsonDocument::fromJson(file.readAll());
QJsonObject json = str.object();
for (const QString &key: json.keys()) {
for (const QString& key : json.keys())
{
Lang::GetInstance().applyValue(key.toUtf8(), json.value(key).toString().toUtf8());
}
Lang::GetInstance().updatePluralRules();
@ -115,15 +140,18 @@ void CustomLangPack::loadDefaultLangFile() {
}
}
void CustomLangPack::parseLangFile(QJsonDocument str) {
void CustomLangPack::parseLangFile(QJsonDocument str)
{
QJsonObject json = str.object();
for (const QString &brokenKey: json.keys()) {
for (const QString& brokenKey : json.keys())
{
auto key = qsl("ayu_") + brokenKey;
auto val = json.value(brokenKey).toString().replace(qsl("&"), qsl("&")).toUtf8();
Lang::GetInstance().resetValue(key.toUtf8());
Lang::GetInstance().applyValue(key.toUtf8(), val);
if (key.contains("#other")) {
if (key.contains("#other"))
{
Lang::GetInstance().resetValue(key.toUtf8().replace("#other", "#few"));
Lang::GetInstance().resetValue(key.toUtf8().replace("#other", "#few"));
Lang::GetInstance().applyValue(key.toUtf8().replace("#other", "#few"), val);

View file

@ -10,26 +10,26 @@
#include <QtNetwork/QNetworkReply>
#include <QtXml/QDomDocument>
class CustomLangPack : public QObject {
Q_OBJECT
class CustomLangPack : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(CustomLangPack)
public:
static CustomLangPack *currentInstance();
static CustomLangPack* currentInstance();
static void initInstance();
static CustomLangPack *instance;
static CustomLangPack* instance;
void fetchCustomLangPack(const QString &langPackId, const QString &langPackBaseId);
void fetchCustomLangPack(const QString& langPackId, const QString& langPackBaseId);
void loadDefaultLangFile();
void parseLangFile(QJsonDocument str);
public Q_SLOTS:
void fetchFinished();
void fetchError(QNetworkReply::NetworkError e);
@ -37,9 +37,9 @@ public Q_SLOTS:
private:
CustomLangPack();
~CustomLangPack() = default;
~CustomLangPack() override = default;
QNetworkAccessManager networkManager;
QNetworkReply *_chkReply = nullptr;
QNetworkReply* _chkReply = nullptr;
bool needFallback = false;
};

View file

@ -12,7 +12,8 @@
using json = nlohmann::json;
namespace AyuSettings {
namespace AyuSettings
{
const QString filename = "tdata/ayu_settings.json";
std::optional<AyuGramSettings> settings = std::nullopt;
@ -29,43 +30,55 @@ namespace AyuSettings {
rpl::lifetime lifetime = rpl::lifetime();
bool ghostModeEnabled_util(AyuGramSettings &settingsUtil) {
bool ghostModeEnabled_util(AyuGramSettings& settingsUtil)
{
return (!settingsUtil.sendReadPackets
&& !settingsUtil.sendOnlinePackets
&& !settingsUtil.sendUploadProgress
&& settingsUtil.sendOfflinePacketAfterOnline);
}
void initialize() {
if (settings.has_value()) {
void initialize()
{
if (settings.has_value())
{
return;
}
settings = AyuGramSettings();
sendReadPacketsReactive.value() | rpl::filter([=](bool val) {
sendReadPacketsReactive.value() | rpl::filter([=](bool val)
{
return (val != settings->sendReadPackets);
}) | rpl::start_with_next([=](bool val) {
}) | start_with_next([=](bool val)
{
ghostModeEnabled = ghostModeEnabled_util(settings.value());
}, lifetime);
sendOnlinePacketsReactive.value() | rpl::filter([=](bool val) {
sendOnlinePacketsReactive.value() | rpl::filter([=](bool val)
{
return (val != settings->sendOnlinePackets);
}) | rpl::start_with_next([=](bool val) {
}) | start_with_next([=](bool val)
{
ghostModeEnabled = ghostModeEnabled_util(settings.value());
}, lifetime);
sendUploadProgressReactive.value() | rpl::filter([=](bool val) {
sendUploadProgressReactive.value() | rpl::filter([=](bool val)
{
return (val != settings->sendUploadProgress);
}) | rpl::start_with_next([=](bool val) {
}) | start_with_next([=](bool val)
{
ghostModeEnabled = ghostModeEnabled_util(settings.value());
}, lifetime);
sendOfflinePacketAfterOnlineReactive.value() | rpl::filter([=](bool val) {
sendOfflinePacketAfterOnlineReactive.value() | rpl::filter([=](bool val)
{
return (val != settings->sendOfflinePacketAfterOnline);
}) | rpl::start_with_next([=](bool val) {
}) | start_with_next([=](bool val)
{
ghostModeEnabled = ghostModeEnabled_util(settings.value());
}, lifetime);
}
void postinitialize() {
void postinitialize()
{
sendReadPacketsReactive = settings->sendReadPackets;
sendOnlinePacketsReactive = settings->sendOnlinePackets;
@ -76,14 +89,17 @@ namespace AyuSettings {
ghostModeEnabled = ghostModeEnabled_util(settings.value());
}
AyuGramSettings &getInstance() {
AyuGramSettings& getInstance()
{
initialize();
return settings.value();
}
void load() {
void load()
{
QFile file(filename);
if (!file.exists()) {
if (!file.exists())
{
return;
}
file.open(QIODevice::ReadOnly);
@ -92,11 +108,12 @@ namespace AyuSettings {
initialize();
json p = json::parse(data);
settings = p.template get<AyuGramSettings>();
settings = p.get<AyuGramSettings>();
postinitialize();
}
void save() {
void save()
{
initialize();
json p = settings.value();
@ -109,102 +126,125 @@ namespace AyuSettings {
postinitialize();
}
void AyuGramSettings::set_sendReadPackets(bool val) {
void AyuGramSettings::set_sendReadPackets(bool val)
{
sendReadPackets = val;
sendReadPacketsReactive = val;
}
void AyuGramSettings::set_sendOnlinePackets(bool val) {
void AyuGramSettings::set_sendOnlinePackets(bool val)
{
sendOnlinePackets = val;
sendOnlinePacketsReactive = val;
}
void AyuGramSettings::set_sendUploadProgress(bool val) {
void AyuGramSettings::set_sendUploadProgress(bool val)
{
sendUploadProgress = val;
sendUploadProgressReactive = val;
}
void AyuGramSettings::set_sendOfflinePacketAfterOnline(bool val) {
void AyuGramSettings::set_sendOfflinePacketAfterOnline(bool val)
{
sendOfflinePacketAfterOnline = val;
sendOfflinePacketAfterOnlineReactive = val;
}
void AyuGramSettings::set_markReadAfterSend(bool val) {
void AyuGramSettings::set_markReadAfterSend(bool val)
{
markReadAfterSend = val;
}
void AyuGramSettings::set_useScheduledMessages(bool val) {
void AyuGramSettings::set_useScheduledMessages(bool val)
{
useScheduledMessages = val;
}
void AyuGramSettings::set_keepDeletedMessages(bool val) {
void AyuGramSettings::set_keepDeletedMessages(bool val)
{
keepDeletedMessages = val;
}
void AyuGramSettings::set_keepMessagesHistory(bool val) {
void AyuGramSettings::set_keepMessagesHistory(bool val)
{
keepMessagesHistory = val;
}
void AyuGramSettings::set_enableAds(bool val) {
void AyuGramSettings::set_enableAds(bool val)
{
enableAds = val;
}
void AyuGramSettings::set_deletedMark(QString val) {
void AyuGramSettings::set_deletedMark(QString val)
{
deletedMark = std::move(val);
deletedMarkReactive = deletedMark;
}
void AyuGramSettings::set_editedMark(QString val) {
void AyuGramSettings::set_editedMark(QString val)
{
editedMark = std::move(val);
editedMarkReactive = editedMark;
}
void AyuGramSettings::set_recentStickersCount(int val) {
void AyuGramSettings::set_recentStickersCount(int val)
{
recentStickersCount = val;
}
void AyuGramSettings::set_showGhostToggleInDrawer(bool val) {
void AyuGramSettings::set_showGhostToggleInDrawer(bool val)
{
showGhostToggleInDrawer = val;
}
void AyuGramSettings::set_showPeerId(int val) {
void AyuGramSettings::set_showPeerId(int val)
{
showPeerId = val;
showPeerIdReactive = val;
}
void AyuGramSettings::set_showMessageSeconds(bool val) {
void AyuGramSettings::set_showMessageSeconds(bool val)
{
showMessageSeconds = val;
}
void AyuGramSettings::set_stickerConfirmation(bool val) {
void AyuGramSettings::set_stickerConfirmation(bool val)
{
stickerConfirmation = val;
}
void AyuGramSettings::set_GIFConfirmation(bool val) {
void AyuGramSettings::set_GIFConfirmation(bool val)
{
GIFConfirmation = val;
}
void AyuGramSettings::set_voiceConfirmation(bool val) {
void AyuGramSettings::set_voiceConfirmation(bool val)
{
voiceConfirmation = val;
}
bool get_ghostModeEnabled() {
bool get_ghostModeEnabled()
{
return ghostModeEnabled.current();
}
rpl::producer<QString> get_deletedMarkReactive() {
rpl::producer<QString> get_deletedMarkReactive()
{
return deletedMarkReactive.value();
}
rpl::producer<QString> get_editedMarkReactive() {
rpl::producer<QString> get_editedMarkReactive()
{
return editedMarkReactive.value();
}
rpl::producer<int> get_showPeerIdReactive() {
rpl::producer<int> get_showPeerIdReactive()
{
return showPeerIdReactive.value();
}
rpl::producer<bool> get_ghostModeEnabledReactive() {
rpl::producer<bool> get_ghostModeEnabledReactive()
{
return ghostModeEnabled.value();
}
}

View file

@ -7,15 +7,18 @@
#pragma once
#include "rpl/producer.h"
#include "lang_auto.h"
#include "ayu/libs/json.hpp"
#include "ayu/libs/json_ext.hpp"
#include "rpl/producer.h"
namespace AyuSettings {
class AyuGramSettings {
namespace AyuSettings
{
class AyuGramSettings
{
public:
AyuGramSettings() {
AyuGramSettings()
{
// ~ Ghost essentials
sendReadPackets = true;
sendOnlinePackets = true;
@ -136,7 +139,7 @@ namespace AyuSettings {
voiceConfirmation
);
AyuGramSettings &getInstance();
AyuGramSettings& getInstance();
void load();

View file

@ -7,13 +7,16 @@
#include "ayu_state.h"
namespace AyuState {
void setAllowSendReadPacket(bool val, int resetAfter) {
namespace AyuState
{
void setAllowSendReadPacket(bool val, int resetAfter)
{
allowSendReadPacket.val = val;
allowSendReadPacket.resetAfter = resetAfter;
}
bool getAllowSendPacket() {
bool getAllowSendPacket()
{
auto settings = &AyuSettings::getInstance();
return settings->sendReadPackets || processVariable(allowSendReadPacket);
}

View file

@ -9,9 +9,12 @@
#include "ayu_settings.h"
namespace AyuState {
namespace {
class AyuStateVariable {
namespace AyuState
{
namespace
{
class AyuStateVariable
{
public:
bool val;
int resetAfter;
@ -19,15 +22,18 @@ namespace AyuState {
AyuStateVariable allowSendReadPacket;
bool processVariable(AyuStateVariable &variable) {
if (variable.resetAfter == -1) {
bool processVariable(AyuStateVariable& variable)
{
if (variable.resetAfter == -1)
{
return variable.val;
}
variable.resetAfter -= 1;
auto val = variable.val;
if (variable.resetAfter == 0) {
if (variable.resetAfter == 0)
{
variable.val = false;
}

View file

@ -27,16 +27,17 @@ auto storage = make_storage("ayugram.db",
);
namespace AyuDatabase {
namespace AyuDatabase
{
void addEditedMessage(
long userId,
long dialogId,
long messageId,
const QString &text,
const QString& text,
bool isDocument,
QString path,
long date) {
long date)
{
EditedMessage entity;
entity.userId = userId;
entity.dialogId = dialogId;
@ -57,8 +58,8 @@ namespace AyuDatabase {
long userId,
long dialogId,
long messageId
) {
)
{
return storage.get_all<EditedMessage>(
where(
c(&EditedMessage::userId) == userId and
@ -67,16 +68,18 @@ namespace AyuDatabase {
);
}
std::vector<EditedMessage> getEditedMessages(HistoryItem *item) {
std::vector<EditedMessage> getEditedMessages(HistoryItem* item)
{
auto userId = item->displayFrom()->id.value;
auto dialogId = item->history()->peer->id.value;
auto msgId = item->id.bare;
// auto some = &item->history()->session().account();
// auto some = &item->history()->session().account();
return getEditedMessages((long) userId, (long) dialogId, (long) msgId);
return getEditedMessages(static_cast<long>(userId), static_cast<long>(dialogId), static_cast<long>(msgId));
}
bool editedMessagesTableExists() {
bool editedMessagesTableExists()
{
return storage.table_exists("editedmessage");
}
}

View file

@ -8,15 +8,16 @@
#pragma once
#include "entities.h"
#include "history/history_item.h"
#include "history/history.h"
#include "history/history_item.h"
namespace AyuDatabase {
namespace AyuDatabase
{
void addEditedMessage(
long userId,
long dialogId,
long messageId,
const QString &text,
const QString& text,
bool isDocument,
QString path,
long date);
@ -27,7 +28,7 @@ namespace AyuDatabase {
long messageId
);
std::vector<EditedMessage> getEditedMessages(HistoryItem *item);
std::vector<EditedMessage> getEditedMessages(HistoryItem* item);
bool editedMessagesTableExists();
}

View file

@ -11,7 +11,8 @@
#include <string>
// https://github.com/AyuGram/AyuGram4A/blob/main/TMessagesProj/src/main/java/com/radolyn/ayugram/database/entities/EditedMessage.java
class EditedMessage {
class EditedMessage
{
public:
long userId;
long dialogId;

View file

@ -10,10 +10,12 @@
#include <QString>
#include "json.hpp"
inline void to_json(nlohmann::json &j, const QString &q) {
inline void to_json(nlohmann::json& j, const QString& q)
{
j = nlohmann::json(q.toStdString());
}
inline void from_json(const nlohmann::json &j, QString &q) {
inline void from_json(const nlohmann::json& j, QString& q)
{
q = QString::fromStdString(j.get<std::string>());
}

View file

@ -7,46 +7,55 @@
#include "ayu_sync_controller.h"
#include "ayu/libs/process.hpp"
#include "ayu/sync/utils/process_utils.hpp"
#include "ayu/sync/models.h"
#include "ayu/sync/utils/process_utils.hpp"
#include "ayu/sync/utils/telegram_helpers.h"
#include "data/data_session.h"
#include "history/history.h"
#include "ayu/sync/utils/telegram_helpers.h"
#include <QString>
#include <thread>
namespace AyuSync {
namespace AyuSync
{
std::optional<ayu_sync_controller> controller = std::nullopt;
bool isAgentDownloaded() {
bool isAgentDownloaded()
{
return std::filesystem::exists(AgentPath);
}
bool isAgentRunning() {
bool isAgentRunning()
{
return is_process_running(AgentFilename);
}
void initialize() {
if (controller.has_value()) {
void initialize()
{
if (controller.has_value())
{
return;
}
controller = ayu_sync_controller();
}
ayu_sync_controller &getControllerInstance() {
ayu_sync_controller& getControllerInstance()
{
initialize();
return controller.value();
}
void ayu_sync_controller::initializeAgent() {
if (!isAgentDownloaded()) {
void ayu_sync_controller::initializeAgent()
{
if (!isAgentDownloaded())
{
return;
}
if (!isAgentRunning()) {
if (!isAgentRunning())
{
auto configPath = std::filesystem::absolute("./tdata/sync_preferences.json");
auto process = nes::process{AgentPath, {configPath.string(), ""}, nes::process_options::none};
process.detach();
@ -56,12 +65,15 @@ namespace AyuSync {
receiverThread.detach();
}
void ayu_sync_controller::receiver() {
void ayu_sync_controller::receiver()
{
pipe = std::make_unique<ayu_pipe_wrapper>();
while (true) {
while (true)
{
auto p = pipe->receive();
if (p == std::nullopt) {
if (p == std::nullopt)
{
continue;
}
@ -72,7 +84,8 @@ namespace AyuSync {
}
}
void ayu_sync_controller::invokeHandler(json p) {
void ayu_sync_controller::invokeHandler(json p)
{
LOG(("Invoking handler on %1").arg(p.dump().c_str()));
auto userId = p["userId"].get<long>();
@ -82,34 +95,43 @@ namespace AyuSync {
// todo: check if account exists
if (type == "sync_force") {
if (type == "sync_force")
{
auto ev = p.template get<SyncForce>();
onSyncForce(ev);
} else if (type == "sync_batch") {
}
else if (type == "sync_batch")
{
onSyncBatch(p);
} else if (type == "sync_read") {
}
else if (type == "sync_read")
{
auto ev = p.template get<SyncRead>();
onSyncRead(ev);
} else {
}
else
{
LOG(("Unknown sync type: %1").arg(type.c_str()));
}
}
void ayu_sync_controller::onSyncForce(SyncForce ev) {
void ayu_sync_controller::onSyncForce(SyncForce ev)
{
}
void ayu_sync_controller::onSyncBatch(json ev) {
void ayu_sync_controller::onSyncBatch(json ev)
{
}
void ayu_sync_controller::onSyncRead(SyncRead ev) {
void ayu_sync_controller::onSyncRead(SyncRead ev)
{
auto session = getSession(ev.userId);
auto peer = PeerId(abs(ev.args.dialogId));
auto history = session->data().history(peer);
if (history) {
if (history)
{
history->inboxRead(ev.args.untilId, ev.args.unread);
}
}

View file

@ -7,8 +7,8 @@
#pragma once
#include "ayu/libs/json.hpp"
#include "models.h"
#include "ayu/libs/json.hpp"
#include "utils/ayu_pipe_wrapper.h"
using json = nlohmann::json;
@ -22,8 +22,10 @@ const std::string AgentFilename =
const std::string AgentPath = "./AyuSync/" + AgentFilename;
namespace AyuSync {
class ayu_sync_controller {
namespace AyuSync
{
class ayu_sync_controller
{
public:
void initializeAgent();
@ -32,13 +34,14 @@ namespace AyuSync {
void onSyncRead(SyncRead ev);
void invokeHandler(json p);
private:
void receiver();
std::unique_ptr<ayu_pipe_wrapper> pipe;
};
ayu_sync_controller &getControllerInstance();
ayu_sync_controller& getControllerInstance();
bool isAgentDownloaded();
bool isAgentRunning();

View file

@ -1,20 +1,25 @@
#pragma once
#include "ayu/libs/json.hpp"
#include <string>
#include <vector>
class SyncEvent {
class SyncEvent
{
public:
std::string type = "sync_unspecified";
long userId = 0;
};
class SyncBatch : public SyncEvent {
class SyncBatch : public SyncEvent
{
public:
std::string type = "sync_batch";
long userId;
class SyncBatchArgs {
class SyncBatchArgs
{
public:
std::vector<SyncEvent> events;
};
@ -22,12 +27,14 @@ public:
SyncBatchArgs args;
};
class SyncRead : public SyncEvent {
class SyncRead : public SyncEvent
{
public:
std::string type = "sync_read";
long userId;
class SyncReadArgs {
class SyncReadArgs
{
public:
long dialogId;
int untilId;
@ -37,12 +44,14 @@ public:
SyncReadArgs args;
};
class SyncForce : public SyncEvent {
class SyncForce : public SyncEvent
{
public:
std::string type = "sync_force";
long userId;
class SyncForceArgs {
class SyncForceArgs
{
public:
int fromDate;
};
@ -50,12 +59,14 @@ public:
SyncForceArgs args;
};
class SyncForceFinish : public SyncEvent {
class SyncForceFinish : public SyncEvent
{
public:
std::string type = "sync_force_finish";
long userId;
class SyncForceFinishArgs {
class SyncForceFinishArgs
{
public:
short dummy; // required to be JSON serializable
};
@ -73,4 +84,3 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncForce::SyncForceArgs, fromDate)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncForce, type, userId, args)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncForceFinish::SyncForceFinishArgs, dummy)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncForceFinish, type, userId, args)

View file

@ -5,25 +5,28 @@
//
// Copyright @Radolyn, 2023
#include <sstream>
#include "ayu_pipe_wrapper.h"
#include <sstream>
#include "ayu/libs/bit_converter.hpp"
template<class T>
void ayu_pipe_wrapper::send(T obj) {
// auto s = json(obj).dump();
// auto length = s.length();
// char lengthBuff[4];
// bit_converter::i32_to_bytes(length, false, lengthBuff);
//
// os.write(lengthBuff, 4);
// os.write(s.c_str(), length);
// os.flush();
template <class T>
void ayu_pipe_wrapper::send(T obj)
{
// auto s = json(obj).dump();
// auto length = s.length();
// char lengthBuff[4];
// bit_converter::i32_to_bytes(length, false, lengthBuff);
//
// os.write(lengthBuff, 4);
// os.write(s.c_str(), length);
// os.flush();
throw std::logic_error("not implemented");
}
std::optional<json> ayu_pipe_wrapper::receive() {
if (!is.is_open()) {
std::optional<json> ayu_pipe_wrapper::receive()
{
if (!is.is_open())
{
return std::nullopt;
}
@ -32,15 +35,17 @@ std::optional<json> ayu_pipe_wrapper::receive() {
auto length = bit_converter::bytes_to_i32(lengthBuff, false);
if (length <= 0) {
if (length <= 0)
{
return std::nullopt;
}
auto sb = std::stringbuf();
char buff[4096];
while (length > 0) {
auto readSize = std::min(length, (int) sizeof(buff));
while (length > 0)
{
auto readSize = std::min(length, static_cast<int>(sizeof(buff)));
is.read(buff, readSize);
sb.sputn(buff, readSize);
length -= readSize;

View file

@ -13,9 +13,10 @@
using json = nlohmann::json;
class ayu_pipe_wrapper {
class ayu_pipe_wrapper
{
public:
template<class T>
template <class T>
void send(T obj);
std::optional<json> receive();

View file

@ -1,14 +1,14 @@
#include <algorithm>
#include <codecvt>
#include <iostream>
#include <locale>
#include <string>
#include <vector>
#include <algorithm>
#include <locale>
#include <codecvt>
#ifdef _WIN32
#include <windows.h>
#include <tlhelp32.h>
#include <windows.h>
#else
#include <dirent.h>
@ -17,31 +17,37 @@
// A function to check if a process is running by its name
// Bing AI generated
bool is_process_running(const std::string &name) {
bool is_process_running(const std::string& name)
{
#ifdef _WIN32
// Create a snapshot of all processes
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshot == INVALID_HANDLE_VALUE) {
if (snapshot == INVALID_HANDLE_VALUE)
{
std::cerr << "Failed to create snapshot\n";
return false;
}
// Iterate over the processes and compare the names
PROCESSENTRY32 entry;
entry.dwSize = sizeof(entry);
if (!Process32First(snapshot, &entry)) {
if (!Process32First(snapshot, &entry))
{
std::cerr << "Failed to get first process\n";
CloseHandle(snapshot);
return false;
}
do {
do
{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::string entry_name = converter.to_bytes(entry.szExeFile);
if (name == entry_name) {
if (name == entry_name)
{
// Found a match
CloseHandle(snapshot);
return true;
}
} while (Process32Next(snapshot, &entry));
}
while (Process32Next(snapshot, &entry));
// No match found
CloseHandle(snapshot);
return false;

View file

@ -8,10 +8,14 @@
#include "telegram_helpers.h"
#include "data/data_peer_id.h"
Main::Session* getSession(long userId) {
for (auto &[index, account] : Core::App().domain().accounts()) {
if (const auto session = account->maybeSession()) {
if (session->userId().bare == userId) {
Main::Session* getSession(long userId)
{
for (auto& [index, account] : Core::App().domain().accounts())
{
if (const auto session = account->maybeSession())
{
if (session->userId().bare == userId)
{
return session;
}
}
@ -20,7 +24,8 @@ Main::Session* getSession(long userId) {
return nullptr;
}
PeerId dialogIdToPeerId(long dialogId) {
PeerId dialogIdToPeerId(long dialogId)
{
auto peerId = PeerId();
return peerId;
}

View file

@ -9,7 +9,7 @@
#include "core/application.h"
#include "main/main_account.h"
#include "main/main_session.h"
#include "main/main_domain.h"
#include "main/main_session.h"
Main::Session* getSession(long userId);

View file

@ -6,24 +6,27 @@
// Copyright @Radolyn, 2023
#include "confirmation_box.h"
#include "ayu/ayu_settings.h"
#include "window/window_session_controller.h"
#include "main/main_session.h"
#include "data/data_session.h"
#include "window/window_peer_menu.h"
#include "styles/style_layers.h"
#include "lang_auto.h"
#include "ayu/ayu_settings.h"
#include "data/data_session.h"
#include "main/main_session.h"
#include "styles/style_layers.h"
#include "ui/text/text_utilities.h"
#include "window/window_peer_menu.h"
#include "window/window_session_controller.h"
namespace AyuUi {
namespace AyuUi
{
ConfirmationBox::ConfirmationBox(
QWidget *,
not_null<Window::SessionController *> controller) : _controller(controller) {
QWidget*,
not_null<Window::SessionController*> controller) : _controller(controller)
{
//
}
void ConfirmationBox::prepare() {
// setTitle(rpl::single(QString("Confirmation for SRead")));
void ConfirmationBox::prepare()
{
// setTitle(rpl::single(QString("Confirmation for SRead")));
auto details = TextWithEntities();
details.text = QString("Do you want to read all messages?");
@ -35,21 +38,24 @@ namespace AyuUi {
setDimensions(st::boxWidth, fullHeight);
addButton(rpl::single(QString("Read")), [=, this] {
addButton(rpl::single(QString("Read")), [=, this]
{
ReadAllPeers();
closeBox();
});
addButton(tr::lng_cancel(), [=, this] { closeBox(); });
}
void ConfirmationBox::resizeEvent(QResizeEvent *e) {
void ConfirmationBox::resizeEvent(QResizeEvent* e)
{
BoxContent::resizeEvent(e);
const auto &padding = st::boxPadding;
const auto& padding = st::boxPadding;
_text->moveToLeft(padding.left(), padding.top());
}
void ConfirmationBox::ReadAllPeers() {
void ConfirmationBox::ReadAllPeers()
{
auto settings = &AyuSettings::getInstance();
auto prev = settings->sendReadPackets;
settings->set_sendReadPackets(true);

View file

@ -8,20 +8,22 @@
#include "ui/layers/box_content.h"
#include "window/window_main_menu.h"
namespace AyuUi {
class ConfirmationBox : public Ui::BoxContent {
namespace AyuUi
{
class ConfirmationBox : public Ui::BoxContent
{
public:
ConfirmationBox(QWidget *, not_null<Window::SessionController *> controller);
ConfirmationBox(QWidget*, not_null<Window::SessionController*> controller);
protected:
void prepare() override;
void resizeEvent(QResizeEvent *e) override;
void resizeEvent(QResizeEvent* e) override;
private:
void ReadAllPeers();
not_null<Window::SessionController *> _controller;
not_null<Window::SessionController*> _controller;
object_ptr<Ui::FlatLabel> _text = {nullptr};
};
}

View file

@ -7,36 +7,38 @@
#include "edit_deleted_mark.h"
#include "lang/lang_keys.h"
#include "base/random.h"
#include "boxes/peer_list_controllers.h"
#include "boxes/premium_limits_box.h"
#include "data/data_cloud_file.h"
#include "lang/lang_keys.h"
#include "main/main_session.h"
#include "styles/style_boxes.h"
#include "styles/style_layers.h"
#include "styles/style_widgets.h"
#include "ui/ui_utility.h"
#include "ui/unread_badge.h"
#include "ui/controls/userpic_button.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/fields/special_fields.h"
#include "ui/widgets/popup_menu.h"
#include "ui/unread_badge.h"
#include "ui/ui_utility.h"
#include "data/data_cloud_file.h"
#include "main/main_session.h"
#include "styles/style_layers.h"
#include "styles/style_boxes.h"
#include "styles/style_widgets.h"
#include "ui/widgets/fields/special_fields.h"
#include <QtGui/QGuiApplication>
#include "storage/localstorage.h"
#include "ayu/ayu_settings.h"
EditDeletedMarkBox::EditDeletedMarkBox(QWidget *) :
EditDeletedMarkBox::EditDeletedMarkBox(QWidget*) :
_text(
this,
st::defaultInputField,
rpl::single(QString("Deleted Mark")),
AyuSettings::getInstance().deletedMark) {
AyuSettings::getInstance().deletedMark)
{
}
void EditDeletedMarkBox::prepare() {
void EditDeletedMarkBox::prepare()
{
const auto defaultDeletedMark = "🧹";
auto newHeight = st::contactPadding.top() + _text->height();
@ -53,20 +55,26 @@ void EditDeletedMarkBox::prepare() {
connect(_text, &Ui::InputField::submitted, [=] { submit(); });
}
void EditDeletedMarkBox::setInnerFocus() {
void EditDeletedMarkBox::setInnerFocus()
{
_text->setFocusFast();
}
void EditDeletedMarkBox::submit() {
if (_text->getLastText().trimmed().isEmpty()) {
void EditDeletedMarkBox::submit()
{
if (_text->getLastText().trimmed().isEmpty())
{
_text->setFocus();
_text->showError();
} else {
}
else
{
save();
}
}
void EditDeletedMarkBox::resizeEvent(QResizeEvent *e) {
void EditDeletedMarkBox::resizeEvent(QResizeEvent* e)
{
BoxContent::resizeEvent(e);
_text->resize(
@ -80,7 +88,8 @@ void EditDeletedMarkBox::resizeEvent(QResizeEvent *e) {
_text->moveToLeft(left, st::contactPadding.top());
}
void EditDeletedMarkBox::save() {
void EditDeletedMarkBox::save()
{
const auto settings = &AyuSettings::getInstance();
settings->set_deletedMark(_text->getLastText());
AyuSettings::save();

View file

@ -7,20 +7,21 @@
#pragma once
#include "boxes/abstract_box.h"
#include "base/timer.h"
#include "boxes/abstract_box.h"
#include "mtproto/sender.h"
class EditDeletedMarkBox : public Ui::BoxContent {
class EditDeletedMarkBox : public Ui::BoxContent
{
public:
EditDeletedMarkBox(QWidget *);
EditDeletedMarkBox(QWidget*);
protected:
void setInnerFocus() override;
void prepare() override;
void resizeEvent(QResizeEvent *e) override;
void resizeEvent(QResizeEvent* e) override;
private:
void submit();

View file

@ -7,38 +7,39 @@
#include "edit_edited_mark.h"
#include "lang/lang_keys.h"
#include "base/random.h"
#include "boxes/peer_list_controllers.h"
#include "boxes/premium_limits_box.h"
#include "data/data_cloud_file.h"
#include "lang/lang_keys.h"
#include "main/main_session.h"
#include "styles/style_boxes.h"
#include "styles/style_layers.h"
#include "styles/style_widgets.h"
#include "ui/ui_utility.h"
#include "ui/unread_badge.h"
#include "ui/controls/userpic_button.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/fields/special_fields.h"
#include "ui/widgets/popup_menu.h"
#include "ui/unread_badge.h"
#include "ui/ui_utility.h"
#include "data/data_cloud_file.h"
#include "main/main_session.h"
#include "styles/style_layers.h"
#include "styles/style_boxes.h"
#include "styles/style_widgets.h"
#include "ui/widgets/fields/special_fields.h"
#include <QtGui/QGuiApplication>
#include "storage/localstorage.h"
#include "ayu/ayu_settings.h"
EditEditedMarkBox::EditEditedMarkBox(QWidget *) :
EditEditedMarkBox::EditEditedMarkBox(QWidget*) :
_text(
this,
st::defaultInputField,
rpl::single(QString("Edited mark")),
AyuSettings::getInstance().editedMark) {
AyuSettings::getInstance().editedMark)
{
}
void EditEditedMarkBox::prepare() {
void EditEditedMarkBox::prepare()
{
const auto defaultEditedMark = tr::lng_edited(tr::now);
auto newHeight = st::contactPadding.top() + _text->height();
@ -55,20 +56,26 @@ void EditEditedMarkBox::prepare() {
}
void EditEditedMarkBox::setInnerFocus() {
void EditEditedMarkBox::setInnerFocus()
{
_text->setFocusFast();
}
void EditEditedMarkBox::submit() {
if (_text->getLastText().trimmed().isEmpty()) {
void EditEditedMarkBox::submit()
{
if (_text->getLastText().trimmed().isEmpty())
{
_text->setFocus();
_text->showError();
} else {
}
else
{
save();
}
}
void EditEditedMarkBox::resizeEvent(QResizeEvent *e) {
void EditEditedMarkBox::resizeEvent(QResizeEvent* e)
{
BoxContent::resizeEvent(e);
_text->resize(
@ -82,7 +89,8 @@ void EditEditedMarkBox::resizeEvent(QResizeEvent *e) {
_text->moveToLeft(left, st::contactPadding.top());
}
void EditEditedMarkBox::save() {
void EditEditedMarkBox::save()
{
const auto settings = &AyuSettings::getInstance();
settings->set_editedMark(_text->getLastText());
AyuSettings::save();

View file

@ -7,20 +7,21 @@
#pragma once
#include "boxes/abstract_box.h"
#include "base/timer.h"
#include "boxes/abstract_box.h"
#include "mtproto/sender.h"
class EditEditedMarkBox : public Ui::BoxContent {
class EditEditedMarkBox : public Ui::BoxContent
{
public:
EditEditedMarkBox(QWidget *);
EditEditedMarkBox(QWidget*);
protected:
void setInnerFocus() override;
void prepare() override;
void resizeEvent(QResizeEvent *e) override;
void resizeEvent(QResizeEvent* e) override;
private:
void submit();

View file

@ -6,51 +6,65 @@
// Copyright @Radolyn, 2023
#include "ui/boxes/confirm_box.h"
#include "lang/lang_keys.h"
#include "ui/widgets/buttons.h"
#include "styles/style_layers.h"
#include "voice_confirmation_box.h"
#include "lang/lang_keys.h"
#include "styles/style_layers.h"
#include "ui/widgets/buttons.h"
namespace AyuUi {
void VoiceConfirmBox(not_null<Ui::GenericBox *> box, Ui::ConfirmBoxArgs &&args) {
const auto weak = Ui::MakeWeak(box);
namespace AyuUi
{
void VoiceConfirmBox(not_null<Ui::GenericBox*> box, Ui::ConfirmBoxArgs&& args)
{
const auto weak = MakeWeak(box);
const auto lifetime = box->lifetime().make_state<rpl::lifetime>();
v::match(args.text, [](v::null_t) {
}, [&](auto &&) {
v::match(args.text, [](v::null_t)
{
}, [&](auto&&)
{
const auto label = box->addRow(
object_ptr<Ui::FlatLabel>(
box.get(),
v::text::take_marked(std::move(args.text)),
args.labelStyle ? *args.labelStyle : st::boxLabel),
st::boxPadding);
if (args.labelFilter) {
if (args.labelFilter)
{
label->setClickHandlerFilter(std::move(args.labelFilter));
}
});
const auto prepareCallback = [&](Ui::ConfirmBoxArgs::Callback &callback) {
return [=, confirmed = std::move(callback)]() {
if (const auto callbackPtr = std::get_if<1>(&confirmed)) {
if (auto callback = (*callbackPtr)) {
const auto prepareCallback = [&](Ui::ConfirmBoxArgs::Callback& callback)
{
return [=, confirmed = std::move(callback)]()
{
if (const auto callbackPtr = std::get_if<1>(&confirmed))
{
if (auto callback = (*callbackPtr))
{
callback();
}
} else if (const auto callbackPtr = std::get_if<2>(&confirmed)) {
if (auto callback = (*callbackPtr)) {
}
else if (const auto callbackPtr = std::get_if<2>(&confirmed))
{
if (auto callback = (*callbackPtr))
{
callback(crl::guard(weak, [=] { weak->closeBox(); }));
}
} else if (weak) {
}
else if (weak)
{
weak->closeBox();
}
};
};
const auto &defaultButtonStyle = box->getDelegate()->style().button;
const auto& defaultButtonStyle = box->getDelegate()->style().button;
const auto confirmButton = box->addButton(
v::text::take_plain(std::move(args.confirmText), tr::lng_box_ok()),
[=, c = prepareCallback(args.confirmed)]() {
[=, c = prepareCallback(args.confirmed)]()
{
lifetime->destroy();
c();
@ -58,45 +72,53 @@ namespace AyuUi {
},
args.confirmStyle ? *args.confirmStyle : defaultButtonStyle);
box->events(
) | rpl::start_with_next([=](not_null<QEvent *> e) {
if ((e->type() != QEvent::KeyPress) || !confirmButton) {
) | start_with_next([=](not_null<QEvent*> e)
{
if ((e->type() != QEvent::KeyPress) || !confirmButton)
{
return;
}
const auto k = static_cast<QKeyEvent *>(e.get());
if (k->key() == Qt::Key_Enter || k->key() == Qt::Key_Return) {
const auto k = static_cast<QKeyEvent*>(e.get());
if (k->key() == Qt::Key_Enter || k->key() == Qt::Key_Return)
{
confirmButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton);
}
}, box->lifetime());
if (!args.inform) {
if (!args.inform)
{
const auto cancelButton = box->addButton(
v::text::take_plain(std::move(args.cancelText), tr::lng_cancel()),
crl::guard(weak, [=, c = prepareCallback(args.cancelled)]() {
crl::guard(weak, [=, c = prepareCallback(args.cancelled)]()
{
lifetime->destroy();
c();
}),
args.cancelStyle ? *args.cancelStyle : defaultButtonStyle);
box->boxClosing(
) | rpl::start_with_next(crl::guard(cancelButton, [=] {
) | start_with_next(crl::guard(cancelButton, [=]
{
cancelButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton);
}), *lifetime);
}
if (args.strictCancel) {
if (args.strictCancel)
{
lifetime->destroy();
}
}
object_ptr<Ui::GenericBox> MakeConfirmBox(Ui::ConfirmBoxArgs &&args) {
object_ptr<Ui::GenericBox> MakeConfirmBox(Ui::ConfirmBoxArgs&& args)
{
return Box(VoiceConfirmBox, std::move(args));
}
object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text) {
object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text)
{
return MakeConfirmBox({
.text = std::move(text),
.inform = true,
});
}
} // namespace AyuUi

View file

@ -6,16 +6,16 @@
// Copyright @Radolyn, 2023
#pragma once
#include "ui/boxes/confirm_box.h"
#include "ui/layers/generic_box.h"
#include "ui/text/text_variant.h"
#include "ui/boxes/confirm_box.h"
namespace AyuUi {
void VoiceConfirmBox(not_null<Ui::GenericBox *> box, Ui::ConfirmBoxArgs &&args);
namespace AyuUi
{
void VoiceConfirmBox(not_null<Ui::GenericBox*> box, Ui::ConfirmBoxArgs&& args);
[[nodiscard]] object_ptr<Ui::GenericBox> MakeConfirmBox(
Ui::ConfirmBoxArgs &&args);
Ui::ConfirmBoxArgs&& args);
[[nodiscard]] object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text);
} // namespace Ui

View file

@ -6,34 +6,41 @@
// Copyright @Radolyn, 2023
#include "context_menu.h"
#include "history/history_inner_widget.h"
#include "lang_auto.h"
#include "ui/widgets/popup_menu.h"
#include "base/unixtime.h"
#include "styles/style_chat.h"
#include "settings/settings_common.h"
#include "message_history_box.h"
#include "ayu/database/ayu_database.h"
#include "ayu/ayu_state.h"
#include "ayu/database/ayu_database.h"
#include "base/unixtime.h"
#include "history/history_inner_widget.h"
#include "settings/settings_common.h"
#include "styles/style_chat.h"
#include "ui/widgets/popup_menu.h"
namespace AyuUi {
AyuPopupMenu::AyuPopupMenu(HistoryInner *parent) {
namespace AyuUi
{
AyuPopupMenu::AyuPopupMenu(HistoryInner* parent)
{
_ayuSubMenu = std::make_unique<Ui::PopupMenu>(parent, st::popupMenuWithIcons);
}
void AyuPopupMenu::addHistoryAction(HistoryItem *item) {
if (AyuDatabase::editedMessagesTableExists() && !((AyuDatabase::getEditedMessages(item)).empty())) {
_ayuSubMenu->addAction(tr::ayu_EditsHistoryMenuText(tr::now), [=] {
void AyuPopupMenu::addHistoryAction(HistoryItem* item)
{
if (AyuDatabase::editedMessagesTableExists() && !((AyuDatabase::getEditedMessages(item)).empty()))
{
_ayuSubMenu->addAction(tr::ayu_EditsHistoryMenuText(tr::now), [=]
{
auto box = Box<MessageHistoryBox>(item);
Ui::show(std::move(box));
show(std::move(box));
}, &st::menuIconInfo);
}
}
void AyuPopupMenu::addHideMessageAction(HistoryItem *item) const {
void AyuPopupMenu::addHideMessageAction(HistoryItem* item) const
{
const auto settings = &AyuSettings::getInstance();
const auto history = item->history();
_ayuSubMenu->addAction(QString("Hide"), [=]() {
_ayuSubMenu->addAction(QString("Hide"), [=]()
{
const auto initKeepDeleted = settings->keepDeletedMessages;
settings->set_keepDeletedMessages(false);
@ -42,9 +49,11 @@ namespace AyuUi {
}, &st::menuIconClear);
}
void AyuPopupMenu::addReadUntilAction(HistoryItem *item) const {
void AyuPopupMenu::addReadUntilAction(HistoryItem* item) const
{
const auto history = item->history();
_ayuSubMenu->addAction(tr::ayu_ReadUntilMenuText(tr::now), [=]() {
_ayuSubMenu->addAction(tr::ayu_ReadUntilMenuText(tr::now), [=]()
{
AyuState::setAllowSendReadPacket(true);
history->session().data().histories().readInboxOnNewMessage(item);
}, &st::menuIconShowInChat);

View file

@ -7,93 +7,93 @@
#pragma once
#include "history/history_inner_widget.h"
#include "ui/widgets/popup_menu.h"
#include "ui/image/image.h"
#include "ui/effects/path_shift_gradient.h"
#include "ui/effects/message_sending_animation_controller.h"
#include "ui/effects/reaction_fly_animation.h"
#include "ui/text/text_options.h"
#include "ui/text/text_entity.h"
#include "ui/boxes/report_box.h"
#include "ui/layers/generic_box.h"
#include "ui/controls/delete_message_context_action.h"
#include "ui/controls/who_reacted_context_action.h"
#include "ui/painter.h"
#include "ui/ui_utility.h"
#include "ui/cached_round_corners.h"
#include "ui/inactive_press.h"
#include "window/window_adaptive.h"
#include "window/window_session_controller.h"
#include "window/window_controller.h"
#include "window/window_peer_menu.h"
#include "window/window_controller.h"
#include "window/notifications_manager.h"
#include "boxes/about_sponsored_box.h"
#include "boxes/delete_messages_box.h"
#include "boxes/report_messages_box.h"
#include "boxes/sticker_set_box.h"
#include "boxes/premium_preview_box.h"
#include "boxes/translate_box.h"
#include "chat_helpers/message_field.h"
#include "chat_helpers/emoji_interactions.h"
#include "history/history_widget.h"
#include "history/view/history_view_translate_tracker.h"
#include "mainwindow.h"
#include "base/call_delayed.h"
#include "base/unixtime.h"
#include "base/platform/base_platform_info.h"
#include "base/qt/qt_common_adapters.h"
#include "base/qt/qt_key_modifiers.h"
#include "base/unixtime.h"
#include "base/call_delayed.h"
#include "mainwindow.h"
#include "boxes/about_sponsored_box.h"
#include "boxes/delete_messages_box.h"
#include "boxes/premium_preview_box.h"
#include "boxes/report_messages_box.h"
#include "boxes/sticker_set_box.h"
#include "boxes/translate_box.h"
#include "chat_helpers/emoji_interactions.h"
#include "chat_helpers/message_field.h"
#include "core/application.h"
#include "data/data_changes.h"
#include "data/data_channel.h"
#include "data/data_chat.h"
#include "data/data_document.h"
#include "data/data_file_click_handler.h"
#include "data/data_file_origin.h"
#include "data/data_forum_topic.h"
#include "data/data_histories.h"
#include "data/data_media_types.h"
#include "data/data_message_reactions.h"
#include "data/data_peer_values.h"
#include "data/data_photo.h"
#include "data/data_photo_media.h"
#include "data/data_poll.h"
#include "data/data_session.h"
#include "data/data_sponsored_messages.h"
#include "data/data_user.h"
#include "data/stickers/data_stickers.h"
#include "dialogs/ui/dialogs_video_userpic.h"
#include "history/history_inner_widget.h"
#include "history/history_widget.h"
#include "history/view/history_view_translate_tracker.h"
#include "lang/lang_keys.h"
#include "layout/layout_selection.h"
#include "main/main_session.h"
#include "main/main_session_settings.h"
#include "main/session/send_as_peers.h"
#include "menu/menu_item_download_files.h"
#include "core/application.h"
#include "lang/lang_keys.h"
#include "data/data_session.h"
#include "data/data_media_types.h"
#include "data/data_message_reactions.h"
#include "data/data_document.h"
#include "data/data_channel.h"
#include "data/data_forum_topic.h"
#include "data/data_poll.h"
#include "data/data_photo.h"
#include "data/data_photo_media.h"
#include "data/data_peer_values.h"
#include "data/data_chat.h"
#include "data/data_user.h"
#include "data/data_file_click_handler.h"
#include "data/data_file_origin.h"
#include "data/data_histories.h"
#include "data/data_changes.h"
#include "data/stickers/data_stickers.h"
#include "data/data_sponsored_messages.h"
#include "dialogs/ui/dialogs_video_userpic.h"
#include "settings/settings_premium.h"
#include "styles/style_chat.h"
#include "styles/style_window.h" // st::windowMinWidth
#include "styles/style_menu_icons.h"
#include "styles/style_window.h" // st::windowMinWidth
#include "ui/cached_round_corners.h"
#include "ui/inactive_press.h"
#include "ui/painter.h"
#include "ui/ui_utility.h"
#include "ui/boxes/report_box.h"
#include "ui/controls/delete_message_context_action.h"
#include "ui/controls/who_reacted_context_action.h"
#include "ui/effects/message_sending_animation_controller.h"
#include "ui/effects/path_shift_gradient.h"
#include "ui/effects/reaction_fly_animation.h"
#include "ui/image/image.h"
#include "ui/layers/generic_box.h"
#include "ui/text/text_entity.h"
#include "ui/text/text_options.h"
#include "ui/widgets/popup_menu.h"
#include "window/notifications_manager.h"
#include "window/window_adaptive.h"
#include "window/window_controller.h"
#include "window/window_controller.h"
#include "window/window_peer_menu.h"
#include "window/window_session_controller.h"
#include "history/view/history_view_context_menu.h"
#include <styles/style_info.h>
#include <ayu/ayu_settings.h>
#include <styles/style_info.h>
namespace AyuUi {
class AyuPopupMenu {
namespace AyuUi
{
class AyuPopupMenu
{
public:
AyuPopupMenu(HistoryInner *parent);
AyuPopupMenu(HistoryInner* parent);
void addHistoryAction(HistoryItem *item);
void addHistoryAction(HistoryItem* item);
void addHideMessageAction(HistoryItem *item) const;
void addHideMessageAction(HistoryItem* item) const;
void addReadUntilAction(HistoryItem *item) const;
void addReadUntilAction(HistoryItem* item) const;
std::unique_ptr<Ui::PopupMenu> _ayuSubMenu;
};
}

View file

@ -5,62 +5,71 @@
//
// Copyright @Radolyn, 2023
#include <styles/style_layers.h>
#include <styles/style_boxes.h>
#include <ui/effects/scroll_content_shadow.h>
#include <styles/style_settings.h>
#include "message_history_box.h"
#include "settings/settings_common.h"
#include <styles/style_boxes.h>
#include <styles/style_layers.h>
#include <styles/style_settings.h>
#include <ui/effects/scroll_content_shadow.h>
#include "ayu/ayu_settings.h"
#include "ayu/database/ayu_database.h"
#include "history/history.h"
#include "settings/settings_common.h"
using namespace Settings;
namespace AyuUi {
MessageHistoryBox::MessageHistoryBox(QWidget *, HistoryItem *item)
: _content(this), _scroll(base::make_unique_q<Ui::ScrollArea>(this, st::boxScroll)) {
namespace AyuUi
{
MessageHistoryBox::MessageHistoryBox(QWidget*, HistoryItem* item)
: _content(this), _scroll(base::make_unique_q<Ui::ScrollArea>(this, st::boxScroll))
{
setupControls();
addEditedMessagesToLayout(item);
}
void MessageHistoryBox::setupControls() {
void MessageHistoryBox::setupControls()
{
_content.create(this);
_content->resizeToWidth(st::boxWideWidth);
_content->moveToLeft(0, 0);
_content->heightValue(
) | rpl::start_to_stream(_contentHeight, _content->lifetime());
) | start_to_stream(_contentHeight, _content->lifetime());
_scroll->setOwnedWidget(
object_ptr<Ui::RpWidget>::fromRaw(_content));
object_ptr<RpWidget>::fromRaw(_content));
}
void MessageHistoryBox::resizeEvent(QResizeEvent *e) {
void MessageHistoryBox::resizeEvent(QResizeEvent* e)
{
_scroll->resize(width(), height() - st::boxPhotoPadding.top() - st::boxPadding.bottom());
_scroll->move(0, st::boxPadding.top());
if (_content) {
if (_content)
{
_content->resize(_scroll->width(), _content->height());
}
}
void MessageHistoryBox::prepare() {
void MessageHistoryBox::prepare()
{
setTitle(tr::ayu_EditsHistoryTitle());
// setDimensionsToContent(st::boxWideWidth, _content);
// setDimensionsToContent(st::boxWideWidth, _content);
setDimensions(st::boxWideWidth, 900);
Ui::SetupShadowsToScrollContent(this, _scroll, _contentHeight.events());
SetupShadowsToScrollContent(this, _scroll, _contentHeight.events());
}
void MessageHistoryBox::addEditedMessagesToLayout(HistoryItem *item) {
void MessageHistoryBox::addEditedMessagesToLayout(HistoryItem* item)
{
auto messages = AyuDatabase::getEditedMessages(item);
if (messages.empty()) {
if (messages.empty())
{
return;
}
for (const auto &message: messages) {
for (const auto& message : messages)
{
AddSkip(_content);
AddDividerText(_content, rpl::single(QString::fromStdString(message.text)));
AddSkip(_content);

View file

@ -6,24 +6,26 @@
// Copyright @Radolyn, 2023
#include <ui/layers/box_content.h>
#include "ui/wrap/vertical_layout.h"
#include "ui/widgets/scroll_area.h"
#include "history/history_item.h"
#include "ui/widgets/scroll_area.h"
#include "ui/wrap/vertical_layout.h"
namespace AyuUi {
class MessageHistoryBox : public Ui::BoxContent {
namespace AyuUi
{
class MessageHistoryBox : public Ui::BoxContent
{
public:
MessageHistoryBox(QWidget *, HistoryItem *item);
MessageHistoryBox(QWidget*, HistoryItem* item);
protected:
void prepare() override;
void resizeEvent(QResizeEvent *e) override;
void resizeEvent(QResizeEvent* e) override;
private:
void setupControls();
void addEditedMessagesToLayout(HistoryItem *item);
void addEditedMessagesToLayout(HistoryItem* item);
object_ptr<Ui::VerticalLayout> _content;
const base::unique_qptr<Ui::ScrollArea> _scroll;

View file

@ -5,46 +5,49 @@
//
// Copyright @Radolyn, 2023
#include "ayu/sync/ayu_sync_controller.h"
#include "ayu/ui/boxes/edit_edited_mark.h"
#include "ayu/ui/boxes/edit_deleted_mark.h"
#include "ayu/ayu_settings.h"
#include "settings_ayu.h"
#include "ayu/ayu_settings.h"
#include "ayu/sync/ayu_sync_controller.h"
#include "ayu/ui/boxes/edit_deleted_mark.h"
#include "ayu/ui/boxes/edit_edited_mark.h"
#include "apiwrap.h"
#include "lang_auto.h"
#include "mainwindow.h"
#include "api/api_blocked_peers.h"
#include "boxes/connection_box.h"
#include "core/application.h"
#include "data/data_session.h"
#include "lang/lang_instance.h"
#include "main/main_session.h"
#include "platform/platform_specific.h"
#include "settings/settings_common.h"
#include "ui/wrap/vertical_layout.h"
#include "storage/localstorage.h"
#include "styles/style_settings.h"
#include "ui/boxes/single_choice_box.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/checkbox.h"
#include "boxes/connection_box.h"
#include "platform/platform_specific.h"
#include "window/window_session_controller.h"
#include "lang/lang_instance.h"
#include "core/application.h"
#include "storage/localstorage.h"
#include "data/data_session.h"
#include "main/main_session.h"
#include "styles/style_settings.h"
#include "apiwrap.h"
#include "api/api_blocked_peers.h"
#include "ui/widgets/continuous_sliders.h"
#include "ui/boxes/single_choice_box.h"
#include "ui/wrap/vertical_layout.h"
#include "window/window_session_controller.h"
namespace Settings {
rpl::producer<QString> Ayu::title() {
namespace Settings
{
rpl::producer<QString> Ayu::title()
{
return tr::ayu_AyuPreferences();
}
Ayu::Ayu(
QWidget *parent,
not_null<Window::SessionController *> controller)
: Section(parent) {
QWidget* parent,
not_null<Window::SessionController*> controller)
: Section(parent)
{
setupContent(controller);
}
void Ayu::SetupGhostEssentials(not_null<Ui::VerticalLayout *> container) {
void Ayu::SetupGhostEssentials(not_null<Ui::VerticalLayout*> container)
{
auto settings = &AyuSettings::getInstance();
AddSubsectionTitle(container, tr::ayu_GhostEssentialsHeader());
@ -56,9 +59,11 @@ namespace Settings {
)->toggleOn(
rpl::single(settings->sendReadPackets)
)->toggledValue(
) | rpl::filter([=](bool enabled) {
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->sendReadPackets);
}) | rpl::start_with_next([=](bool enabled) {
}) | start_with_next([=](bool enabled)
{
settings->set_sendReadPackets(enabled);
AyuSettings::save();
}, container->lifetime());
@ -70,9 +75,11 @@ namespace Settings {
)->toggleOn(
rpl::single(settings->sendOnlinePackets)
)->toggledValue(
) | rpl::filter([=](bool enabled) {
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->sendOnlinePackets);
}) | rpl::start_with_next([=](bool enabled) {
}) | start_with_next([=](bool enabled)
{
settings->set_sendOnlinePackets(enabled);
AyuSettings::save();
}, container->lifetime());
@ -84,9 +91,11 @@ namespace Settings {
)->toggleOn(
rpl::single(settings->sendUploadProgress)
)->toggledValue(
) | rpl::filter([=](bool enabled) {
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->sendUploadProgress);
}) | rpl::start_with_next([=](bool enabled) {
}) | start_with_next([=](bool enabled)
{
settings->set_sendUploadProgress(enabled);
AyuSettings::save();
}, container->lifetime());
@ -98,9 +107,11 @@ namespace Settings {
)->toggleOn(
rpl::single(settings->sendOfflinePacketAfterOnline)
)->toggledValue(
) | rpl::filter([=](bool enabled) {
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->sendOfflinePacketAfterOnline);
}) | rpl::start_with_next([=](bool enabled) {
}) | start_with_next([=](bool enabled)
{
settings->set_sendOfflinePacketAfterOnline(enabled);
AyuSettings::save();
}, container->lifetime());
@ -112,9 +123,11 @@ namespace Settings {
)->toggleOn(
rpl::single(settings->markReadAfterSend)
)->toggledValue(
) | rpl::filter([=](bool enabled) {
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->markReadAfterSend);
}) | rpl::start_with_next([=](bool enabled) {
}) | start_with_next([=](bool enabled)
{
settings->set_markReadAfterSend(enabled);
AyuSettings::save();
}, container->lifetime());
@ -126,15 +139,18 @@ namespace Settings {
)->toggleOn(
rpl::single(settings->useScheduledMessages)
)->toggledValue(
) | rpl::filter([=](bool enabled) {
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->useScheduledMessages);
}) | rpl::start_with_next([=](bool enabled) {
}) | start_with_next([=](bool enabled)
{
settings->set_useScheduledMessages(enabled);
AyuSettings::save();
}, container->lifetime());
}
void Ayu::SetupSpyEssentials(not_null<Ui::VerticalLayout *> container) {
void Ayu::SetupSpyEssentials(not_null<Ui::VerticalLayout*> container)
{
auto settings = &AyuSettings::getInstance();
AddSubsectionTitle(container, tr::ayu_SpyEssentialsHeader());
@ -146,9 +162,11 @@ namespace Settings {
)->toggleOn(
rpl::single(settings->keepDeletedMessages)
)->toggledValue(
) | rpl::filter([=](bool enabled) {
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->keepDeletedMessages);
}) | rpl::start_with_next([=](bool enabled) {
}) | start_with_next([=](bool enabled)
{
settings->set_keepDeletedMessages(enabled);
AyuSettings::save();
}, container->lifetime());
@ -160,15 +178,18 @@ namespace Settings {
)->toggleOn(
rpl::single(settings->keepMessagesHistory)
)->toggledValue(
) | rpl::filter([=](bool enabled) {
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->keepMessagesHistory);
}) | rpl::start_with_next([=](bool enabled) {
}) | start_with_next([=](bool enabled)
{
settings->set_keepMessagesHistory(enabled);
AyuSettings::save();
}, container->lifetime());
}
void Ayu::SetupQoLToggles(not_null<Ui::VerticalLayout *> container) {
void Ayu::SetupQoLToggles(not_null<Ui::VerticalLayout*> container)
{
auto settings = &AyuSettings::getInstance();
AddSubsectionTitle(container, tr::ayu_QoLTogglesHeader());
@ -180,16 +201,19 @@ namespace Settings {
)->toggleOn(
rpl::single(settings->enableAds)
)->toggledValue(
) | rpl::filter([=](bool enabled) {
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->enableAds);
}) | rpl::start_with_next([=](bool enabled) {
}) | start_with_next([=](bool enabled)
{
settings->set_enableAds(enabled);
AyuSettings::save();
}, container->lifetime());
}
void Ayu::SetupCustomization(not_null<Ui::VerticalLayout *> container,
not_null<Window::SessionController *> controller) {
void Ayu::SetupCustomization(not_null<Ui::VerticalLayout*> container,
not_null<Window::SessionController*> controller)
{
auto settings = &AyuSettings::getInstance();
AddSubsectionTitle(container, tr::ayu_CustomizationHeader());
@ -200,7 +224,8 @@ namespace Settings {
AyuSettings::get_deletedMarkReactive(),
st::settingsButtonNoIcon
);
btn->addClickHandler([=]() {
btn->addClickHandler([=]()
{
auto box = Box<EditDeletedMarkBox>();
Ui::show(std::move(box));
});
@ -211,7 +236,8 @@ namespace Settings {
AyuSettings::get_editedMarkReactive(),
st::settingsButtonNoIcon
);
btn2->addClickHandler([=]() {
btn2->addClickHandler([=]()
{
auto box = Box<EditEditedMarkBox>();
Ui::show(std::move(box));
});
@ -227,9 +253,11 @@ namespace Settings {
)->toggleOn(
rpl::single(settings->showGhostToggleInDrawer)
)->toggledValue(
) | rpl::filter([=](bool enabled) {
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->showGhostToggleInDrawer);
}) | rpl::start_with_next([=](bool enabled) {
}) | start_with_next([=](bool enabled)
{
settings->set_showGhostToggleInDrawer(enabled);
AyuSettings::save();
}, container->lifetime());
@ -241,9 +269,11 @@ namespace Settings {
)->toggleOn(
rpl::single(settings->showMessageSeconds)
)->toggledValue(
) | rpl::filter([=](bool enabled) {
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->showMessageSeconds);
}) | rpl::start_with_next([=](bool enabled) {
}) | start_with_next([=](bool enabled)
{
settings->set_showMessageSeconds(enabled);
AyuSettings::save();
}, container->lifetime());
@ -251,8 +281,9 @@ namespace Settings {
AddDividerText(container, tr::ayu_SettingsCustomizationHint());
}
void Ayu::SetupShowPeerId(not_null<Ui::VerticalLayout *> container,
not_null<Window::SessionController *> controller) {
void Ayu::SetupShowPeerId(not_null<Ui::VerticalLayout*> container,
not_null<Window::SessionController*> controller)
{
auto settings = &AyuSettings::getInstance();
const auto options = std::vector{
@ -261,7 +292,8 @@ namespace Settings {
QString("Bot API")
};
auto currentVal = AyuSettings::get_showPeerIdReactive() | rpl::map([=](int val) {
auto currentVal = AyuSettings::get_showPeerIdReactive() | rpl::map([=](int val)
{
return options[val];
});
@ -270,9 +302,12 @@ namespace Settings {
tr::ayu_SettingsShowID(),
currentVal,
st::settingsButtonNoIcon);
button->addClickHandler([=] {
controller->show(Box([=](not_null<Ui::GenericBox *> box) {
const auto save = [=](int index) {
button->addClickHandler([=]
{
controller->show(Box([=](not_null<Ui::GenericBox*> box)
{
const auto save = [=](int index)
{
settings->set_showPeerId(index);
AyuSettings::save();
};
@ -286,7 +321,8 @@ namespace Settings {
});
}
void Ayu::SetupRecentStickersLimitSlider(not_null<Ui::VerticalLayout *> container) {
void Ayu::SetupRecentStickersLimitSlider(not_null<Ui::VerticalLayout*> container)
{
auto settings = &AyuSettings::getInstance();
container->add(
@ -308,7 +344,8 @@ namespace Settings {
const auto slider = recentStickersLimitSlider.slider;
const auto label = recentStickersLimitSlider.label;
const auto updateLabel = [=](int amount) {
const auto updateLabel = [=](int amount)
{
label->setText(QString::number(amount));
};
updateLabel(settings->recentStickersCount);
@ -318,7 +355,8 @@ namespace Settings {
[=](int amount) { return amount; },
settings->recentStickersCount,
[=](int amount) { updateLabel(amount); },
[=](int amount) {
[=](int amount)
{
updateLabel(amount);
settings->set_recentStickersCount(amount);
@ -326,24 +364,25 @@ namespace Settings {
});
}
void Ayu::SetupAyuSync(not_null<Ui::VerticalLayout *> container) {
void Ayu::SetupAyuSync(not_null<Ui::VerticalLayout*> container)
{
AddSubsectionTitle(container, rpl::single(QString("AyuSync")));
auto text = AyuSync::isAgentDownloaded() ?
QString("Open preferences") :
QString("Download agent");
auto text = AyuSync::isAgentDownloaded() ? QString("Open preferences") : QString("Download agent");
AddButton(
container,
rpl::single(text),
st::settingsButtonNoIcon
)->addClickHandler([=] {
)->addClickHandler([=]
{
auto controller = &AyuSync::getControllerInstance();
controller->initializeAgent();
});
}
void Ayu::SetupBetaFunctions(not_null<Ui::VerticalLayout *> container) {
void Ayu::SetupBetaFunctions(not_null<Ui::VerticalLayout*> container)
{
auto settings = &AyuSettings::getInstance();
AddSubsectionTitle(container, rpl::single(QString("Beta functions")));
@ -355,9 +394,11 @@ namespace Settings {
)->toggleOn(
rpl::single(settings->stickerConfirmation)
)->toggledValue(
) | rpl::filter([=](bool enabled) {
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->stickerConfirmation);
}) | rpl::start_with_next([=](bool enabled) {
}) | start_with_next([=](bool enabled)
{
settings->set_stickerConfirmation(enabled);
AyuSettings::save();
}, container->lifetime());
@ -369,9 +410,11 @@ namespace Settings {
)->toggleOn(
rpl::single(settings->GIFConfirmation)
)->toggledValue(
) | rpl::filter([=](bool enabled) {
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->GIFConfirmation);
}) | rpl::start_with_next([=](bool enabled) {
}) | start_with_next([=](bool enabled)
{
settings->set_GIFConfirmation(enabled);
AyuSettings::save();
}, container->lifetime());
@ -383,16 +426,19 @@ namespace Settings {
)->toggleOn(
rpl::single(settings->voiceConfirmation)
)->toggledValue(
) | rpl::filter([=](bool enabled) {
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->voiceConfirmation);
}) | rpl::start_with_next([=](bool enabled) {
}) | start_with_next([=](bool enabled)
{
settings->set_voiceConfirmation(enabled);
AyuSettings::save();
}, container->lifetime());
}
void Ayu::SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container,
not_null<Window::SessionController *> controller) {
void Ayu::SetupAyuGramSettings(not_null<Ui::VerticalLayout*> container,
not_null<Window::SessionController*> controller)
{
AddSkip(container);
SetupGhostEssentials(container);
@ -422,12 +468,12 @@ namespace Settings {
AddDividerText(container, tr::ayu_SettingsWatermark());
}
void Ayu::setupContent(not_null<Window::SessionController *> controller) {
void Ayu::setupContent(not_null<Window::SessionController*> controller)
{
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
SetupAyuGramSettings(content, controller);
Ui::ResizeFitChild(this, content);
ResizeFitChild(this, content);
}
} // namespace Settings

View file

@ -11,39 +11,42 @@
class BoxContent;
namespace Window {
namespace Window
{
class Controller;
class SessionController;
} // namespace Window
namespace Settings {
class Ayu : public Section<Ayu> {
namespace Settings
{
class Ayu : public Section<Ayu>
{
public:
Ayu(QWidget *parent, not_null<Window::SessionController *> controller);
Ayu(QWidget* parent, not_null<Window::SessionController*> controller);
[[nodiscard]] rpl::producer<QString> title() override;
private:
void SetupGhostEssentials(not_null<Ui::VerticalLayout *> container);
void SetupGhostEssentials(not_null<Ui::VerticalLayout*> container);
void SetupSpyEssentials(not_null<Ui::VerticalLayout *> container);
void SetupSpyEssentials(not_null<Ui::VerticalLayout*> container);
void SetupQoLToggles(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 SetupCustomization(not_null<Ui::VerticalLayout*> container,
not_null<Window::SessionController*> controller);
void SetupShowPeerId(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 SetupAyuSync(not_null<Ui::VerticalLayout *> container);
void SetupAyuSync(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);
};
} // namespace Settings

View file

@ -5,16 +5,17 @@
//
// Copyright @Radolyn, 2023
#include "ui/text/text_utilities.h"
#include "ayu/ayu_settings.h"
#include "ayu_profile_values.h"
#include "ayu/ayu_settings.h"
#include "data/data_peer.h"
#include "ui/text/text_utilities.h"
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)
@ -23,11 +24,15 @@ QString IDString(not_null<PeerData *> peer) {
? peerToChannel(peer->id).bare
: peer->id.value);
auto const settings = &AyuSettings::getInstance();
if (settings->showPeerId == 2) {
if (peer->isChannel()) {
const auto settings = &AyuSettings::getInstance();
if (settings->showPeerId == 2)
{
if (peer->isChannel())
{
resultId = QString::number(peerToChannel(peer->id).bare - kMaxChannelId).prepend("-");
} else if (peer->isChat()) {
}
else if (peer->isChat())
{
resultId = resultId.prepend("-");
}
}
@ -35,17 +40,20 @@ QString IDString(not_null<PeerData *> peer) {
return resultId;
}
QString IDString(MsgId topic_root_id) {
QString IDString(MsgId topic_root_id)
{
auto resultId = QString::number(topic_root_id.bare);
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();
}
rpl::producer<TextWithEntities> IDValue(MsgId topic_root_id) {
rpl::producer<TextWithEntities> IDValue(MsgId topic_root_id)
{
return rpl::single(IDString(topic_root_id)) | Ui::Text::ToWithEntities();
}

View file

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

View file

@ -481,11 +481,12 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
});
}
if (settings->showPeerId != 0) {
if (settings->showPeerId != 0)
{
auto idDrawableText = IDValue(
user
) | rpl::map([](TextWithEntities &&text) {
) | rpl::map([](TextWithEntities&& text)
{
return Ui::Text::Code(text.text);
});
auto idInfo = addInfoOneLine(
@ -494,9 +495,11 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
tr::ayu_ContextCopyID(tr::now)
);
idInfo.text->setClickHandlerFilter([=](auto &&...) {
idInfo.text->setClickHandlerFilter([=](auto&&...)
{
const auto idText = IDString(user);
if (!idText.isEmpty()) {
if (!idText.isEmpty())
{
QGuiApplication::clipboard()->setText(idText);
const auto msg = tr::ayu_IDCopiedToast(tr::now);
controller->showToast(msg);
@ -566,10 +569,12 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
addTranslateToMenu(about.text, AboutValue(_peer));
}
if (settings->showPeerId != 0 && !_topic) {
if (settings->showPeerId != 0 && !_topic)
{
auto idDrawableText = IDValue(
_peer
) | rpl::map([](TextWithEntities &&text) {
) | rpl::map([](TextWithEntities&& text)
{
return Ui::Text::Code(text.text);
});
auto idInfo = addInfoOneLine(
@ -578,9 +583,11 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
tr::ayu_ContextCopyID(tr::now)
);
idInfo.text->setClickHandlerFilter([=, peer = _peer](auto &&...) {
idInfo.text->setClickHandlerFilter([=, peer = _peer](auto&&...)
{
const auto idText = IDString(peer);
if (!idText.isEmpty()) {
if (!idText.isEmpty())
{
QGuiApplication::clipboard()->setText(idText);
const auto msg = tr::ayu_IDCopiedToast(tr::now);
controller->showToast(msg);
@ -589,11 +596,13 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
});
}
if (settings->showPeerId != 0 && _topic) {
if (settings->showPeerId != 0 && _topic)
{
const auto topicRootId = _topic->rootId();
auto idDrawableText = IDValue(
_peer->forumTopicFor(topicRootId)->topicRootId()
) | rpl::map([](TextWithEntities &&text) {
) | rpl::map([](TextWithEntities&& text)
{
return Ui::Text::Code(text.text);
});
auto idInfo = addInfoOneLine(
@ -602,9 +611,11 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
tr::ayu_ContextCopyID(tr::now)
);
idInfo.text->setClickHandlerFilter([=, peer = _peer](auto &&...) {
idInfo.text->setClickHandlerFilter([=, peer = _peer](auto&&...)
{
const auto idText = IDString(peer);
if (!idText.isEmpty()) {
if (!idText.isEmpty())
{
QGuiApplication::clipboard()->setText(idText);
const auto msg = tr::ayu_IDCopiedToast(tr::now);
controller->showToast(msg);