mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 21:27:07 +02:00
feat: reformat ayu files with resharper
This commit is contained in:
parent
85e8c75ad1
commit
32a2de1bef
35 changed files with 1866 additions and 1590 deletions
|
@ -8,127 +8,155 @@
|
|||
#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() {
|
||||
if (!instance)
|
||||
instance = new CustomLangPack;
|
||||
void CustomLangPack::initInstance()
|
||||
{
|
||||
if (!instance)
|
||||
instance = new CustomLangPack;
|
||||
}
|
||||
|
||||
CustomLangPack *CustomLangPack::currentInstance() {
|
||||
return instance;
|
||||
CustomLangPack* CustomLangPack::currentInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
void CustomLangPack::fetchCustomLangPack(const QString &langPackId, const QString &langPackBaseId) {
|
||||
LOG(("Current Language pack ID: %1, Base ID: %2").arg(langPackId, 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
|
||||
finalLangPackId = qsl("pt");
|
||||
}
|
||||
auto finalLangPackId = langPackId;
|
||||
if (finalLangPackId == qsl("pt-br"))
|
||||
{
|
||||
// meh
|
||||
finalLangPackId = qsl("pt");
|
||||
}
|
||||
|
||||
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));
|
||||
networkManager.setProxy(LocaleProxy);
|
||||
}
|
||||
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 = ToNetworkProxy(ToDirectIpProxy(proxy));
|
||||
networkManager.setProxy(LocaleProxy);
|
||||
}
|
||||
|
||||
QUrl url;
|
||||
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 {
|
||||
url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/Languages/l10n_main/values/langs/%1/Shared.json").arg(
|
||||
needFallback ? langPackBaseId : finalLangPackId));
|
||||
}
|
||||
_chkReply = networkManager.get(QNetworkRequest(url));
|
||||
connect(_chkReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(fetchError(QNetworkReply::NetworkError)));
|
||||
connect(_chkReply, SIGNAL(finished()), this, SLOT(fetchFinished()));
|
||||
LOG(("Fetching %1 lang pack...").arg(
|
||||
needFallback ? (langPackBaseId.isEmpty() ? finalLangPackId : langPackBaseId) : finalLangPackId));
|
||||
QUrl url;
|
||||
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
|
||||
{
|
||||
url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/Languages/l10n_main/values/langs/%1/Shared.json").arg(
|
||||
needFallback ? langPackBaseId : finalLangPackId));
|
||||
}
|
||||
_chkReply = networkManager.get(QNetworkRequest(url));
|
||||
connect(_chkReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(fetchError(QNetworkReply::NetworkError)));
|
||||
connect(_chkReply, SIGNAL(finished()), this, SLOT(fetchFinished()));
|
||||
LOG(("Fetching %1 lang pack...").arg(
|
||||
needFallback ? (langPackBaseId.isEmpty() ? finalLangPackId : langPackBaseId) : finalLangPackId));
|
||||
}
|
||||
|
||||
void CustomLangPack::fetchFinished() {
|
||||
if (!_chkReply) return;
|
||||
void CustomLangPack::fetchFinished()
|
||||
{
|
||||
if (!_chkReply) return;
|
||||
|
||||
QString langPackBaseId = Lang::GetInstance().baseId();
|
||||
QString langPackId = Lang::GetInstance().id();
|
||||
auto statusCode = _chkReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
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) {
|
||||
LOG(("AyuGram Language pack not found! Fallback to main language: %1...").arg(langPackBaseId));
|
||||
needFallback = true;
|
||||
_chkReply->disconnect();
|
||||
fetchCustomLangPack("", langPackBaseId);
|
||||
} else {
|
||||
QByteArray result = _chkReply->readAll().trimmed();
|
||||
QJsonParseError error{};
|
||||
QJsonDocument str = QJsonDocument::fromJson(result, &error);
|
||||
if (error.error == QJsonParseError::NoError) {
|
||||
parseLangFile(str);
|
||||
} else {
|
||||
LOG(("Incorrect JSON File. Fallback to default language: English..."));
|
||||
loadDefaultLangFile();
|
||||
}
|
||||
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
|
||||
{
|
||||
QByteArray result = _chkReply->readAll().trimmed();
|
||||
QJsonParseError error{};
|
||||
QJsonDocument str = QJsonDocument::fromJson(result, &error);
|
||||
if (error.error == QJsonParseError::NoError)
|
||||
{
|
||||
parseLangFile(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(("Incorrect JSON File. Fallback to default language: English..."));
|
||||
loadDefaultLangFile();
|
||||
}
|
||||
|
||||
_chkReply = nullptr;
|
||||
}
|
||||
_chkReply = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void CustomLangPack::fetchError(QNetworkReply::NetworkError e) {
|
||||
LOG(("Network error: %1").arg(e));
|
||||
void CustomLangPack::fetchError(QNetworkReply::NetworkError e)
|
||||
{
|
||||
LOG(("Network error: %1").arg(e));
|
||||
|
||||
if (e == QNetworkReply::NetworkError::ContentNotFoundError) {
|
||||
QString langPackBaseId = Lang::GetInstance().baseId();
|
||||
QString langPackId = Lang::GetInstance().id();
|
||||
if (e == QNetworkReply::NetworkError::ContentNotFoundError)
|
||||
{
|
||||
QString langPackBaseId = Lang::GetInstance().baseId();
|
||||
QString langPackId = Lang::GetInstance().id();
|
||||
|
||||
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 {
|
||||
LOG(("AyuGram Language pack not found! Fallback to default language: English..."));
|
||||
loadDefaultLangFile();
|
||||
_chkReply = nullptr;
|
||||
}
|
||||
}
|
||||
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
|
||||
{
|
||||
LOG(("AyuGram Language pack not found! Fallback to default language: English..."));
|
||||
loadDefaultLangFile();
|
||||
_chkReply = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CustomLangPack::loadDefaultLangFile() {
|
||||
QFile file(":/localization/en.json");
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
QJsonDocument str = QJsonDocument::fromJson(file.readAll());
|
||||
QJsonObject json = str.object();
|
||||
for (const QString &key: json.keys()) {
|
||||
Lang::GetInstance().applyValue(key.toUtf8(), json.value(key).toString().toUtf8());
|
||||
}
|
||||
Lang::GetInstance().updatePluralRules();
|
||||
file.close();
|
||||
}
|
||||
void CustomLangPack::loadDefaultLangFile()
|
||||
{
|
||||
QFile file(":/localization/en.json");
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QJsonDocument str = QJsonDocument::fromJson(file.readAll());
|
||||
QJsonObject json = str.object();
|
||||
for (const QString& key : json.keys())
|
||||
{
|
||||
Lang::GetInstance().applyValue(key.toUtf8(), json.value(key).toString().toUtf8());
|
||||
}
|
||||
Lang::GetInstance().updatePluralRules();
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void CustomLangPack::parseLangFile(QJsonDocument str) {
|
||||
QJsonObject json = str.object();
|
||||
for (const QString &brokenKey: json.keys()) {
|
||||
auto key = qsl("ayu_") + brokenKey;
|
||||
auto val = json.value(brokenKey).toString().replace(qsl("&"), qsl("&")).toUtf8();
|
||||
void CustomLangPack::parseLangFile(QJsonDocument str)
|
||||
{
|
||||
QJsonObject json = str.object();
|
||||
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")) {
|
||||
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);
|
||||
Lang::GetInstance().applyValue(key.toUtf8().replace("#other", "#many"), val);
|
||||
}
|
||||
}
|
||||
Lang::GetInstance().updatePluralRules();
|
||||
}
|
||||
Lang::GetInstance().resetValue(key.toUtf8());
|
||||
Lang::GetInstance().applyValue(key.toUtf8(), val);
|
||||
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);
|
||||
Lang::GetInstance().applyValue(key.toUtf8().replace("#other", "#many"), val);
|
||||
}
|
||||
}
|
||||
Lang::GetInstance().updatePluralRules();
|
||||
}
|
||||
|
|
|
@ -10,36 +10,36 @@
|
|||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QtXml/QDomDocument>
|
||||
|
||||
class CustomLangPack : public QObject {
|
||||
Q_OBJECT
|
||||
class CustomLangPack : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_DISABLE_COPY(CustomLangPack)
|
||||
Q_DISABLE_COPY(CustomLangPack)
|
||||
|
||||
public:
|
||||
static CustomLangPack *currentInstance();
|
||||
static CustomLangPack* currentInstance();
|
||||
|
||||
static void initInstance();
|
||||
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 loadDefaultLangFile();
|
||||
|
||||
void parseLangFile(QJsonDocument str);
|
||||
void parseLangFile(QJsonDocument str);
|
||||
|
||||
public Q_SLOTS:
|
||||
void fetchFinished();
|
||||
|
||||
void fetchFinished();
|
||||
|
||||
void fetchError(QNetworkReply::NetworkError e);
|
||||
void fetchError(QNetworkReply::NetworkError e);
|
||||
|
||||
private:
|
||||
CustomLangPack();
|
||||
CustomLangPack();
|
||||
|
||||
~CustomLangPack() = default;
|
||||
~CustomLangPack() override = default;
|
||||
|
||||
QNetworkAccessManager networkManager;
|
||||
QNetworkReply *_chkReply = nullptr;
|
||||
bool needFallback = false;
|
||||
};
|
||||
QNetworkAccessManager networkManager;
|
||||
QNetworkReply* _chkReply = nullptr;
|
||||
bool needFallback = false;
|
||||
};
|
||||
|
|
|
@ -12,199 +12,239 @@
|
|||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace AyuSettings {
|
||||
const QString filename = "tdata/ayu_settings.json";
|
||||
std::optional<AyuGramSettings> settings = std::nullopt;
|
||||
namespace AyuSettings
|
||||
{
|
||||
const QString filename = "tdata/ayu_settings.json";
|
||||
std::optional<AyuGramSettings> settings = std::nullopt;
|
||||
|
||||
rpl::variable<bool> sendReadPacketsReactive;
|
||||
rpl::variable<bool> sendOnlinePacketsReactive;
|
||||
rpl::variable<bool> sendUploadProgressReactive;
|
||||
rpl::variable<bool> sendOfflinePacketAfterOnlineReactive;
|
||||
rpl::variable<bool> sendReadPacketsReactive;
|
||||
rpl::variable<bool> sendOnlinePacketsReactive;
|
||||
rpl::variable<bool> sendUploadProgressReactive;
|
||||
rpl::variable<bool> sendOfflinePacketAfterOnlineReactive;
|
||||
|
||||
rpl::variable<QString> deletedMarkReactive;
|
||||
rpl::variable<QString> editedMarkReactive;
|
||||
rpl::variable<int> showPeerIdReactive;
|
||||
rpl::variable<QString> deletedMarkReactive;
|
||||
rpl::variable<QString> editedMarkReactive;
|
||||
rpl::variable<int> showPeerIdReactive;
|
||||
|
||||
rpl::variable<bool> ghostModeEnabled;
|
||||
rpl::variable<bool> ghostModeEnabled;
|
||||
|
||||
rpl::lifetime lifetime = rpl::lifetime();
|
||||
rpl::lifetime lifetime = rpl::lifetime();
|
||||
|
||||
bool ghostModeEnabled_util(AyuGramSettings &settingsUtil) {
|
||||
return (!settingsUtil.sendReadPackets
|
||||
&& !settingsUtil.sendOnlinePackets
|
||||
&& !settingsUtil.sendUploadProgress
|
||||
&& settingsUtil.sendOfflinePacketAfterOnline);
|
||||
}
|
||||
bool ghostModeEnabled_util(AyuGramSettings& settingsUtil)
|
||||
{
|
||||
return (!settingsUtil.sendReadPackets
|
||||
&& !settingsUtil.sendOnlinePackets
|
||||
&& !settingsUtil.sendUploadProgress
|
||||
&& settingsUtil.sendOfflinePacketAfterOnline);
|
||||
}
|
||||
|
||||
void initialize() {
|
||||
if (settings.has_value()) {
|
||||
return;
|
||||
}
|
||||
void initialize()
|
||||
{
|
||||
if (settings.has_value())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
settings = AyuGramSettings();
|
||||
settings = AyuGramSettings();
|
||||
|
||||
sendReadPacketsReactive.value() | rpl::filter([=](bool val) {
|
||||
return (val != settings->sendReadPackets);
|
||||
}) | rpl::start_with_next([=](bool val) {
|
||||
ghostModeEnabled = ghostModeEnabled_util(settings.value());
|
||||
}, lifetime);
|
||||
sendOnlinePacketsReactive.value() | rpl::filter([=](bool val) {
|
||||
return (val != settings->sendOnlinePackets);
|
||||
}) | rpl::start_with_next([=](bool val) {
|
||||
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);
|
||||
}
|
||||
sendReadPacketsReactive.value() | rpl::filter([=](bool val)
|
||||
{
|
||||
return (val != settings->sendReadPackets);
|
||||
}) | start_with_next([=](bool val)
|
||||
{
|
||||
ghostModeEnabled = ghostModeEnabled_util(settings.value());
|
||||
}, lifetime);
|
||||
sendOnlinePacketsReactive.value() | rpl::filter([=](bool val)
|
||||
{
|
||||
return (val != settings->sendOnlinePackets);
|
||||
}) | start_with_next([=](bool val)
|
||||
{
|
||||
ghostModeEnabled = ghostModeEnabled_util(settings.value());
|
||||
}, lifetime);
|
||||
sendUploadProgressReactive.value() | rpl::filter([=](bool val)
|
||||
{
|
||||
return (val != settings->sendUploadProgress);
|
||||
}) | start_with_next([=](bool val)
|
||||
{
|
||||
ghostModeEnabled = ghostModeEnabled_util(settings.value());
|
||||
}, lifetime);
|
||||
sendOfflinePacketAfterOnlineReactive.value() | rpl::filter([=](bool val)
|
||||
{
|
||||
return (val != settings->sendOfflinePacketAfterOnline);
|
||||
}) | start_with_next([=](bool val)
|
||||
{
|
||||
ghostModeEnabled = ghostModeEnabled_util(settings.value());
|
||||
}, lifetime);
|
||||
}
|
||||
|
||||
void postinitialize() {
|
||||
sendReadPacketsReactive = settings->sendReadPackets;
|
||||
sendOnlinePacketsReactive = settings->sendOnlinePackets;
|
||||
void postinitialize()
|
||||
{
|
||||
sendReadPacketsReactive = settings->sendReadPackets;
|
||||
sendOnlinePacketsReactive = settings->sendOnlinePackets;
|
||||
|
||||
deletedMarkReactive = settings->deletedMark;
|
||||
editedMarkReactive = settings->editedMark;
|
||||
showPeerIdReactive = settings->showPeerId;
|
||||
deletedMarkReactive = settings->deletedMark;
|
||||
editedMarkReactive = settings->editedMark;
|
||||
showPeerIdReactive = settings->showPeerId;
|
||||
|
||||
ghostModeEnabled = ghostModeEnabled_util(settings.value());
|
||||
}
|
||||
ghostModeEnabled = ghostModeEnabled_util(settings.value());
|
||||
}
|
||||
|
||||
AyuGramSettings &getInstance() {
|
||||
initialize();
|
||||
return settings.value();
|
||||
}
|
||||
AyuGramSettings& getInstance()
|
||||
{
|
||||
initialize();
|
||||
return settings.value();
|
||||
}
|
||||
|
||||
void load() {
|
||||
QFile file(filename);
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QByteArray data = file.readAll();
|
||||
file.close();
|
||||
void load()
|
||||
{
|
||||
QFile file(filename);
|
||||
if (!file.exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QByteArray data = file.readAll();
|
||||
file.close();
|
||||
|
||||
initialize();
|
||||
json p = json::parse(data);
|
||||
settings = p.template get<AyuGramSettings>();
|
||||
postinitialize();
|
||||
}
|
||||
initialize();
|
||||
json p = json::parse(data);
|
||||
settings = p.get<AyuGramSettings>();
|
||||
postinitialize();
|
||||
}
|
||||
|
||||
void save() {
|
||||
initialize();
|
||||
void save()
|
||||
{
|
||||
initialize();
|
||||
|
||||
json p = settings.value();
|
||||
json p = settings.value();
|
||||
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write(p.dump().c_str());
|
||||
file.close();
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write(p.dump().c_str());
|
||||
file.close();
|
||||
|
||||
postinitialize();
|
||||
}
|
||||
postinitialize();
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_sendReadPackets(bool val) {
|
||||
sendReadPackets = val;
|
||||
sendReadPacketsReactive = val;
|
||||
}
|
||||
void AyuGramSettings::set_sendReadPackets(bool val)
|
||||
{
|
||||
sendReadPackets = val;
|
||||
sendReadPacketsReactive = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_sendOnlinePackets(bool val) {
|
||||
sendOnlinePackets = val;
|
||||
sendOnlinePacketsReactive = val;
|
||||
}
|
||||
void AyuGramSettings::set_sendOnlinePackets(bool val)
|
||||
{
|
||||
sendOnlinePackets = val;
|
||||
sendOnlinePacketsReactive = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_sendUploadProgress(bool val) {
|
||||
sendUploadProgress = val;
|
||||
sendUploadProgressReactive = val;
|
||||
}
|
||||
void AyuGramSettings::set_sendUploadProgress(bool val)
|
||||
{
|
||||
sendUploadProgress = val;
|
||||
sendUploadProgressReactive = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_sendOfflinePacketAfterOnline(bool val) {
|
||||
sendOfflinePacketAfterOnline = val;
|
||||
sendOfflinePacketAfterOnlineReactive = val;
|
||||
}
|
||||
void AyuGramSettings::set_sendOfflinePacketAfterOnline(bool val)
|
||||
{
|
||||
sendOfflinePacketAfterOnline = val;
|
||||
sendOfflinePacketAfterOnlineReactive = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_markReadAfterSend(bool val) {
|
||||
markReadAfterSend = val;
|
||||
}
|
||||
void AyuGramSettings::set_markReadAfterSend(bool val)
|
||||
{
|
||||
markReadAfterSend = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_useScheduledMessages(bool val) {
|
||||
useScheduledMessages = val;
|
||||
}
|
||||
void AyuGramSettings::set_useScheduledMessages(bool val)
|
||||
{
|
||||
useScheduledMessages = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_keepDeletedMessages(bool val) {
|
||||
keepDeletedMessages = val;
|
||||
}
|
||||
void AyuGramSettings::set_keepDeletedMessages(bool val)
|
||||
{
|
||||
keepDeletedMessages = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_keepMessagesHistory(bool val) {
|
||||
keepMessagesHistory = val;
|
||||
}
|
||||
void AyuGramSettings::set_keepMessagesHistory(bool val)
|
||||
{
|
||||
keepMessagesHistory = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_enableAds(bool val) {
|
||||
enableAds = val;
|
||||
}
|
||||
void AyuGramSettings::set_enableAds(bool val)
|
||||
{
|
||||
enableAds = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_deletedMark(QString val) {
|
||||
deletedMark = std::move(val);
|
||||
deletedMarkReactive = deletedMark;
|
||||
}
|
||||
void AyuGramSettings::set_deletedMark(QString val)
|
||||
{
|
||||
deletedMark = std::move(val);
|
||||
deletedMarkReactive = deletedMark;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_editedMark(QString val) {
|
||||
editedMark = std::move(val);
|
||||
editedMarkReactive = editedMark;
|
||||
}
|
||||
void AyuGramSettings::set_editedMark(QString val)
|
||||
{
|
||||
editedMark = std::move(val);
|
||||
editedMarkReactive = editedMark;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_recentStickersCount(int val) {
|
||||
recentStickersCount = val;
|
||||
}
|
||||
void AyuGramSettings::set_recentStickersCount(int val)
|
||||
{
|
||||
recentStickersCount = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_showGhostToggleInDrawer(bool val) {
|
||||
showGhostToggleInDrawer = val;
|
||||
}
|
||||
void AyuGramSettings::set_showGhostToggleInDrawer(bool val)
|
||||
{
|
||||
showGhostToggleInDrawer = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_showPeerId(int val) {
|
||||
showPeerId = val;
|
||||
showPeerIdReactive = val;
|
||||
}
|
||||
void AyuGramSettings::set_showPeerId(int val)
|
||||
{
|
||||
showPeerId = val;
|
||||
showPeerIdReactive = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_showMessageSeconds(bool val) {
|
||||
showMessageSeconds = val;
|
||||
}
|
||||
void AyuGramSettings::set_showMessageSeconds(bool val)
|
||||
{
|
||||
showMessageSeconds = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_stickerConfirmation(bool val) {
|
||||
stickerConfirmation = val;
|
||||
}
|
||||
void AyuGramSettings::set_stickerConfirmation(bool val)
|
||||
{
|
||||
stickerConfirmation = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_GIFConfirmation(bool val) {
|
||||
GIFConfirmation = val;
|
||||
}
|
||||
void AyuGramSettings::set_GIFConfirmation(bool val)
|
||||
{
|
||||
GIFConfirmation = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_voiceConfirmation(bool val) {
|
||||
voiceConfirmation = val;
|
||||
}
|
||||
void AyuGramSettings::set_voiceConfirmation(bool val)
|
||||
{
|
||||
voiceConfirmation = val;
|
||||
}
|
||||
|
||||
bool get_ghostModeEnabled() {
|
||||
return ghostModeEnabled.current();
|
||||
}
|
||||
bool get_ghostModeEnabled()
|
||||
{
|
||||
return ghostModeEnabled.current();
|
||||
}
|
||||
|
||||
rpl::producer<QString> get_deletedMarkReactive() {
|
||||
return deletedMarkReactive.value();
|
||||
}
|
||||
rpl::producer<QString> get_deletedMarkReactive()
|
||||
{
|
||||
return deletedMarkReactive.value();
|
||||
}
|
||||
|
||||
rpl::producer<QString> get_editedMarkReactive() {
|
||||
return editedMarkReactive.value();
|
||||
}
|
||||
rpl::producer<QString> get_editedMarkReactive()
|
||||
{
|
||||
return editedMarkReactive.value();
|
||||
}
|
||||
|
||||
rpl::producer<int> get_showPeerIdReactive() {
|
||||
return showPeerIdReactive.value();
|
||||
}
|
||||
rpl::producer<int> get_showPeerIdReactive()
|
||||
{
|
||||
return showPeerIdReactive.value();
|
||||
}
|
||||
|
||||
rpl::producer<bool> get_ghostModeEnabledReactive() {
|
||||
return ghostModeEnabled.value();
|
||||
}
|
||||
rpl::producer<bool> get_ghostModeEnabledReactive()
|
||||
{
|
||||
return ghostModeEnabled.value();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,149 +7,152 @@
|
|||
|
||||
#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 {
|
||||
public:
|
||||
AyuGramSettings() {
|
||||
// ~ Ghost essentials
|
||||
sendReadPackets = true;
|
||||
sendOnlinePackets = true;
|
||||
sendUploadProgress = true;
|
||||
namespace AyuSettings
|
||||
{
|
||||
class AyuGramSettings
|
||||
{
|
||||
public:
|
||||
AyuGramSettings()
|
||||
{
|
||||
// ~ Ghost essentials
|
||||
sendReadPackets = true;
|
||||
sendOnlinePackets = true;
|
||||
sendUploadProgress = true;
|
||||
|
||||
sendOfflinePacketAfterOnline = false;
|
||||
markReadAfterSend = true;
|
||||
sendOfflinePacketAfterOnline = false;
|
||||
markReadAfterSend = true;
|
||||
|
||||
useScheduledMessages = false;
|
||||
useScheduledMessages = false;
|
||||
|
||||
// ~ Message edits & deletion history
|
||||
keepDeletedMessages = true;
|
||||
keepMessagesHistory = true;
|
||||
// ~ Message edits & deletion history
|
||||
keepDeletedMessages = true;
|
||||
keepMessagesHistory = true;
|
||||
|
||||
// ~ QoL toggles
|
||||
enableAds = false;
|
||||
// ~ QoL toggles
|
||||
enableAds = false;
|
||||
|
||||
// ~ Customization
|
||||
deletedMark = "🧹";
|
||||
editedMark = tr::lng_edited(tr::now);
|
||||
recentStickersCount = 20;
|
||||
showGhostToggleInDrawer = true;
|
||||
// ~ Customization
|
||||
deletedMark = "🧹";
|
||||
editedMark = tr::lng_edited(tr::now);
|
||||
recentStickersCount = 20;
|
||||
showGhostToggleInDrawer = true;
|
||||
|
||||
// ~ Beta functionality
|
||||
stickerConfirmation = false;
|
||||
GIFConfirmation = false;
|
||||
voiceConfirmation = false;
|
||||
// ~ Beta functionality
|
||||
stickerConfirmation = false;
|
||||
GIFConfirmation = false;
|
||||
voiceConfirmation = false;
|
||||
|
||||
/*
|
||||
* showPeerId = 0 means no ID shown
|
||||
* showPeerId = 1 means ID shown as for Telegram API devs
|
||||
* showPeerId = 2 means ID shown as for Bot API devs (-100)
|
||||
*/
|
||||
showPeerId = 2;
|
||||
/*
|
||||
* showPeerId = 0 means no ID shown
|
||||
* showPeerId = 1 means ID shown as for Telegram API devs
|
||||
* showPeerId = 2 means ID shown as for Bot API devs (-100)
|
||||
*/
|
||||
showPeerId = 2;
|
||||
|
||||
showMessageSeconds = false;
|
||||
stickerConfirmation = false;
|
||||
GIFConfirmation = false;
|
||||
voiceConfirmation = false;
|
||||
}
|
||||
showMessageSeconds = false;
|
||||
stickerConfirmation = false;
|
||||
GIFConfirmation = false;
|
||||
voiceConfirmation = false;
|
||||
}
|
||||
|
||||
bool sendReadPackets;
|
||||
bool sendOnlinePackets;
|
||||
bool sendUploadProgress;
|
||||
bool sendOfflinePacketAfterOnline;
|
||||
bool markReadAfterSend;
|
||||
bool useScheduledMessages;
|
||||
bool keepDeletedMessages;
|
||||
bool keepMessagesHistory;
|
||||
bool enableAds;
|
||||
QString deletedMark;
|
||||
QString editedMark;
|
||||
int recentStickersCount;
|
||||
bool showGhostToggleInDrawer;
|
||||
int showPeerId;
|
||||
bool showMessageSeconds;
|
||||
bool stickerConfirmation;
|
||||
bool GIFConfirmation;
|
||||
bool voiceConfirmation;
|
||||
bool sendReadPackets;
|
||||
bool sendOnlinePackets;
|
||||
bool sendUploadProgress;
|
||||
bool sendOfflinePacketAfterOnline;
|
||||
bool markReadAfterSend;
|
||||
bool useScheduledMessages;
|
||||
bool keepDeletedMessages;
|
||||
bool keepMessagesHistory;
|
||||
bool enableAds;
|
||||
QString deletedMark;
|
||||
QString editedMark;
|
||||
int recentStickersCount;
|
||||
bool showGhostToggleInDrawer;
|
||||
int showPeerId;
|
||||
bool showMessageSeconds;
|
||||
bool stickerConfirmation;
|
||||
bool GIFConfirmation;
|
||||
bool voiceConfirmation;
|
||||
|
||||
public:
|
||||
void set_sendReadPackets(bool val);
|
||||
public:
|
||||
void set_sendReadPackets(bool val);
|
||||
|
||||
void set_sendOnlinePackets(bool val);
|
||||
void set_sendOnlinePackets(bool val);
|
||||
|
||||
void set_sendUploadProgress(bool val);
|
||||
void set_sendUploadProgress(bool val);
|
||||
|
||||
void set_sendOfflinePacketAfterOnline(bool val);
|
||||
void set_sendOfflinePacketAfterOnline(bool val);
|
||||
|
||||
void set_markReadAfterSend(bool val);
|
||||
void set_markReadAfterSend(bool val);
|
||||
|
||||
void set_useScheduledMessages(bool val);
|
||||
void set_useScheduledMessages(bool val);
|
||||
|
||||
void set_keepDeletedMessages(bool val);
|
||||
void set_keepDeletedMessages(bool val);
|
||||
|
||||
void set_keepMessagesHistory(bool val);
|
||||
void set_keepMessagesHistory(bool val);
|
||||
|
||||
void set_enableAds(bool val);
|
||||
void set_enableAds(bool val);
|
||||
|
||||
void set_deletedMark(QString val);
|
||||
void set_deletedMark(QString val);
|
||||
|
||||
void set_editedMark(QString val);
|
||||
void set_editedMark(QString val);
|
||||
|
||||
void set_recentStickersCount(int val);
|
||||
void set_recentStickersCount(int val);
|
||||
|
||||
void set_showGhostToggleInDrawer(bool val);
|
||||
void set_showGhostToggleInDrawer(bool val);
|
||||
|
||||
void set_showPeerId(int val);
|
||||
void set_showPeerId(int val);
|
||||
|
||||
void set_showMessageSeconds(bool val);
|
||||
void set_showMessageSeconds(bool val);
|
||||
|
||||
void set_stickerConfirmation(bool val);
|
||||
void set_stickerConfirmation(bool val);
|
||||
|
||||
void set_GIFConfirmation(bool val);
|
||||
void set_GIFConfirmation(bool val);
|
||||
|
||||
void set_voiceConfirmation(bool val);
|
||||
};
|
||||
void set_voiceConfirmation(bool val);
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
|
||||
AyuGramSettings,
|
||||
sendReadPackets,
|
||||
sendOnlinePackets,
|
||||
sendUploadProgress,
|
||||
sendOfflinePacketAfterOnline,
|
||||
markReadAfterSend,
|
||||
useScheduledMessages,
|
||||
keepDeletedMessages,
|
||||
keepMessagesHistory,
|
||||
enableAds,
|
||||
deletedMark,
|
||||
editedMark,
|
||||
recentStickersCount,
|
||||
showGhostToggleInDrawer,
|
||||
showPeerId,
|
||||
showMessageSeconds,
|
||||
stickerConfirmation,
|
||||
GIFConfirmation,
|
||||
voiceConfirmation
|
||||
);
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
|
||||
AyuGramSettings,
|
||||
sendReadPackets,
|
||||
sendOnlinePackets,
|
||||
sendUploadProgress,
|
||||
sendOfflinePacketAfterOnline,
|
||||
markReadAfterSend,
|
||||
useScheduledMessages,
|
||||
keepDeletedMessages,
|
||||
keepMessagesHistory,
|
||||
enableAds,
|
||||
deletedMark,
|
||||
editedMark,
|
||||
recentStickersCount,
|
||||
showGhostToggleInDrawer,
|
||||
showPeerId,
|
||||
showMessageSeconds,
|
||||
stickerConfirmation,
|
||||
GIFConfirmation,
|
||||
voiceConfirmation
|
||||
);
|
||||
|
||||
AyuGramSettings &getInstance();
|
||||
AyuGramSettings& getInstance();
|
||||
|
||||
void load();
|
||||
void load();
|
||||
|
||||
void save();
|
||||
void save();
|
||||
|
||||
rpl::producer<QString> get_deletedMarkReactive();
|
||||
rpl::producer<QString> get_deletedMarkReactive();
|
||||
|
||||
rpl::producer<QString> get_editedMarkReactive();
|
||||
rpl::producer<QString> get_editedMarkReactive();
|
||||
|
||||
rpl::producer<int> get_showPeerIdReactive();
|
||||
rpl::producer<int> get_showPeerIdReactive();
|
||||
|
||||
// computed fields
|
||||
bool get_ghostModeEnabled();
|
||||
// computed fields
|
||||
bool get_ghostModeEnabled();
|
||||
|
||||
rpl::producer<bool> get_ghostModeEnabledReactive();
|
||||
rpl::producer<bool> get_ghostModeEnabledReactive();
|
||||
}
|
||||
|
|
|
@ -7,14 +7,17 @@
|
|||
|
||||
#include "ayu_state.h"
|
||||
|
||||
namespace AyuState {
|
||||
void setAllowSendReadPacket(bool val, int resetAfter) {
|
||||
allowSendReadPacket.val = val;
|
||||
allowSendReadPacket.resetAfter = resetAfter;
|
||||
}
|
||||
namespace AyuState
|
||||
{
|
||||
void setAllowSendReadPacket(bool val, int resetAfter)
|
||||
{
|
||||
allowSendReadPacket.val = val;
|
||||
allowSendReadPacket.resetAfter = resetAfter;
|
||||
}
|
||||
|
||||
bool getAllowSendPacket() {
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
return settings->sendReadPackets || processVariable(allowSendReadPacket);
|
||||
}
|
||||
}
|
||||
bool getAllowSendPacket()
|
||||
{
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
return settings->sendReadPackets || processVariable(allowSendReadPacket);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,33 +9,39 @@
|
|||
|
||||
#include "ayu_settings.h"
|
||||
|
||||
namespace AyuState {
|
||||
namespace {
|
||||
class AyuStateVariable {
|
||||
public:
|
||||
bool val;
|
||||
int resetAfter;
|
||||
};
|
||||
namespace AyuState
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class AyuStateVariable
|
||||
{
|
||||
public:
|
||||
bool val;
|
||||
int resetAfter;
|
||||
};
|
||||
|
||||
AyuStateVariable allowSendReadPacket;
|
||||
AyuStateVariable allowSendReadPacket;
|
||||
|
||||
bool processVariable(AyuStateVariable &variable) {
|
||||
if (variable.resetAfter == -1) {
|
||||
return variable.val;
|
||||
}
|
||||
bool processVariable(AyuStateVariable& variable)
|
||||
{
|
||||
if (variable.resetAfter == -1)
|
||||
{
|
||||
return variable.val;
|
||||
}
|
||||
|
||||
variable.resetAfter -= 1;
|
||||
auto val = variable.val;
|
||||
variable.resetAfter -= 1;
|
||||
auto val = variable.val;
|
||||
|
||||
if (variable.resetAfter == 0) {
|
||||
variable.val = false;
|
||||
}
|
||||
if (variable.resetAfter == 0)
|
||||
{
|
||||
variable.val = false;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
void setAllowSendReadPacket(bool val, int resetAfter = 1);
|
||||
void setAllowSendReadPacket(bool val, int resetAfter = 1);
|
||||
|
||||
bool getAllowSendPacket();
|
||||
}
|
||||
bool getAllowSendPacket();
|
||||
}
|
||||
|
|
|
@ -27,56 +27,59 @@ auto storage = make_storage("ayugram.db",
|
|||
);
|
||||
|
||||
|
||||
namespace AyuDatabase {
|
||||
void addEditedMessage(
|
||||
long userId,
|
||||
long dialogId,
|
||||
long messageId,
|
||||
const QString &text,
|
||||
bool isDocument,
|
||||
QString path,
|
||||
long date) {
|
||||
namespace AyuDatabase
|
||||
{
|
||||
void addEditedMessage(
|
||||
long userId,
|
||||
long dialogId,
|
||||
long messageId,
|
||||
const QString& text,
|
||||
bool isDocument,
|
||||
QString path,
|
||||
long date)
|
||||
{
|
||||
EditedMessage entity;
|
||||
entity.userId = userId;
|
||||
entity.dialogId = dialogId;
|
||||
entity.messageId = messageId;
|
||||
entity.text = text.toStdString();
|
||||
entity.isDocument = isDocument;
|
||||
entity.path = path.toStdString();
|
||||
entity.date = date;
|
||||
|
||||
EditedMessage entity;
|
||||
entity.userId = userId;
|
||||
entity.dialogId = dialogId;
|
||||
entity.messageId = messageId;
|
||||
entity.text = text.toStdString();
|
||||
entity.isDocument = isDocument;
|
||||
entity.path = path.toStdString();
|
||||
entity.date = date;
|
||||
storage.sync_schema();
|
||||
|
||||
storage.sync_schema();
|
||||
storage.begin_transaction();
|
||||
storage.insert(entity);
|
||||
storage.commit();
|
||||
}
|
||||
|
||||
storage.begin_transaction();
|
||||
storage.insert(entity);
|
||||
storage.commit();
|
||||
}
|
||||
std::vector<EditedMessage> getEditedMessages(
|
||||
long userId,
|
||||
long dialogId,
|
||||
long messageId
|
||||
)
|
||||
{
|
||||
return storage.get_all<EditedMessage>(
|
||||
where(
|
||||
c(&EditedMessage::userId) == userId and
|
||||
c(&EditedMessage::dialogId) == dialogId and
|
||||
c(&EditedMessage::messageId) == messageId)
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<EditedMessage> getEditedMessages(
|
||||
long userId,
|
||||
long dialogId,
|
||||
long messageId
|
||||
) {
|
||||
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();
|
||||
|
||||
return storage.get_all<EditedMessage>(
|
||||
where(
|
||||
c(&EditedMessage::userId) == userId and
|
||||
c(&EditedMessage::dialogId) == dialogId and
|
||||
c(&EditedMessage::messageId) == messageId)
|
||||
);
|
||||
}
|
||||
return getEditedMessages(static_cast<long>(userId), static_cast<long>(dialogId), static_cast<long>(msgId));
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
return getEditedMessages((long) userId, (long) dialogId, (long) msgId);
|
||||
}
|
||||
|
||||
bool editedMessagesTableExists() {
|
||||
return storage.table_exists("editedmessage");
|
||||
}
|
||||
bool editedMessagesTableExists()
|
||||
{
|
||||
return storage.table_exists("editedmessage");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,26 +8,27 @@
|
|||
#pragma once
|
||||
|
||||
#include "entities.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
|
||||
namespace AyuDatabase {
|
||||
void addEditedMessage(
|
||||
long userId,
|
||||
long dialogId,
|
||||
long messageId,
|
||||
const QString &text,
|
||||
bool isDocument,
|
||||
QString path,
|
||||
long date);
|
||||
namespace AyuDatabase
|
||||
{
|
||||
void addEditedMessage(
|
||||
long userId,
|
||||
long dialogId,
|
||||
long messageId,
|
||||
const QString& text,
|
||||
bool isDocument,
|
||||
QString path,
|
||||
long date);
|
||||
|
||||
std::vector<EditedMessage> getEditedMessages(
|
||||
long userId,
|
||||
long dialogId,
|
||||
long messageId
|
||||
);
|
||||
std::vector<EditedMessage> getEditedMessages(
|
||||
long userId,
|
||||
long dialogId,
|
||||
long messageId
|
||||
);
|
||||
|
||||
std::vector<EditedMessage> getEditedMessages(HistoryItem *item);
|
||||
std::vector<EditedMessage> getEditedMessages(HistoryItem* item);
|
||||
|
||||
bool editedMessagesTableExists();
|
||||
bool editedMessagesTableExists();
|
||||
}
|
||||
|
|
|
@ -11,14 +11,15 @@
|
|||
#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;
|
||||
long messageId;
|
||||
long userId;
|
||||
long dialogId;
|
||||
long messageId;
|
||||
|
||||
std::string text;
|
||||
bool isDocument;
|
||||
std::string path;
|
||||
long date;
|
||||
std::string text;
|
||||
bool isDocument;
|
||||
std::string path;
|
||||
long date;
|
||||
};
|
||||
|
|
|
@ -10,10 +10,12 @@
|
|||
#include <QString>
|
||||
#include "json.hpp"
|
||||
|
||||
inline void to_json(nlohmann::json &j, const QString &q) {
|
||||
j = nlohmann::json(q.toStdString());
|
||||
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) {
|
||||
q = QString::fromStdString(j.get<std::string>());
|
||||
}
|
||||
inline void from_json(const nlohmann::json& j, QString& q)
|
||||
{
|
||||
q = QString::fromStdString(j.get<std::string>());
|
||||
}
|
||||
|
|
|
@ -7,110 +7,132 @@
|
|||
|
||||
#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 {
|
||||
std::optional<ayu_sync_controller> controller = std::nullopt;
|
||||
namespace AyuSync
|
||||
{
|
||||
std::optional<ayu_sync_controller> controller = std::nullopt;
|
||||
|
||||
bool isAgentDownloaded() {
|
||||
return std::filesystem::exists(AgentPath);
|
||||
}
|
||||
bool isAgentDownloaded()
|
||||
{
|
||||
return std::filesystem::exists(AgentPath);
|
||||
}
|
||||
|
||||
bool isAgentRunning() {
|
||||
return is_process_running(AgentFilename);
|
||||
}
|
||||
bool isAgentRunning()
|
||||
{
|
||||
return is_process_running(AgentFilename);
|
||||
}
|
||||
|
||||
void initialize() {
|
||||
if (controller.has_value()) {
|
||||
return;
|
||||
}
|
||||
void initialize()
|
||||
{
|
||||
if (controller.has_value())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
controller = ayu_sync_controller();
|
||||
}
|
||||
controller = ayu_sync_controller();
|
||||
}
|
||||
|
||||
ayu_sync_controller &getControllerInstance() {
|
||||
initialize();
|
||||
return controller.value();
|
||||
}
|
||||
ayu_sync_controller& getControllerInstance()
|
||||
{
|
||||
initialize();
|
||||
return controller.value();
|
||||
}
|
||||
|
||||
void ayu_sync_controller::initializeAgent() {
|
||||
if (!isAgentDownloaded()) {
|
||||
return;
|
||||
}
|
||||
void ayu_sync_controller::initializeAgent()
|
||||
{
|
||||
if (!isAgentDownloaded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isAgentRunning()) {
|
||||
auto configPath = std::filesystem::absolute("./tdata/sync_preferences.json");
|
||||
auto process = nes::process{AgentPath, {configPath.string(), ""}, nes::process_options::none};
|
||||
process.detach();
|
||||
}
|
||||
if (!isAgentRunning())
|
||||
{
|
||||
auto configPath = std::filesystem::absolute("./tdata/sync_preferences.json");
|
||||
auto process = nes::process{AgentPath, {configPath.string(), ""}, nes::process_options::none};
|
||||
process.detach();
|
||||
}
|
||||
|
||||
std::thread receiverThread(&ayu_sync_controller::receiver, this);
|
||||
receiverThread.detach();
|
||||
}
|
||||
std::thread receiverThread(&ayu_sync_controller::receiver, this);
|
||||
receiverThread.detach();
|
||||
}
|
||||
|
||||
void ayu_sync_controller::receiver() {
|
||||
pipe = std::make_unique<ayu_pipe_wrapper>();
|
||||
void ayu_sync_controller::receiver()
|
||||
{
|
||||
pipe = std::make_unique<ayu_pipe_wrapper>();
|
||||
|
||||
while (true) {
|
||||
auto p = pipe->receive();
|
||||
if (p == std::nullopt) {
|
||||
continue;
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
auto p = pipe->receive();
|
||||
if (p == std::nullopt)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string s = p->dump();
|
||||
LOG(("[AyuSync] Received message: %1").arg(QString::fromStdString(s)));
|
||||
std::string s = p->dump();
|
||||
LOG(("[AyuSync] Received message: %1").arg(QString::fromStdString(s)));
|
||||
|
||||
invokeHandler(p.value());
|
||||
}
|
||||
}
|
||||
invokeHandler(p.value());
|
||||
}
|
||||
}
|
||||
|
||||
void ayu_sync_controller::invokeHandler(json p) {
|
||||
LOG(("Invoking handler on %1").arg(p.dump().c_str()));
|
||||
void ayu_sync_controller::invokeHandler(json p)
|
||||
{
|
||||
LOG(("Invoking handler on %1").arg(p.dump().c_str()));
|
||||
|
||||
auto userId = p["userId"].get<long>();
|
||||
auto type = p["type"].get<std::string>();
|
||||
auto userId = p["userId"].get<long>();
|
||||
auto type = p["type"].get<std::string>();
|
||||
|
||||
LOG(("userId: %1, type: %2").arg(userId).arg(type.c_str()));
|
||||
LOG(("userId: %1, type: %2").arg(userId).arg(type.c_str()));
|
||||
|
||||
// todo: check if account exists
|
||||
// todo: check if account exists
|
||||
|
||||
if (type == "sync_force") {
|
||||
auto ev = p.template get<SyncForce>();
|
||||
onSyncForce(ev);
|
||||
} else if (type == "sync_batch") {
|
||||
onSyncBatch(p);
|
||||
} else if (type == "sync_read") {
|
||||
auto ev = p.template get<SyncRead>();
|
||||
onSyncRead(ev);
|
||||
} else {
|
||||
LOG(("Unknown sync type: %1").arg(type.c_str()));
|
||||
}
|
||||
}
|
||||
if (type == "sync_force")
|
||||
{
|
||||
auto ev = p.template get<SyncForce>();
|
||||
onSyncForce(ev);
|
||||
}
|
||||
else if (type == "sync_batch")
|
||||
{
|
||||
onSyncBatch(p);
|
||||
}
|
||||
else if (type == "sync_read")
|
||||
{
|
||||
auto ev = p.template get<SyncRead>();
|
||||
onSyncRead(ev);
|
||||
}
|
||||
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)
|
||||
{
|
||||
auto session = getSession(ev.userId);
|
||||
|
||||
}
|
||||
auto peer = PeerId(abs(ev.args.dialogId));
|
||||
|
||||
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) {
|
||||
history->inboxRead(ev.args.untilId, ev.args.unread);
|
||||
}
|
||||
}
|
||||
}
|
||||
auto history = session->data().history(peer);
|
||||
if (history)
|
||||
{
|
||||
history->inboxRead(ev.args.untilId, ev.args.unread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,39 +7,42 @@
|
|||
|
||||
#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;
|
||||
|
||||
const std::string AgentFilename =
|
||||
#ifdef _WIN32
|
||||
"AyuSync.Agent.exe";
|
||||
"AyuSync.Agent.exe";
|
||||
#else
|
||||
"AyuSync.Agent";
|
||||
"AyuSync.Agent";
|
||||
#endif
|
||||
|
||||
const std::string AgentPath = "./AyuSync/" + AgentFilename;
|
||||
|
||||
namespace AyuSync {
|
||||
class ayu_sync_controller {
|
||||
public:
|
||||
void initializeAgent();
|
||||
namespace AyuSync
|
||||
{
|
||||
class ayu_sync_controller
|
||||
{
|
||||
public:
|
||||
void initializeAgent();
|
||||
|
||||
void onSyncForce(SyncForce ev);
|
||||
void onSyncBatch(json ev);
|
||||
void onSyncRead(SyncRead ev);
|
||||
void onSyncForce(SyncForce ev);
|
||||
void onSyncBatch(json ev);
|
||||
void onSyncRead(SyncRead ev);
|
||||
|
||||
void invokeHandler(json p);
|
||||
private:
|
||||
void receiver();
|
||||
void invokeHandler(json p);
|
||||
|
||||
std::unique_ptr<ayu_pipe_wrapper> pipe;
|
||||
};
|
||||
private:
|
||||
void receiver();
|
||||
|
||||
ayu_sync_controller &getControllerInstance();
|
||||
std::unique_ptr<ayu_pipe_wrapper> pipe;
|
||||
};
|
||||
|
||||
bool isAgentDownloaded();
|
||||
bool isAgentRunning();
|
||||
ayu_sync_controller& getControllerInstance();
|
||||
|
||||
bool isAgentDownloaded();
|
||||
bool isAgentRunning();
|
||||
}
|
||||
|
|
|
@ -1,66 +1,77 @@
|
|||
#pragma once
|
||||
|
||||
#include "ayu/libs/json.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class SyncEvent {
|
||||
class SyncEvent
|
||||
{
|
||||
public:
|
||||
std::string type = "sync_unspecified";
|
||||
long userId = 0;
|
||||
std::string type = "sync_unspecified";
|
||||
long userId = 0;
|
||||
};
|
||||
|
||||
class SyncBatch : public SyncEvent {
|
||||
class SyncBatch : public SyncEvent
|
||||
{
|
||||
public:
|
||||
std::string type = "sync_batch";
|
||||
long userId;
|
||||
std::string type = "sync_batch";
|
||||
long userId;
|
||||
|
||||
class SyncBatchArgs {
|
||||
public:
|
||||
std::vector<SyncEvent> events;
|
||||
};
|
||||
class SyncBatchArgs
|
||||
{
|
||||
public:
|
||||
std::vector<SyncEvent> events;
|
||||
};
|
||||
|
||||
SyncBatchArgs args;
|
||||
SyncBatchArgs args;
|
||||
};
|
||||
|
||||
class SyncRead : public SyncEvent {
|
||||
class SyncRead : public SyncEvent
|
||||
{
|
||||
public:
|
||||
std::string type = "sync_read";
|
||||
long userId;
|
||||
std::string type = "sync_read";
|
||||
long userId;
|
||||
|
||||
class SyncReadArgs {
|
||||
public:
|
||||
long dialogId;
|
||||
int untilId;
|
||||
int unread;
|
||||
};
|
||||
class SyncReadArgs
|
||||
{
|
||||
public:
|
||||
long dialogId;
|
||||
int untilId;
|
||||
int unread;
|
||||
};
|
||||
|
||||
SyncReadArgs args;
|
||||
SyncReadArgs args;
|
||||
};
|
||||
|
||||
class SyncForce : public SyncEvent {
|
||||
class SyncForce : public SyncEvent
|
||||
{
|
||||
public:
|
||||
std::string type = "sync_force";
|
||||
long userId;
|
||||
std::string type = "sync_force";
|
||||
long userId;
|
||||
|
||||
class SyncForceArgs {
|
||||
public:
|
||||
int fromDate;
|
||||
};
|
||||
class SyncForceArgs
|
||||
{
|
||||
public:
|
||||
int fromDate;
|
||||
};
|
||||
|
||||
SyncForceArgs args;
|
||||
SyncForceArgs args;
|
||||
};
|
||||
|
||||
class SyncForceFinish : public SyncEvent {
|
||||
class SyncForceFinish : public SyncEvent
|
||||
{
|
||||
public:
|
||||
std::string type = "sync_force_finish";
|
||||
long userId;
|
||||
std::string type = "sync_force_finish";
|
||||
long userId;
|
||||
|
||||
class SyncForceFinishArgs {
|
||||
public:
|
||||
short dummy; // required to be JSON serializable
|
||||
};
|
||||
class SyncForceFinishArgs
|
||||
{
|
||||
public:
|
||||
short dummy; // required to be JSON serializable
|
||||
};
|
||||
|
||||
SyncForceFinishArgs args;
|
||||
SyncForceFinishArgs args;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
|
|
@ -5,47 +5,52 @@
|
|||
//
|
||||
// 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();
|
||||
throw std::logic_error("not implemented");
|
||||
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()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
std::optional<json> ayu_pipe_wrapper::receive()
|
||||
{
|
||||
if (!is.is_open())
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
char lengthBuff[4];
|
||||
is.read(lengthBuff, 4);
|
||||
char lengthBuff[4];
|
||||
is.read(lengthBuff, 4);
|
||||
|
||||
auto length = bit_converter::bytes_to_i32(lengthBuff, false);
|
||||
auto length = bit_converter::bytes_to_i32(lengthBuff, false);
|
||||
|
||||
if (length <= 0) {
|
||||
return std::nullopt;
|
||||
}
|
||||
if (length <= 0)
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto sb = std::stringbuf();
|
||||
char buff[4096];
|
||||
auto sb = std::stringbuf();
|
||||
char buff[4096];
|
||||
|
||||
while (length > 0) {
|
||||
auto readSize = std::min(length, (int) sizeof(buff));
|
||||
is.read(buff, readSize);
|
||||
sb.sputn(buff, readSize);
|
||||
length -= readSize;
|
||||
}
|
||||
while (length > 0)
|
||||
{
|
||||
auto readSize = std::min(length, static_cast<int>(sizeof(buff)));
|
||||
is.read(buff, readSize);
|
||||
sb.sputn(buff, readSize);
|
||||
length -= readSize;
|
||||
}
|
||||
|
||||
auto p = json::parse(sb.str());
|
||||
return p;
|
||||
}
|
||||
auto p = json::parse(sb.str());
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -13,13 +13,14 @@
|
|||
|
||||
using json = nlohmann::json;
|
||||
|
||||
class ayu_pipe_wrapper {
|
||||
class ayu_pipe_wrapper
|
||||
{
|
||||
public:
|
||||
template<class T>
|
||||
void send(T obj);
|
||||
template <class T>
|
||||
void send(T obj);
|
||||
|
||||
std::optional<json> receive();
|
||||
std::optional<json> receive();
|
||||
|
||||
private:
|
||||
nes::pipe_istream is{"AyuSync"};
|
||||
nes::pipe_istream is{"AyuSync"};
|
||||
};
|
||||
|
|
|
@ -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,34 +17,40 @@
|
|||
|
||||
// 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) {
|
||||
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)) {
|
||||
std::cerr << "Failed to get first process\n";
|
||||
CloseHandle(snapshot);
|
||||
return false;
|
||||
}
|
||||
do {
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::string entry_name = converter.to_bytes(entry.szExeFile);
|
||||
if (name == entry_name) {
|
||||
// Found a match
|
||||
CloseHandle(snapshot);
|
||||
return true;
|
||||
}
|
||||
} while (Process32Next(snapshot, &entry));
|
||||
// No match found
|
||||
CloseHandle(snapshot);
|
||||
return false;
|
||||
// Create a snapshot of all processes
|
||||
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
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))
|
||||
{
|
||||
std::cerr << "Failed to get first process\n";
|
||||
CloseHandle(snapshot);
|
||||
return false;
|
||||
}
|
||||
do
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::string entry_name = converter.to_bytes(entry.szExeFile);
|
||||
if (name == entry_name)
|
||||
{
|
||||
// Found a match
|
||||
CloseHandle(snapshot);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
while (Process32Next(snapshot, &entry));
|
||||
// No match found
|
||||
CloseHandle(snapshot);
|
||||
return false;
|
||||
#else
|
||||
// Open the /proc directory
|
||||
DIR* dir = opendir("/proc");
|
||||
|
@ -83,4 +89,4 @@ bool is_process_running(const std::string &name) {
|
|||
closedir(dir);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,19 +8,24 @@
|
|||
#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) {
|
||||
return session;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PeerId dialogIdToPeerId(long dialogId) {
|
||||
auto peerId = PeerId();
|
||||
return peerId;
|
||||
}
|
||||
PeerId dialogIdToPeerId(long dialogId)
|
||||
{
|
||||
auto peerId = PeerId();
|
||||
return peerId;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -6,57 +6,63 @@
|
|||
// 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 {
|
||||
ConfirmationBox::ConfirmationBox(
|
||||
QWidget *,
|
||||
not_null<Window::SessionController *> controller) : _controller(controller) {
|
||||
//
|
||||
}
|
||||
namespace AyuUi
|
||||
{
|
||||
ConfirmationBox::ConfirmationBox(
|
||||
QWidget*,
|
||||
not_null<Window::SessionController*> controller) : _controller(controller)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
void ConfirmationBox::prepare() {
|
||||
// setTitle(rpl::single(QString("Confirmation for SRead")));
|
||||
auto details = TextWithEntities();
|
||||
details.text = QString("Do you want to read all messages?");
|
||||
void ConfirmationBox::prepare()
|
||||
{
|
||||
// setTitle(rpl::single(QString("Confirmation for SRead")));
|
||||
auto details = TextWithEntities();
|
||||
details.text = QString("Do you want to read all messages?");
|
||||
|
||||
_text.create(this, rpl::single(std::move(details)), st::boxLabel);
|
||||
_text.create(this, rpl::single(std::move(details)), st::boxLabel);
|
||||
|
||||
auto fullHeight = st::boxPadding.top()
|
||||
+ _text->height()
|
||||
+ st::boxPadding.bottom();
|
||||
auto fullHeight = st::boxPadding.top()
|
||||
+ _text->height()
|
||||
+ st::boxPadding.bottom();
|
||||
|
||||
setDimensions(st::boxWidth, fullHeight);
|
||||
setDimensions(st::boxWidth, fullHeight);
|
||||
|
||||
addButton(rpl::single(QString("Read")), [=, this] {
|
||||
ReadAllPeers();
|
||||
closeBox();
|
||||
});
|
||||
addButton(tr::lng_cancel(), [=, this] { closeBox(); });
|
||||
}
|
||||
addButton(rpl::single(QString("Read")), [=, this]
|
||||
{
|
||||
ReadAllPeers();
|
||||
closeBox();
|
||||
});
|
||||
addButton(tr::lng_cancel(), [=, this] { closeBox(); });
|
||||
}
|
||||
|
||||
void ConfirmationBox::resizeEvent(QResizeEvent *e) {
|
||||
BoxContent::resizeEvent(e);
|
||||
void ConfirmationBox::resizeEvent(QResizeEvent* e)
|
||||
{
|
||||
BoxContent::resizeEvent(e);
|
||||
|
||||
const auto &padding = st::boxPadding;
|
||||
_text->moveToLeft(padding.left(), padding.top());
|
||||
}
|
||||
const auto& padding = st::boxPadding;
|
||||
_text->moveToLeft(padding.left(), padding.top());
|
||||
}
|
||||
|
||||
void ConfirmationBox::ReadAllPeers() {
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
auto prev = settings->sendReadPackets;
|
||||
settings->set_sendReadPackets(true);
|
||||
void ConfirmationBox::ReadAllPeers()
|
||||
{
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
auto prev = settings->sendReadPackets;
|
||||
settings->set_sendReadPackets(true);
|
||||
|
||||
auto chats = _controller->session().data().chatsList();
|
||||
Window::MarkAsReadChatListHack(chats);
|
||||
auto chats = _controller->session().data().chatsList();
|
||||
Window::MarkAsReadChatListHack(chats);
|
||||
|
||||
settings->set_sendReadPackets(prev);
|
||||
}
|
||||
}
|
||||
settings->set_sendReadPackets(prev);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,20 +8,22 @@
|
|||
#include "ui/layers/box_content.h"
|
||||
#include "window/window_main_menu.h"
|
||||
|
||||
namespace AyuUi {
|
||||
class ConfirmationBox : public Ui::BoxContent {
|
||||
public:
|
||||
ConfirmationBox(QWidget *, not_null<Window::SessionController *> controller);
|
||||
namespace AyuUi
|
||||
{
|
||||
class ConfirmationBox : public Ui::BoxContent
|
||||
{
|
||||
public:
|
||||
ConfirmationBox(QWidget*, not_null<Window::SessionController*> controller);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
protected:
|
||||
void prepare() override;
|
||||
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void resizeEvent(QResizeEvent* e) override;
|
||||
|
||||
private:
|
||||
void ReadAllPeers();
|
||||
private:
|
||||
void ReadAllPeers();
|
||||
|
||||
not_null<Window::SessionController *> _controller;
|
||||
object_ptr<Ui::FlatLabel> _text = {nullptr};
|
||||
};
|
||||
}
|
||||
not_null<Window::SessionController*> _controller;
|
||||
object_ptr<Ui::FlatLabel> _text = {nullptr};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -7,83 +7,92 @@
|
|||
|
||||
#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 *) :
|
||||
_text(
|
||||
this,
|
||||
st::defaultInputField,
|
||||
rpl::single(QString("Deleted Mark")),
|
||||
AyuSettings::getInstance().deletedMark) {
|
||||
EditDeletedMarkBox::EditDeletedMarkBox(QWidget*) :
|
||||
_text(
|
||||
this,
|
||||
st::defaultInputField,
|
||||
rpl::single(QString("Deleted Mark")),
|
||||
AyuSettings::getInstance().deletedMark)
|
||||
{
|
||||
}
|
||||
|
||||
void EditDeletedMarkBox::prepare() {
|
||||
const auto defaultDeletedMark = "🧹";
|
||||
auto newHeight = st::contactPadding.top() + _text->height();
|
||||
void EditDeletedMarkBox::prepare()
|
||||
{
|
||||
const auto defaultDeletedMark = "🧹";
|
||||
auto newHeight = st::contactPadding.top() + _text->height();
|
||||
|
||||
setTitle(rpl::single(QString("Edit Deleted Mark")));
|
||||
setTitle(rpl::single(QString("Edit Deleted Mark")));
|
||||
|
||||
newHeight += st::boxPadding.bottom() + st::contactPadding.bottom();
|
||||
setDimensions(st::boxWidth, newHeight);
|
||||
newHeight += st::boxPadding.bottom() + st::contactPadding.bottom();
|
||||
setDimensions(st::boxWidth, newHeight);
|
||||
|
||||
addLeftButton(rpl::single(QString("Reset")), [=] { _text->setText(defaultDeletedMark); });
|
||||
addLeftButton(rpl::single(QString("Reset")), [=] { _text->setText(defaultDeletedMark); });
|
||||
|
||||
addButton(tr::lng_settings_save(), [=] { save(); });
|
||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||
addButton(tr::lng_settings_save(), [=] { save(); });
|
||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||
|
||||
connect(_text, &Ui::InputField::submitted, [=] { submit(); });
|
||||
connect(_text, &Ui::InputField::submitted, [=] { submit(); });
|
||||
}
|
||||
|
||||
void EditDeletedMarkBox::setInnerFocus() {
|
||||
_text->setFocusFast();
|
||||
void EditDeletedMarkBox::setInnerFocus()
|
||||
{
|
||||
_text->setFocusFast();
|
||||
}
|
||||
|
||||
void EditDeletedMarkBox::submit() {
|
||||
if (_text->getLastText().trimmed().isEmpty()) {
|
||||
_text->setFocus();
|
||||
_text->showError();
|
||||
} else {
|
||||
save();
|
||||
}
|
||||
void EditDeletedMarkBox::submit()
|
||||
{
|
||||
if (_text->getLastText().trimmed().isEmpty())
|
||||
{
|
||||
_text->setFocus();
|
||||
_text->showError();
|
||||
}
|
||||
else
|
||||
{
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
void EditDeletedMarkBox::resizeEvent(QResizeEvent *e) {
|
||||
BoxContent::resizeEvent(e);
|
||||
void EditDeletedMarkBox::resizeEvent(QResizeEvent* e)
|
||||
{
|
||||
BoxContent::resizeEvent(e);
|
||||
|
||||
_text->resize(
|
||||
width()
|
||||
- st::boxPadding.left()
|
||||
- st::newGroupInfoPadding.left()
|
||||
- st::boxPadding.right(),
|
||||
_text->height());
|
||||
_text->resize(
|
||||
width()
|
||||
- st::boxPadding.left()
|
||||
- st::newGroupInfoPadding.left()
|
||||
- st::boxPadding.right(),
|
||||
_text->height());
|
||||
|
||||
const auto left = st::boxPadding.left() + st::newGroupInfoPadding.left();
|
||||
_text->moveToLeft(left, st::contactPadding.top());
|
||||
const auto left = st::boxPadding.left() + st::newGroupInfoPadding.left();
|
||||
_text->moveToLeft(left, st::contactPadding.top());
|
||||
}
|
||||
|
||||
void EditDeletedMarkBox::save() {
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
settings->set_deletedMark(_text->getLastText());
|
||||
AyuSettings::save();
|
||||
void EditDeletedMarkBox::save()
|
||||
{
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
settings->set_deletedMark(_text->getLastText());
|
||||
AyuSettings::save();
|
||||
|
||||
closeBox();
|
||||
closeBox();
|
||||
}
|
||||
|
|
|
@ -7,25 +7,26 @@
|
|||
|
||||
#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 setInnerFocus() override;
|
||||
|
||||
void prepare() override;
|
||||
void prepare() override;
|
||||
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void resizeEvent(QResizeEvent* e) override;
|
||||
|
||||
private:
|
||||
void submit();
|
||||
void submit();
|
||||
|
||||
void save();
|
||||
void save();
|
||||
|
||||
object_ptr<Ui::InputField> _text;
|
||||
object_ptr<Ui::InputField> _text;
|
||||
};
|
||||
|
|
|
@ -7,85 +7,93 @@
|
|||
|
||||
#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 *) :
|
||||
_text(
|
||||
this,
|
||||
st::defaultInputField,
|
||||
rpl::single(QString("Edited mark")),
|
||||
AyuSettings::getInstance().editedMark) {
|
||||
|
||||
EditEditedMarkBox::EditEditedMarkBox(QWidget*) :
|
||||
_text(
|
||||
this,
|
||||
st::defaultInputField,
|
||||
rpl::single(QString("Edited mark")),
|
||||
AyuSettings::getInstance().editedMark)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void EditEditedMarkBox::prepare() {
|
||||
const auto defaultEditedMark = tr::lng_edited(tr::now);
|
||||
auto newHeight = st::contactPadding.top() + _text->height();
|
||||
void EditEditedMarkBox::prepare()
|
||||
{
|
||||
const auto defaultEditedMark = tr::lng_edited(tr::now);
|
||||
auto newHeight = st::contactPadding.top() + _text->height();
|
||||
|
||||
setTitle(rpl::single(QString("Edit edited Mark")));
|
||||
setTitle(rpl::single(QString("Edit edited Mark")));
|
||||
|
||||
newHeight += st::boxPadding.bottom() + st::contactPadding.bottom();
|
||||
setDimensions(st::boxWidth, newHeight);
|
||||
newHeight += st::boxPadding.bottom() + st::contactPadding.bottom();
|
||||
setDimensions(st::boxWidth, newHeight);
|
||||
|
||||
addLeftButton(rpl::single(QString("Reset")), [=] { _text->setText(defaultEditedMark); });
|
||||
addButton(tr::lng_settings_save(), [=] { save(); });
|
||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||
addLeftButton(rpl::single(QString("Reset")), [=] { _text->setText(defaultEditedMark); });
|
||||
addButton(tr::lng_settings_save(), [=] { save(); });
|
||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||
|
||||
connect(_text, &Ui::InputField::submitted, [=] { submit(); });
|
||||
connect(_text, &Ui::InputField::submitted, [=] { submit(); });
|
||||
}
|
||||
|
||||
|
||||
void EditEditedMarkBox::setInnerFocus() {
|
||||
_text->setFocusFast();
|
||||
void EditEditedMarkBox::setInnerFocus()
|
||||
{
|
||||
_text->setFocusFast();
|
||||
}
|
||||
|
||||
void EditEditedMarkBox::submit() {
|
||||
if (_text->getLastText().trimmed().isEmpty()) {
|
||||
_text->setFocus();
|
||||
_text->showError();
|
||||
} else {
|
||||
save();
|
||||
}
|
||||
void EditEditedMarkBox::submit()
|
||||
{
|
||||
if (_text->getLastText().trimmed().isEmpty())
|
||||
{
|
||||
_text->setFocus();
|
||||
_text->showError();
|
||||
}
|
||||
else
|
||||
{
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
void EditEditedMarkBox::resizeEvent(QResizeEvent *e) {
|
||||
BoxContent::resizeEvent(e);
|
||||
void EditEditedMarkBox::resizeEvent(QResizeEvent* e)
|
||||
{
|
||||
BoxContent::resizeEvent(e);
|
||||
|
||||
_text->resize(
|
||||
width()
|
||||
- st::boxPadding.left()
|
||||
- st::newGroupInfoPadding.left()
|
||||
- st::boxPadding.right(),
|
||||
_text->height());
|
||||
_text->resize(
|
||||
width()
|
||||
- st::boxPadding.left()
|
||||
- st::newGroupInfoPadding.left()
|
||||
- st::boxPadding.right(),
|
||||
_text->height());
|
||||
|
||||
const auto left = st::boxPadding.left() + st::newGroupInfoPadding.left();
|
||||
_text->moveToLeft(left, st::contactPadding.top());
|
||||
const auto left = st::boxPadding.left() + st::newGroupInfoPadding.left();
|
||||
_text->moveToLeft(left, st::contactPadding.top());
|
||||
}
|
||||
|
||||
void EditEditedMarkBox::save() {
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
settings->set_editedMark(_text->getLastText());
|
||||
AyuSettings::save();
|
||||
void EditEditedMarkBox::save()
|
||||
{
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
settings->set_editedMark(_text->getLastText());
|
||||
AyuSettings::save();
|
||||
|
||||
closeBox();
|
||||
}
|
||||
closeBox();
|
||||
}
|
||||
|
|
|
@ -7,25 +7,26 @@
|
|||
|
||||
#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 setInnerFocus() override;
|
||||
|
||||
void prepare() override;
|
||||
void prepare() override;
|
||||
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void resizeEvent(QResizeEvent* e) override;
|
||||
|
||||
private:
|
||||
void submit();
|
||||
void submit();
|
||||
|
||||
void save();
|
||||
void save();
|
||||
|
||||
object_ptr<Ui::InputField> _text;
|
||||
};
|
||||
object_ptr<Ui::InputField> _text;
|
||||
};
|
||||
|
|
|
@ -6,97 +6,119 @@
|
|||
// 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 {
|
||||
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>();
|
||||
|
||||
void VoiceConfirmBox(not_null<Ui::GenericBox *> box, Ui::ConfirmBoxArgs &&args) {
|
||||
const auto weak = Ui::MakeWeak(box);
|
||||
const auto lifetime = box->lifetime().make_state<rpl::lifetime>();
|
||||
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)
|
||||
{
|
||||
label->setClickHandlerFilter(std::move(args.labelFilter));
|
||||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
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))
|
||||
{
|
||||
callback();
|
||||
}
|
||||
}
|
||||
else if (const auto callbackPtr = std::get_if<2>(&confirmed))
|
||||
{
|
||||
if (auto callback = (*callbackPtr))
|
||||
{
|
||||
callback(crl::guard(weak, [=] { weak->closeBox(); }));
|
||||
}
|
||||
}
|
||||
else if (weak)
|
||||
{
|
||||
weak->closeBox();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
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)) {
|
||||
callback(crl::guard(weak, [=] { weak->closeBox(); }));
|
||||
}
|
||||
} 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)]()
|
||||
{
|
||||
lifetime->destroy();
|
||||
c();
|
||||
|
||||
const auto confirmButton = box->addButton(
|
||||
v::text::take_plain(std::move(args.confirmText), tr::lng_box_ok()),
|
||||
[=, c = prepareCallback(args.confirmed)]() {
|
||||
lifetime->destroy();
|
||||
c();
|
||||
weak->closeBox();
|
||||
},
|
||||
args.confirmStyle ? *args.confirmStyle : defaultButtonStyle);
|
||||
box->events(
|
||||
) | 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)
|
||||
{
|
||||
confirmButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton);
|
||||
}
|
||||
}, box->lifetime());
|
||||
|
||||
weak->closeBox();
|
||||
},
|
||||
args.confirmStyle ? *args.confirmStyle : defaultButtonStyle);
|
||||
box->events(
|
||||
) | rpl::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) {
|
||||
confirmButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton);
|
||||
}
|
||||
}, box->lifetime());
|
||||
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)]()
|
||||
{
|
||||
lifetime->destroy();
|
||||
c();
|
||||
}),
|
||||
args.cancelStyle ? *args.cancelStyle : defaultButtonStyle);
|
||||
|
||||
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)]() {
|
||||
lifetime->destroy();
|
||||
c();
|
||||
}),
|
||||
args.cancelStyle ? *args.cancelStyle : defaultButtonStyle);
|
||||
box->boxClosing(
|
||||
) | start_with_next(crl::guard(cancelButton, [=]
|
||||
{
|
||||
cancelButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton);
|
||||
}), *lifetime);
|
||||
}
|
||||
|
||||
box->boxClosing(
|
||||
) | rpl::start_with_next(crl::guard(cancelButton, [=] {
|
||||
cancelButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton);
|
||||
}), *lifetime);
|
||||
}
|
||||
if (args.strictCancel)
|
||||
{
|
||||
lifetime->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
if (args.strictCancel) {
|
||||
lifetime->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
object_ptr<Ui::GenericBox> MakeConfirmBox(Ui::ConfirmBoxArgs &&args) {
|
||||
return Box(VoiceConfirmBox, std::move(args));
|
||||
}
|
||||
|
||||
object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text) {
|
||||
return MakeConfirmBox({
|
||||
.text = std::move(text),
|
||||
.inform = true,
|
||||
});
|
||||
}
|
||||
object_ptr<Ui::GenericBox> MakeConfirmBox(Ui::ConfirmBoxArgs&& args)
|
||||
{
|
||||
return Box(VoiceConfirmBox, std::move(args));
|
||||
}
|
||||
|
||||
object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text)
|
||||
{
|
||||
return MakeConfirmBox({
|
||||
.text = std::move(text),
|
||||
.inform = true,
|
||||
});
|
||||
}
|
||||
} // namespace AyuUi
|
||||
|
|
|
@ -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);
|
||||
|
||||
[[nodiscard]] object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text);
|
||||
[[nodiscard]] object_ptr<Ui::GenericBox> MakeConfirmBox(
|
||||
Ui::ConfirmBoxArgs&& args);
|
||||
|
||||
[[nodiscard]] object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text);
|
||||
} // namespace Ui
|
||||
|
|
|
@ -6,47 +6,56 @@
|
|||
// 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) {
|
||||
_ayuSubMenu = std::make_unique<Ui::PopupMenu>(parent, st::popupMenuWithIcons);
|
||||
}
|
||||
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), [=] {
|
||||
auto box = Box<MessageHistoryBox>(item);
|
||||
Ui::show(std::move(box));
|
||||
}, &st::menuIconInfo);
|
||||
}
|
||||
}
|
||||
void AyuPopupMenu::addHistoryAction(HistoryItem* item)
|
||||
{
|
||||
if (AyuDatabase::editedMessagesTableExists() && !((AyuDatabase::getEditedMessages(item)).empty()))
|
||||
{
|
||||
_ayuSubMenu->addAction(tr::ayu_EditsHistoryMenuText(tr::now), [=]
|
||||
{
|
||||
auto box = Box<MessageHistoryBox>(item);
|
||||
show(std::move(box));
|
||||
}, &st::menuIconInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void AyuPopupMenu::addHideMessageAction(HistoryItem *item) const {
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
const auto history = item->history();
|
||||
_ayuSubMenu->addAction(QString("Hide"), [=]() {
|
||||
const auto initKeepDeleted = settings->keepDeletedMessages;
|
||||
void AyuPopupMenu::addHideMessageAction(HistoryItem* item) const
|
||||
{
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
const auto history = item->history();
|
||||
_ayuSubMenu->addAction(QString("Hide"), [=]()
|
||||
{
|
||||
const auto initKeepDeleted = settings->keepDeletedMessages;
|
||||
|
||||
settings->set_keepDeletedMessages(false);
|
||||
history->destroyMessage(item);
|
||||
settings->set_keepDeletedMessages(initKeepDeleted);
|
||||
}, &st::menuIconClear);
|
||||
}
|
||||
settings->set_keepDeletedMessages(false);
|
||||
history->destroyMessage(item);
|
||||
settings->set_keepDeletedMessages(initKeepDeleted);
|
||||
}, &st::menuIconClear);
|
||||
}
|
||||
|
||||
void AyuPopupMenu::addReadUntilAction(HistoryItem *item) const {
|
||||
const auto history = item->history();
|
||||
_ayuSubMenu->addAction(tr::ayu_ReadUntilMenuText(tr::now), [=]() {
|
||||
AyuState::setAllowSendReadPacket(true);
|
||||
history->session().data().histories().readInboxOnNewMessage(item);
|
||||
}, &st::menuIconShowInChat);
|
||||
}
|
||||
} // namespace AyuUi
|
||||
void AyuPopupMenu::addReadUntilAction(HistoryItem* item) const
|
||||
{
|
||||
const auto history = item->history();
|
||||
_ayuSubMenu->addAction(tr::ayu_ReadUntilMenuText(tr::now), [=]()
|
||||
{
|
||||
AyuState::setAllowSendReadPacket(true);
|
||||
history->session().data().histories().readInboxOnNewMessage(item);
|
||||
}, &st::menuIconShowInChat);
|
||||
}
|
||||
} // namespace AyuUi
|
||||
|
|
|
@ -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);
|
||||
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
std::unique_ptr<Ui::PopupMenu> _ayuSubMenu;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,65 +5,74 @@
|
|||
//
|
||||
// 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)) {
|
||||
setupControls();
|
||||
addEditedMessagesToLayout(item);
|
||||
}
|
||||
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() {
|
||||
_content.create(this);
|
||||
void MessageHistoryBox::setupControls()
|
||||
{
|
||||
_content.create(this);
|
||||
|
||||
_content->resizeToWidth(st::boxWideWidth);
|
||||
_content->moveToLeft(0, 0);
|
||||
_content->resizeToWidth(st::boxWideWidth);
|
||||
_content->moveToLeft(0, 0);
|
||||
|
||||
_content->heightValue(
|
||||
) | rpl::start_to_stream(_contentHeight, _content->lifetime());
|
||||
_content->heightValue(
|
||||
) | start_to_stream(_contentHeight, _content->lifetime());
|
||||
|
||||
_scroll->setOwnedWidget(
|
||||
object_ptr<Ui::RpWidget>::fromRaw(_content));
|
||||
}
|
||||
_scroll->setOwnedWidget(
|
||||
object_ptr<RpWidget>::fromRaw(_content));
|
||||
}
|
||||
|
||||
void MessageHistoryBox::resizeEvent(QResizeEvent *e) {
|
||||
_scroll->resize(width(), height() - st::boxPhotoPadding.top() - st::boxPadding.bottom());
|
||||
_scroll->move(0, st::boxPadding.top());
|
||||
void MessageHistoryBox::resizeEvent(QResizeEvent* e)
|
||||
{
|
||||
_scroll->resize(width(), height() - st::boxPhotoPadding.top() - st::boxPadding.bottom());
|
||||
_scroll->move(0, st::boxPadding.top());
|
||||
|
||||
if (_content) {
|
||||
_content->resize(_scroll->width(), _content->height());
|
||||
}
|
||||
}
|
||||
if (_content)
|
||||
{
|
||||
_content->resize(_scroll->width(), _content->height());
|
||||
}
|
||||
}
|
||||
|
||||
void MessageHistoryBox::prepare() {
|
||||
setTitle(tr::ayu_EditsHistoryTitle());
|
||||
void MessageHistoryBox::prepare()
|
||||
{
|
||||
setTitle(tr::ayu_EditsHistoryTitle());
|
||||
|
||||
// setDimensionsToContent(st::boxWideWidth, _content);
|
||||
setDimensions(st::boxWideWidth, 900);
|
||||
Ui::SetupShadowsToScrollContent(this, _scroll, _contentHeight.events());
|
||||
}
|
||||
// setDimensionsToContent(st::boxWideWidth, _content);
|
||||
setDimensions(st::boxWideWidth, 900);
|
||||
SetupShadowsToScrollContent(this, _scroll, _contentHeight.events());
|
||||
}
|
||||
|
||||
void MessageHistoryBox::addEditedMessagesToLayout(HistoryItem *item) {
|
||||
auto messages = AyuDatabase::getEditedMessages(item);
|
||||
if (messages.empty()) {
|
||||
return;
|
||||
}
|
||||
void MessageHistoryBox::addEditedMessagesToLayout(HistoryItem* item)
|
||||
{
|
||||
auto messages = AyuDatabase::getEditedMessages(item);
|
||||
if (messages.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto &message: messages) {
|
||||
AddSkip(_content);
|
||||
AddDividerText(_content, rpl::single(QString::fromStdString(message.text)));
|
||||
AddSkip(_content);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto& message : messages)
|
||||
{
|
||||
AddSkip(_content);
|
||||
AddDividerText(_content, rpl::single(QString::fromStdString(message.text)));
|
||||
AddSkip(_content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,28 +6,30 @@
|
|||
// 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 {
|
||||
public:
|
||||
MessageHistoryBox(QWidget *, HistoryItem *item);
|
||||
namespace AyuUi
|
||||
{
|
||||
class MessageHistoryBox : public Ui::BoxContent
|
||||
{
|
||||
public:
|
||||
MessageHistoryBox(QWidget*, HistoryItem* item);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
protected:
|
||||
void prepare() override;
|
||||
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void resizeEvent(QResizeEvent* e) override;
|
||||
|
||||
private:
|
||||
void setupControls();
|
||||
private:
|
||||
void setupControls();
|
||||
|
||||
void addEditedMessagesToLayout(HistoryItem *item);
|
||||
void addEditedMessagesToLayout(HistoryItem* item);
|
||||
|
||||
object_ptr<Ui::VerticalLayout> _content;
|
||||
const base::unique_qptr<Ui::ScrollArea> _scroll;
|
||||
object_ptr<Ui::VerticalLayout> _content;
|
||||
const base::unique_qptr<Ui::ScrollArea> _scroll;
|
||||
|
||||
rpl::event_stream<int> _contentHeight;
|
||||
};
|
||||
}
|
||||
rpl::event_stream<int> _contentHeight;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,429 +5,475 @@
|
|||
//
|
||||
// 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 {
|
||||
namespace Settings
|
||||
{
|
||||
rpl::producer<QString> Ayu::title()
|
||||
{
|
||||
return tr::ayu_AyuPreferences();
|
||||
}
|
||||
|
||||
rpl::producer<QString> Ayu::title() {
|
||||
return tr::ayu_AyuPreferences();
|
||||
}
|
||||
Ayu::Ayu(
|
||||
QWidget* parent,
|
||||
not_null<Window::SessionController*> controller)
|
||||
: Section(parent)
|
||||
{
|
||||
setupContent(controller);
|
||||
}
|
||||
|
||||
Ayu::Ayu(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController *> controller)
|
||||
: Section(parent) {
|
||||
setupContent(controller);
|
||||
}
|
||||
void Ayu::SetupGhostEssentials(not_null<Ui::VerticalLayout*> container)
|
||||
{
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
|
||||
void Ayu::SetupGhostEssentials(not_null<Ui::VerticalLayout *> container) {
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
AddSubsectionTitle(container, tr::ayu_GhostEssentialsHeader());
|
||||
|
||||
AddSubsectionTitle(container, tr::ayu_GhostEssentialsHeader());
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_SendReadPackets(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->sendReadPackets)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled)
|
||||
{
|
||||
return (enabled != settings->sendReadPackets);
|
||||
}) | start_with_next([=](bool enabled)
|
||||
{
|
||||
settings->set_sendReadPackets(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_SendReadPackets(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->sendReadPackets)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->sendReadPackets);
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
settings->set_sendReadPackets(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_SendOnlinePackets(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->sendOnlinePackets)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled)
|
||||
{
|
||||
return (enabled != settings->sendOnlinePackets);
|
||||
}) | start_with_next([=](bool enabled)
|
||||
{
|
||||
settings->set_sendOnlinePackets(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_SendOnlinePackets(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->sendOnlinePackets)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->sendOnlinePackets);
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
settings->set_sendOnlinePackets(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_SendUploadProgress(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->sendUploadProgress)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled)
|
||||
{
|
||||
return (enabled != settings->sendUploadProgress);
|
||||
}) | start_with_next([=](bool enabled)
|
||||
{
|
||||
settings->set_sendUploadProgress(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_SendUploadProgress(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->sendUploadProgress)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->sendUploadProgress);
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
settings->set_sendUploadProgress(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_SendOfflinePacketAfterOnline(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->sendOfflinePacketAfterOnline)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled)
|
||||
{
|
||||
return (enabled != settings->sendOfflinePacketAfterOnline);
|
||||
}) | start_with_next([=](bool enabled)
|
||||
{
|
||||
settings->set_sendOfflinePacketAfterOnline(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_SendOfflinePacketAfterOnline(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->sendOfflinePacketAfterOnline)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->sendOfflinePacketAfterOnline);
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
settings->set_sendOfflinePacketAfterOnline(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_MarkReadAfterSend(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->markReadAfterSend)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled)
|
||||
{
|
||||
return (enabled != settings->markReadAfterSend);
|
||||
}) | start_with_next([=](bool enabled)
|
||||
{
|
||||
settings->set_markReadAfterSend(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_MarkReadAfterSend(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->markReadAfterSend)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->markReadAfterSend);
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
settings->set_markReadAfterSend(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_UseScheduledMessages(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->useScheduledMessages)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled)
|
||||
{
|
||||
return (enabled != settings->useScheduledMessages);
|
||||
}) | start_with_next([=](bool enabled)
|
||||
{
|
||||
settings->set_useScheduledMessages(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
}
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_UseScheduledMessages(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->useScheduledMessages)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->useScheduledMessages);
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
settings->set_useScheduledMessages(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
}
|
||||
void Ayu::SetupSpyEssentials(not_null<Ui::VerticalLayout*> container)
|
||||
{
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
|
||||
void Ayu::SetupSpyEssentials(not_null<Ui::VerticalLayout *> container) {
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
AddSubsectionTitle(container, tr::ayu_SpyEssentialsHeader());
|
||||
|
||||
AddSubsectionTitle(container, tr::ayu_SpyEssentialsHeader());
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_KeepDeletedMessages(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->keepDeletedMessages)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled)
|
||||
{
|
||||
return (enabled != settings->keepDeletedMessages);
|
||||
}) | start_with_next([=](bool enabled)
|
||||
{
|
||||
settings->set_keepDeletedMessages(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_KeepDeletedMessages(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->keepDeletedMessages)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->keepDeletedMessages);
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
settings->set_keepDeletedMessages(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_KeepMessagesHistory(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->keepMessagesHistory)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled)
|
||||
{
|
||||
return (enabled != settings->keepMessagesHistory);
|
||||
}) | start_with_next([=](bool enabled)
|
||||
{
|
||||
settings->set_keepMessagesHistory(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
}
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_KeepMessagesHistory(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->keepMessagesHistory)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->keepMessagesHistory);
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
settings->set_keepMessagesHistory(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
}
|
||||
void Ayu::SetupQoLToggles(not_null<Ui::VerticalLayout*> container)
|
||||
{
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
|
||||
void Ayu::SetupQoLToggles(not_null<Ui::VerticalLayout *> container) {
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
AddSubsectionTitle(container, tr::ayu_QoLTogglesHeader());
|
||||
|
||||
AddSubsectionTitle(container, tr::ayu_QoLTogglesHeader());
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_EnableAds(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->enableAds)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled)
|
||||
{
|
||||
return (enabled != settings->enableAds);
|
||||
}) | start_with_next([=](bool enabled)
|
||||
{
|
||||
settings->set_enableAds(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
}
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_EnableAds(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->enableAds)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->enableAds);
|
||||
}) | rpl::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)
|
||||
{
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
|
||||
void Ayu::SetupCustomization(not_null<Ui::VerticalLayout *> container,
|
||||
not_null<Window::SessionController *> controller) {
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
AddSubsectionTitle(container, tr::ayu_CustomizationHeader());
|
||||
|
||||
AddSubsectionTitle(container, tr::ayu_CustomizationHeader());
|
||||
auto btn = AddButtonWithLabel(
|
||||
container,
|
||||
tr::ayu_DeletedMarkText(),
|
||||
AyuSettings::get_deletedMarkReactive(),
|
||||
st::settingsButtonNoIcon
|
||||
);
|
||||
btn->addClickHandler([=]()
|
||||
{
|
||||
auto box = Box<EditDeletedMarkBox>();
|
||||
Ui::show(std::move(box));
|
||||
});
|
||||
|
||||
auto btn = AddButtonWithLabel(
|
||||
container,
|
||||
tr::ayu_DeletedMarkText(),
|
||||
AyuSettings::get_deletedMarkReactive(),
|
||||
st::settingsButtonNoIcon
|
||||
);
|
||||
btn->addClickHandler([=]() {
|
||||
auto box = Box<EditDeletedMarkBox>();
|
||||
Ui::show(std::move(box));
|
||||
});
|
||||
auto btn2 = AddButtonWithLabel(
|
||||
container,
|
||||
tr::ayu_EditedMarkText(),
|
||||
AyuSettings::get_editedMarkReactive(),
|
||||
st::settingsButtonNoIcon
|
||||
);
|
||||
btn2->addClickHandler([=]()
|
||||
{
|
||||
auto box = Box<EditEditedMarkBox>();
|
||||
Ui::show(std::move(box));
|
||||
});
|
||||
|
||||
auto btn2 = AddButtonWithLabel(
|
||||
container,
|
||||
tr::ayu_EditedMarkText(),
|
||||
AyuSettings::get_editedMarkReactive(),
|
||||
st::settingsButtonNoIcon
|
||||
);
|
||||
btn2->addClickHandler([=]() {
|
||||
auto box = Box<EditEditedMarkBox>();
|
||||
Ui::show(std::move(box));
|
||||
});
|
||||
SetupRecentStickersLimitSlider(container);
|
||||
|
||||
SetupRecentStickersLimitSlider(container);
|
||||
SetupShowPeerId(container, controller);
|
||||
|
||||
SetupShowPeerId(container, controller);
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_ShowGhostToggleInDrawer(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->showGhostToggleInDrawer)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled)
|
||||
{
|
||||
return (enabled != settings->showGhostToggleInDrawer);
|
||||
}) | start_with_next([=](bool enabled)
|
||||
{
|
||||
settings->set_showGhostToggleInDrawer(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_ShowGhostToggleInDrawer(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->showGhostToggleInDrawer)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->showGhostToggleInDrawer);
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
settings->set_showGhostToggleInDrawer(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_SettingsShowMessageSeconds(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->showMessageSeconds)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled)
|
||||
{
|
||||
return (enabled != settings->showMessageSeconds);
|
||||
}) | start_with_next([=](bool enabled)
|
||||
{
|
||||
settings->set_showMessageSeconds(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
tr::ayu_SettingsShowMessageSeconds(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->showMessageSeconds)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->showMessageSeconds);
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
settings->set_showMessageSeconds(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
AddDividerText(container, tr::ayu_SettingsCustomizationHint());
|
||||
}
|
||||
|
||||
AddDividerText(container, tr::ayu_SettingsCustomizationHint());
|
||||
}
|
||||
void Ayu::SetupShowPeerId(not_null<Ui::VerticalLayout*> container,
|
||||
not_null<Window::SessionController*> controller)
|
||||
{
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
|
||||
void Ayu::SetupShowPeerId(not_null<Ui::VerticalLayout *> container,
|
||||
not_null<Window::SessionController *> controller) {
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
const auto options = std::vector{
|
||||
QString(tr::ayu_SettingsShowID_Hide(tr::now)),
|
||||
QString("Telegram API"),
|
||||
QString("Bot API")
|
||||
};
|
||||
|
||||
const auto options = std::vector{
|
||||
QString(tr::ayu_SettingsShowID_Hide(tr::now)),
|
||||
QString("Telegram API"),
|
||||
QString("Bot API")
|
||||
};
|
||||
auto currentVal = AyuSettings::get_showPeerIdReactive() | rpl::map([=](int val)
|
||||
{
|
||||
return options[val];
|
||||
});
|
||||
|
||||
auto currentVal = AyuSettings::get_showPeerIdReactive() | rpl::map([=](int val) {
|
||||
return options[val];
|
||||
});
|
||||
const auto button = AddButtonWithLabel(
|
||||
container,
|
||||
tr::ayu_SettingsShowID(),
|
||||
currentVal,
|
||||
st::settingsButtonNoIcon);
|
||||
button->addClickHandler([=]
|
||||
{
|
||||
controller->show(Box([=](not_null<Ui::GenericBox*> box)
|
||||
{
|
||||
const auto save = [=](int index)
|
||||
{
|
||||
settings->set_showPeerId(index);
|
||||
AyuSettings::save();
|
||||
};
|
||||
SingleChoiceBox(box, {
|
||||
.title = tr::ayu_SettingsShowID(),
|
||||
.options = options,
|
||||
.initialSelection = settings->showPeerId,
|
||||
.callback = save,
|
||||
});
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
const auto button = AddButtonWithLabel(
|
||||
container,
|
||||
tr::ayu_SettingsShowID(),
|
||||
currentVal,
|
||||
st::settingsButtonNoIcon);
|
||||
button->addClickHandler([=] {
|
||||
controller->show(Box([=](not_null<Ui::GenericBox *> box) {
|
||||
const auto save = [=](int index) {
|
||||
settings->set_showPeerId(index);
|
||||
AyuSettings::save();
|
||||
};
|
||||
SingleChoiceBox(box, {
|
||||
.title = tr::ayu_SettingsShowID(),
|
||||
.options = options,
|
||||
.initialSelection = settings->showPeerId,
|
||||
.callback = save,
|
||||
});
|
||||
}));
|
||||
});
|
||||
}
|
||||
void Ayu::SetupRecentStickersLimitSlider(not_null<Ui::VerticalLayout*> container)
|
||||
{
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
|
||||
void Ayu::SetupRecentStickersLimitSlider(not_null<Ui::VerticalLayout *> container) {
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
container->add(
|
||||
CreateButton(
|
||||
container,
|
||||
tr::ayu_SettingsRecentStickersCount(),
|
||||
st::settingsButtonNoIcon)
|
||||
);
|
||||
|
||||
container->add(
|
||||
CreateButton(
|
||||
container,
|
||||
tr::ayu_SettingsRecentStickersCount(),
|
||||
st::settingsButtonNoIcon)
|
||||
);
|
||||
auto recentStickersLimitSlider = MakeSliderWithLabel(
|
||||
container,
|
||||
st::settingsScale,
|
||||
st::settingsScaleLabel,
|
||||
st::normalFont->spacew * 2,
|
||||
st::settingsScaleLabel.style.font->width("300%"));
|
||||
container->add(
|
||||
std::move(recentStickersLimitSlider.widget),
|
||||
st::settingsScalePadding);
|
||||
const auto slider = recentStickersLimitSlider.slider;
|
||||
const auto label = recentStickersLimitSlider.label;
|
||||
|
||||
auto recentStickersLimitSlider = MakeSliderWithLabel(
|
||||
container,
|
||||
st::settingsScale,
|
||||
st::settingsScaleLabel,
|
||||
st::normalFont->spacew * 2,
|
||||
st::settingsScaleLabel.style.font->width("300%"));
|
||||
container->add(
|
||||
std::move(recentStickersLimitSlider.widget),
|
||||
st::settingsScalePadding);
|
||||
const auto slider = recentStickersLimitSlider.slider;
|
||||
const auto label = recentStickersLimitSlider.label;
|
||||
const auto updateLabel = [=](int amount)
|
||||
{
|
||||
label->setText(QString::number(amount));
|
||||
};
|
||||
updateLabel(settings->recentStickersCount);
|
||||
|
||||
const auto updateLabel = [=](int amount) {
|
||||
label->setText(QString::number(amount));
|
||||
};
|
||||
updateLabel(settings->recentStickersCount);
|
||||
slider->setPseudoDiscrete(
|
||||
100 + 1, // thx tg
|
||||
[=](int amount) { return amount; },
|
||||
settings->recentStickersCount,
|
||||
[=](int amount) { updateLabel(amount); },
|
||||
[=](int amount)
|
||||
{
|
||||
updateLabel(amount);
|
||||
|
||||
slider->setPseudoDiscrete(
|
||||
100 + 1, // thx tg
|
||||
[=](int amount) { return amount; },
|
||||
settings->recentStickersCount,
|
||||
[=](int amount) { updateLabel(amount); },
|
||||
[=](int amount) {
|
||||
updateLabel(amount);
|
||||
settings->set_recentStickersCount(amount);
|
||||
AyuSettings::save();
|
||||
});
|
||||
}
|
||||
|
||||
settings->set_recentStickersCount(amount);
|
||||
AyuSettings::save();
|
||||
});
|
||||
}
|
||||
void Ayu::SetupAyuSync(not_null<Ui::VerticalLayout*> container)
|
||||
{
|
||||
AddSubsectionTitle(container, rpl::single(QString("AyuSync")));
|
||||
|
||||
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([=]
|
||||
{
|
||||
auto controller = &AyuSync::getControllerInstance();
|
||||
controller->initializeAgent();
|
||||
});
|
||||
}
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
rpl::single(text),
|
||||
st::settingsButtonNoIcon
|
||||
)->addClickHandler([=] {
|
||||
auto controller = &AyuSync::getControllerInstance();
|
||||
controller->initializeAgent();
|
||||
});
|
||||
}
|
||||
void Ayu::SetupBetaFunctions(not_null<Ui::VerticalLayout*> container)
|
||||
{
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
|
||||
void Ayu::SetupBetaFunctions(not_null<Ui::VerticalLayout *> container) {
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
AddSubsectionTitle(container, rpl::single(QString("Beta functions")));
|
||||
|
||||
AddSubsectionTitle(container, rpl::single(QString("Beta functions")));
|
||||
AddButton(
|
||||
container,
|
||||
rpl::single(QString("Send sticker confirmation")),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->stickerConfirmation)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled)
|
||||
{
|
||||
return (enabled != settings->stickerConfirmation);
|
||||
}) | start_with_next([=](bool enabled)
|
||||
{
|
||||
settings->set_stickerConfirmation(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
rpl::single(QString("Send sticker confirmation")),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->stickerConfirmation)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->stickerConfirmation);
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
settings->set_stickerConfirmation(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
AddButton(
|
||||
container,
|
||||
rpl::single(QString("Send GIF confirmation")),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->GIFConfirmation)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled)
|
||||
{
|
||||
return (enabled != settings->GIFConfirmation);
|
||||
}) | start_with_next([=](bool enabled)
|
||||
{
|
||||
settings->set_GIFConfirmation(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
rpl::single(QString("Send GIF confirmation")),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->GIFConfirmation)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->GIFConfirmation);
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
settings->set_GIFConfirmation(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
AddButton(
|
||||
container,
|
||||
rpl::single(QString("Send voice confirmation")),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->voiceConfirmation)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled)
|
||||
{
|
||||
return (enabled != settings->voiceConfirmation);
|
||||
}) | start_with_next([=](bool enabled)
|
||||
{
|
||||
settings->set_voiceConfirmation(enabled);
|
||||
AyuSettings::save();
|
||||
}, container->lifetime());
|
||||
}
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
rpl::single(QString("Send voice confirmation")),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->voiceConfirmation)
|
||||
)->toggledValue(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return (enabled != settings->voiceConfirmation);
|
||||
}) | rpl::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)
|
||||
{
|
||||
AddSkip(container);
|
||||
SetupGhostEssentials(container);
|
||||
|
||||
void Ayu::SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container,
|
||||
not_null<Window::SessionController *> controller) {
|
||||
AddSkip(container);
|
||||
SetupGhostEssentials(container);
|
||||
AddDivider(container);
|
||||
|
||||
AddDivider(container);
|
||||
AddSkip(container);
|
||||
SetupSpyEssentials(container);
|
||||
|
||||
AddSkip(container);
|
||||
SetupSpyEssentials(container);
|
||||
AddDivider(container);
|
||||
|
||||
AddDivider(container);
|
||||
AddSkip(container);
|
||||
SetupQoLToggles(container);
|
||||
|
||||
AddSkip(container);
|
||||
SetupQoLToggles(container);
|
||||
AddDivider(container);
|
||||
|
||||
AddDivider(container);
|
||||
AddSkip(container);
|
||||
SetupCustomization(container, controller);
|
||||
|
||||
AddSkip(container);
|
||||
SetupCustomization(container, controller);
|
||||
AddSkip(container);
|
||||
SetupAyuSync(container);
|
||||
|
||||
AddSkip(container);
|
||||
SetupAyuSync(container);
|
||||
AddDivider(container);
|
||||
|
||||
AddDivider(container);
|
||||
AddSkip(container);
|
||||
SetupBetaFunctions(container);
|
||||
|
||||
AddSkip(container);
|
||||
SetupBetaFunctions(container);
|
||||
AddDividerText(container, tr::ayu_SettingsWatermark());
|
||||
}
|
||||
|
||||
AddDividerText(container, tr::ayu_SettingsWatermark());
|
||||
}
|
||||
void Ayu::setupContent(not_null<Window::SessionController*> controller)
|
||||
{
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
void Ayu::setupContent(not_null<Window::SessionController *> controller) {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
SetupAyuGramSettings(content, controller);
|
||||
|
||||
SetupAyuGramSettings(content, controller);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
}
|
||||
ResizeFitChild(this, content);
|
||||
}
|
||||
} // namespace Settings
|
||||
|
||||
|
|
|
@ -11,39 +11,42 @@
|
|||
|
||||
class BoxContent;
|
||||
|
||||
namespace Window {
|
||||
class Controller;
|
||||
namespace Window
|
||||
{
|
||||
class Controller;
|
||||
|
||||
class SessionController;
|
||||
class SessionController;
|
||||
} // namespace Window
|
||||
|
||||
namespace Settings {
|
||||
class Ayu : public Section<Ayu> {
|
||||
public:
|
||||
Ayu(QWidget *parent, not_null<Window::SessionController *> controller);
|
||||
namespace Settings
|
||||
{
|
||||
class Ayu : public Section<Ayu>
|
||||
{
|
||||
public:
|
||||
Ayu(QWidget* parent, not_null<Window::SessionController*> controller);
|
||||
|
||||
[[nodiscard]] rpl::producer<QString> title() override;
|
||||
[[nodiscard]] rpl::producer<QString> title() override;
|
||||
|
||||
private:
|
||||
void SetupGhostEssentials(not_null<Ui::VerticalLayout *> container);
|
||||
private:
|
||||
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 setupContent(not_null<Window::SessionController *> controller);
|
||||
};
|
||||
void SetupAyuGramSettings(not_null<Ui::VerticalLayout*> container, not_null<Window::SessionController*> null);
|
||||
|
||||
void setupContent(not_null<Window::SessionController*> controller);
|
||||
};
|
||||
} // namespace Settings
|
||||
|
|
|
@ -5,47 +5,55 @@
|
|||
//
|
||||
// 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) {
|
||||
auto resultId = QString::number(peerIsUser(peer->id)
|
||||
? peerToUser(peer->id).bare
|
||||
: peerIsChat(peer->id)
|
||||
? peerToChat(peer->id).bare
|
||||
: peerIsChannel(peer->id)
|
||||
? peerToChannel(peer->id).bare
|
||||
: peer->id.value);
|
||||
QString IDString(not_null<PeerData*> peer)
|
||||
{
|
||||
auto resultId = QString::number(peerIsUser(peer->id)
|
||||
? peerToUser(peer->id).bare
|
||||
: peerIsChat(peer->id)
|
||||
? peerToChat(peer->id).bare
|
||||
: peerIsChannel(peer->id)
|
||||
? peerToChannel(peer->id).bare
|
||||
: peer->id.value);
|
||||
|
||||
auto const settings = &AyuSettings::getInstance();
|
||||
if (settings->showPeerId == 2) {
|
||||
if (peer->isChannel()) {
|
||||
resultId = QString::number(peerToChannel(peer->id).bare - kMaxChannelId).prepend("-");
|
||||
} else if (peer->isChat()) {
|
||||
resultId = resultId.prepend("-");
|
||||
}
|
||||
}
|
||||
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())
|
||||
{
|
||||
resultId = resultId.prepend("-");
|
||||
}
|
||||
}
|
||||
|
||||
return resultId;
|
||||
return resultId;
|
||||
}
|
||||
|
||||
QString IDString(MsgId topic_root_id) {
|
||||
auto resultId = QString::number(topic_root_id.bare);
|
||||
QString IDString(MsgId topic_root_id)
|
||||
{
|
||||
auto resultId = QString::number(topic_root_id.bare);
|
||||
|
||||
return resultId;
|
||||
return resultId;
|
||||
}
|
||||
|
||||
|
||||
rpl::producer<TextWithEntities> IDValue(not_null<PeerData *> peer) {
|
||||
return rpl::single(IDString(peer)) | Ui::Text::ToWithEntities();
|
||||
rpl::producer<TextWithEntities> IDValue(not_null<PeerData*> peer)
|
||||
{
|
||||
return rpl::single(IDString(peer)) | Ui::Text::ToWithEntities();
|
||||
}
|
||||
|
||||
rpl::producer<TextWithEntities> IDValue(MsgId topic_root_id) {
|
||||
return rpl::single(IDString(topic_root_id)) | Ui::Text::ToWithEntities();
|
||||
}
|
||||
rpl::producer<TextWithEntities> IDValue(MsgId topic_root_id)
|
||||
{
|
||||
return rpl::single(IDString(topic_root_id)) | Ui::Text::ToWithEntities();
|
||||
}
|
||||
|
|
|
@ -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(MsgId topic_root_id);
|
||||
rpl::producer<TextWithEntities> IDValue(not_null<PeerData*> peer);
|
||||
rpl::producer<TextWithEntities> IDValue(MsgId topic_root_id);
|
||||
|
|
|
@ -481,29 +481,32 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
|
|||
});
|
||||
}
|
||||
|
||||
if (settings->showPeerId != 0) {
|
||||
|
||||
auto idDrawableText = IDValue(
|
||||
user
|
||||
) | rpl::map([](TextWithEntities &&text) {
|
||||
return Ui::Text::Code(text.text);
|
||||
});
|
||||
auto idInfo = addInfoOneLine(
|
||||
rpl::single(QString("ID")),
|
||||
std::move(idDrawableText),
|
||||
tr::ayu_ContextCopyID(tr::now)
|
||||
);
|
||||
if (settings->showPeerId != 0)
|
||||
{
|
||||
auto idDrawableText = IDValue(
|
||||
user
|
||||
) | rpl::map([](TextWithEntities&& text)
|
||||
{
|
||||
return Ui::Text::Code(text.text);
|
||||
});
|
||||
auto idInfo = addInfoOneLine(
|
||||
rpl::single(QString("ID")),
|
||||
std::move(idDrawableText),
|
||||
tr::ayu_ContextCopyID(tr::now)
|
||||
);
|
||||
|
||||
idInfo.text->setClickHandlerFilter([=](auto &&...) {
|
||||
const auto idText = IDString(user);
|
||||
if (!idText.isEmpty()) {
|
||||
QGuiApplication::clipboard()->setText(idText);
|
||||
const auto msg = tr::ayu_IDCopiedToast(tr::now);
|
||||
controller->showToast(msg);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
idInfo.text->setClickHandlerFilter([=](auto&&...)
|
||||
{
|
||||
const auto idText = IDString(user);
|
||||
if (!idText.isEmpty())
|
||||
{
|
||||
QGuiApplication::clipboard()->setText(idText);
|
||||
const auto msg = tr::ayu_IDCopiedToast(tr::now);
|
||||
controller->showToast(msg);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
AddMainButton(
|
||||
result,
|
||||
|
@ -566,45 +569,53 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
|
|||
addTranslateToMenu(about.text, AboutValue(_peer));
|
||||
}
|
||||
|
||||
if (settings->showPeerId != 0 && !_topic) {
|
||||
auto idDrawableText = IDValue(
|
||||
_peer
|
||||
) | rpl::map([](TextWithEntities &&text) {
|
||||
return Ui::Text::Code(text.text);
|
||||
});
|
||||
auto idInfo = addInfoOneLine(
|
||||
rpl::single(QString("ID")),
|
||||
std::move(idDrawableText),
|
||||
tr::ayu_ContextCopyID(tr::now)
|
||||
);
|
||||
if (settings->showPeerId != 0 && !_topic)
|
||||
{
|
||||
auto idDrawableText = IDValue(
|
||||
_peer
|
||||
) | rpl::map([](TextWithEntities&& text)
|
||||
{
|
||||
return Ui::Text::Code(text.text);
|
||||
});
|
||||
auto idInfo = addInfoOneLine(
|
||||
rpl::single(QString("ID")),
|
||||
std::move(idDrawableText),
|
||||
tr::ayu_ContextCopyID(tr::now)
|
||||
);
|
||||
|
||||
idInfo.text->setClickHandlerFilter([=, peer = _peer](auto &&...) {
|
||||
const auto idText = IDString(peer);
|
||||
if (!idText.isEmpty()) {
|
||||
QGuiApplication::clipboard()->setText(idText);
|
||||
const auto msg = tr::ayu_IDCopiedToast(tr::now);
|
||||
controller->showToast(msg);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
idInfo.text->setClickHandlerFilter([=, peer = _peer](auto&&...)
|
||||
{
|
||||
const auto idText = IDString(peer);
|
||||
if (!idText.isEmpty())
|
||||
{
|
||||
QGuiApplication::clipboard()->setText(idText);
|
||||
const auto msg = tr::ayu_IDCopiedToast(tr::now);
|
||||
controller->showToast(msg);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
return Ui::Text::Code(text.text);
|
||||
) | rpl::map([](TextWithEntities&& text)
|
||||
{
|
||||
return Ui::Text::Code(text.text);
|
||||
});
|
||||
auto idInfo = addInfoOneLine(
|
||||
rpl::single(QString("ID")),
|
||||
std::move(idDrawableText),
|
||||
tr::ayu_ContextCopyID(tr::now)
|
||||
rpl::single(QString("ID")),
|
||||
std::move(idDrawableText),
|
||||
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);
|
||||
|
|
Loading…
Add table
Reference in a new issue