mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
feat: fetch devs and supporters
This commit is contained in:
parent
ab26e3d4fa
commit
576822b1ff
7 changed files with 248 additions and 59 deletions
|
@ -118,6 +118,8 @@ set(ayugram_files
|
||||||
ayu/utils/telegram_helpers.h
|
ayu/utils/telegram_helpers.h
|
||||||
ayu/utils/windows_utils.cpp
|
ayu/utils/windows_utils.cpp
|
||||||
ayu/utils/windows_utils.h
|
ayu/utils/windows_utils.h
|
||||||
|
ayu/utils/rc_manager.cpp
|
||||||
|
ayu/utils/rc_manager.h
|
||||||
ayu/utils/taptic_engine/taptic_engine.cpp
|
ayu/utils/taptic_engine/taptic_engine.cpp
|
||||||
ayu/utils/taptic_engine/taptic_engine.h
|
ayu/utils/taptic_engine/taptic_engine.h
|
||||||
ayu/utils/taptic_engine/platform/taptic_engine_dummy.cpp
|
ayu/utils/taptic_engine/platform/taptic_engine_dummy.cpp
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "ayu/ayu_worker.h"
|
#include "ayu/ayu_worker.h"
|
||||||
#include "ayu/data/ayu_database.h"
|
#include "ayu/data/ayu_database.h"
|
||||||
#include "lang/lang_instance.h"
|
#include "lang/lang_instance.h"
|
||||||
|
#include "utils/rc_manager.h"
|
||||||
|
|
||||||
namespace AyuInfra {
|
namespace AyuInfra {
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ void initLang() {
|
||||||
QString id = Lang::GetInstance().id();
|
QString id = Lang::GetInstance().id();
|
||||||
QString baseId = Lang::GetInstance().baseId();
|
QString baseId = Lang::GetInstance().baseId();
|
||||||
if (id.isEmpty()) {
|
if (id.isEmpty()) {
|
||||||
LOG(("Language ID not found!"));
|
LOG(("Language is not loaded"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AyuLanguage::init();
|
AyuLanguage::init();
|
||||||
|
@ -41,11 +42,16 @@ void initWorker() {
|
||||||
AyuWorker::initialize();
|
AyuWorker::initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initRCManager() {
|
||||||
|
RCManager::getInstance().start();
|
||||||
|
}
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
initLang();
|
initLang();
|
||||||
initDatabase();
|
initDatabase();
|
||||||
initUiSettings();
|
initUiSettings();
|
||||||
initWorker();
|
initWorker();
|
||||||
|
initRCManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
156
Telegram/SourceFiles/ayu/utils/rc_manager.cpp
Normal file
156
Telegram/SourceFiles/ayu/utils/rc_manager.cpp
Normal file
|
@ -0,0 +1,156 @@
|
||||||
|
// This is the source code of AyuGram for Desktop.
|
||||||
|
//
|
||||||
|
// We do not and cannot prevent the use of our code,
|
||||||
|
// but be respectful and credit the original author.
|
||||||
|
//
|
||||||
|
// Copyright @Radolyn, 2024
|
||||||
|
#include "rc_manager.h"
|
||||||
|
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <qjsondocument.h>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "base/unixtime.h"
|
||||||
|
|
||||||
|
std::unordered_set<ID> default_developers = {
|
||||||
|
963080346, 1282540315, 1374434073, 168769611,
|
||||||
|
1773117711, 5330087923, 666154369, 139303278,
|
||||||
|
668557709, 1348136086, 6288255532, 7453676178,
|
||||||
|
// -------------------------------------------
|
||||||
|
778327202, 238292700, 1795176335, 6247153446,
|
||||||
|
1752394339, 7745305003, 1183312839, 497855299,
|
||||||
|
623054735
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unordered_set<ID> default_channels = {
|
||||||
|
1233768168, 1524581881, 1571726392, 1632728092,
|
||||||
|
1172503281, 1877362358, 1905581924, 1794457129,
|
||||||
|
1434550607, 1947958814, 1815864846, 2130395384,
|
||||||
|
1976430343, 1754537498, 1725670701,
|
||||||
|
};
|
||||||
|
|
||||||
|
void RCManager::start() {
|
||||||
|
DEBUG_LOG(("RCManager: starting"));
|
||||||
|
_manager = std::make_unique<QNetworkAccessManager>();
|
||||||
|
|
||||||
|
makeRequest();
|
||||||
|
|
||||||
|
_timer = new QTimer(this);
|
||||||
|
connect(_timer, &QTimer::timeout, this, &RCManager::makeRequest);
|
||||||
|
_timer->start(60 * 60 * 1000); // 1 hour
|
||||||
|
}
|
||||||
|
|
||||||
|
void RCManager::makeRequest() {
|
||||||
|
if (!_manager) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG(("RCManager: requesting map"));
|
||||||
|
|
||||||
|
clearSentRequest();
|
||||||
|
|
||||||
|
const auto request = QNetworkRequest(QUrl("https://update.ayugram.one/rc/current/desktop"));
|
||||||
|
_reply = _manager->get(request);
|
||||||
|
connect(_reply,
|
||||||
|
&QNetworkReply::finished,
|
||||||
|
[=]
|
||||||
|
{
|
||||||
|
gotResponse();
|
||||||
|
});
|
||||||
|
connect(_reply,
|
||||||
|
&QNetworkReply::errorOccurred,
|
||||||
|
[=](auto e)
|
||||||
|
{
|
||||||
|
gotFailure(e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void RCManager::gotResponse() {
|
||||||
|
if (!_reply) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cSetLastUpdateCheck(base::unixtime::now());
|
||||||
|
const auto response = _reply->readAll();
|
||||||
|
clearSentRequest();
|
||||||
|
|
||||||
|
if (!handleResponse(response)) {
|
||||||
|
LOG(("RCManager: Error bad map size: %1").arg(response.size()));
|
||||||
|
gotFailure(QNetworkReply::UnknownContentError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RCManager::handleResponse(const QByteArray &response) {
|
||||||
|
return applyResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RCManager::applyResponse(const QByteArray &response) {
|
||||||
|
auto error = QJsonParseError{0, QJsonParseError::NoError};
|
||||||
|
const auto document = QJsonDocument::fromJson(response, &error);
|
||||||
|
if (error.error != QJsonParseError::NoError) {
|
||||||
|
LOG(("RCManager: Failed to parse JSON, error: %1"
|
||||||
|
).arg(error.errorString()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!document.isObject()) {
|
||||||
|
LOG(("RCManager: not an object received in JSON"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto root = document.object();
|
||||||
|
|
||||||
|
const auto developers = root.value("developers").toArray();
|
||||||
|
const auto channels = root.value("channels").toArray();
|
||||||
|
const auto supporters = root.value("supporters").toArray();
|
||||||
|
|
||||||
|
_developers.clear();
|
||||||
|
_channels.clear();
|
||||||
|
_supporters.clear();
|
||||||
|
|
||||||
|
for (const auto &developer : developers) {
|
||||||
|
if (const auto id = developer.toVariant().toLongLong()) {
|
||||||
|
_developers.insert(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &channel : channels) {
|
||||||
|
if (const auto id = channel.toVariant().toLongLong()) {
|
||||||
|
_channels.insert(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &supporter : supporters) {
|
||||||
|
if (const auto id = supporter.toVariant().toLongLong()) {
|
||||||
|
_supporters.insert(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
|
|
||||||
|
LOG(("RCManager: Loaded %1 developers, %2 channels"
|
||||||
|
).arg(_developers.size()).arg(_channels.size()));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RCManager::gotFailure(QNetworkReply::NetworkError e) {
|
||||||
|
LOG(("RCManager: Error %1").arg(e));
|
||||||
|
if (const auto reply = base::take(_reply)) {
|
||||||
|
reply->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RCManager::clearSentRequest() {
|
||||||
|
const auto reply = base::take(_reply);
|
||||||
|
if (!reply) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
disconnect(reply, &QNetworkReply::finished, nullptr, nullptr);
|
||||||
|
disconnect(reply, &QNetworkReply::errorOccurred, nullptr, nullptr);
|
||||||
|
reply->abort();
|
||||||
|
reply->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
RCManager::~RCManager() {
|
||||||
|
clearSentRequest();
|
||||||
|
_manager = nullptr;
|
||||||
|
}
|
73
Telegram/SourceFiles/ayu/utils/rc_manager.h
Normal file
73
Telegram/SourceFiles/ayu/utils/rc_manager.h
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
// This is the source code of AyuGram for Desktop.
|
||||||
|
//
|
||||||
|
// We do not and cannot prevent the use of our code,
|
||||||
|
// but be respectful and credit the original author.
|
||||||
|
//
|
||||||
|
// Copyright @Radolyn, 2024
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QtNetwork/QNetworkReply>
|
||||||
|
|
||||||
|
#include "ayu/data/entities.h"
|
||||||
|
|
||||||
|
extern std::unordered_set<ID> default_developers;
|
||||||
|
extern std::unordered_set<ID> default_channels;
|
||||||
|
|
||||||
|
class RCManager final : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
static RCManager &getInstance() {
|
||||||
|
static RCManager instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
RCManager(const RCManager &) = delete;
|
||||||
|
RCManager &operator=(const RCManager &) = delete;
|
||||||
|
RCManager(RCManager &&) = delete;
|
||||||
|
RCManager &operator=(RCManager &&) = delete;
|
||||||
|
|
||||||
|
void start();
|
||||||
|
|
||||||
|
[[nodiscard]] const std::unordered_set<ID> &developers() const {
|
||||||
|
if (!initialized) {
|
||||||
|
return default_developers;
|
||||||
|
}
|
||||||
|
return _developers;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] const std::unordered_set<ID> &channels() const {
|
||||||
|
if (!initialized) {
|
||||||
|
return default_channels;
|
||||||
|
}
|
||||||
|
return _channels;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] const std::unordered_set<ID> &supporters() const {
|
||||||
|
return _supporters;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
RCManager() = default;
|
||||||
|
~RCManager();
|
||||||
|
|
||||||
|
void makeRequest();
|
||||||
|
|
||||||
|
void gotResponse();
|
||||||
|
void gotFailure(QNetworkReply::NetworkError e);
|
||||||
|
void clearSentRequest();
|
||||||
|
bool handleResponse(const QByteArray &response);
|
||||||
|
bool applyResponse(const QByteArray &response);
|
||||||
|
|
||||||
|
bool initialized = false;
|
||||||
|
|
||||||
|
std::unordered_set<ID> _developers = {};
|
||||||
|
std::unordered_set<ID> _channels = {};
|
||||||
|
std::unordered_set<ID> _supporters = {};
|
||||||
|
|
||||||
|
QTimer* _timer = nullptr;
|
||||||
|
|
||||||
|
std::unique_ptr<QNetworkAccessManager> _manager = nullptr;
|
||||||
|
QNetworkReply *_reply = nullptr;
|
||||||
|
|
||||||
|
};
|
|
@ -10,9 +10,9 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "api/api_text_entities.h"
|
|
||||||
|
|
||||||
#include "lang_auto.h"
|
#include "lang_auto.h"
|
||||||
|
#include "rc_manager.h"
|
||||||
#include "ayu/ayu_worker.h"
|
#include "ayu/ayu_worker.h"
|
||||||
#include "ayu/data/entities.h"
|
#include "ayu/data/entities.h"
|
||||||
#include "core/mime_type.h"
|
#include "core/mime_type.h"
|
||||||
|
@ -23,7 +23,6 @@
|
||||||
#include "data/data_peer_id.h"
|
#include "data/data_peer_id.h"
|
||||||
#include "data/data_photo.h"
|
#include "data/data_photo.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "inline_bots/inline_bot_result.h"
|
|
||||||
|
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
@ -38,54 +37,6 @@
|
||||||
#include "ayu/ayu_settings.h"
|
#include "ayu/ayu_settings.h"
|
||||||
#include "ayu/ayu_state.h"
|
#include "ayu/ayu_state.h"
|
||||||
|
|
||||||
// https://github.com/AyuGram/AyuGram4AX/blob/rewrite/TMessagesProj/src/main/java/com/radolyn/ayugram/AyuConstants.java
|
|
||||||
std::unordered_set<ID> ayugram_channels = {
|
|
||||||
1905581924, // @ayugramchat
|
|
||||||
1794457129, // @ayugram1338
|
|
||||||
1434550607, // @radolyn
|
|
||||||
1947958814, // @ayugramfun
|
|
||||||
1815864846, // @ayugramfcm
|
|
||||||
2130395384, // @ayugram_easter
|
|
||||||
};
|
|
||||||
|
|
||||||
std::unordered_set<ID> ayugram_devs = {
|
|
||||||
139303278, // @alexeyzavar
|
|
||||||
778327202, // @sharapagorg
|
|
||||||
238292700, // @MaxPlays
|
|
||||||
1795176335, // @radolyn_services
|
|
||||||
1752394339, // mouse
|
|
||||||
};
|
|
||||||
|
|
||||||
// https://github.com/AyuGram/AyuGram4AX/blob/rewrite/TMessagesProj/src/main/java/com/exteragram/messenger/ExteraConfig.java
|
|
||||||
std::unordered_set<ID> extera_channels = {
|
|
||||||
1233768168,
|
|
||||||
1524581881,
|
|
||||||
1571726392,
|
|
||||||
1632728092,
|
|
||||||
1172503281,
|
|
||||||
1877362358,
|
|
||||||
// custom
|
|
||||||
1812843581, // @moeGramX
|
|
||||||
1634905346, // @moex_log
|
|
||||||
1516526055, // @moexci
|
|
||||||
1622008530, // @moe_chat
|
|
||||||
};
|
|
||||||
|
|
||||||
std::unordered_set<ID> extera_devs = {
|
|
||||||
963080346,
|
|
||||||
1282540315,
|
|
||||||
1374434073,
|
|
||||||
388099852,
|
|
||||||
1972014627,
|
|
||||||
168769611,
|
|
||||||
480000401,
|
|
||||||
639891381,
|
|
||||||
1773117711,
|
|
||||||
5330087923,
|
|
||||||
666154369,
|
|
||||||
139303278
|
|
||||||
};
|
|
||||||
|
|
||||||
Main::Session *getSession(ID userId) {
|
Main::Session *getSession(ID userId) {
|
||||||
for (const auto &[index, account] : Core::App().domain().accounts()) {
|
for (const auto &[index, account] : Core::App().domain().accounts()) {
|
||||||
if (const auto session = account->maybeSession()) {
|
if (const auto session = account->maybeSession()) {
|
||||||
|
@ -125,12 +76,13 @@ ID getBareID(not_null<PeerData*> peer) {
|
||||||
return peer->id.value & PeerId::kChatTypeMask;
|
return peer->id.value & PeerId::kChatTypeMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isAyuGramRelated(ID peerId) {
|
bool isExteraPeer(ID peerId) {
|
||||||
return ayugram_devs.contains(peerId) || ayugram_channels.contains(peerId);
|
return RCManager::getInstance().developers().contains(peerId) || RCManager::getInstance().channels().
|
||||||
|
contains(peerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isExteraRelated(ID peerId) {
|
bool isSupporterPeer(ID peerId) {
|
||||||
return extera_devs.contains(peerId) || extera_channels.contains(peerId);
|
return RCManager::getInstance().supporters().contains(peerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isMessageHidden(const not_null<HistoryItem*> item) {
|
bool isMessageHidden(const not_null<HistoryItem*> item) {
|
||||||
|
|
|
@ -20,8 +20,8 @@ ID getDialogIdFromPeer(not_null<PeerData*> peer);
|
||||||
|
|
||||||
ID getBareID(not_null<PeerData*> peer);
|
ID getBareID(not_null<PeerData*> peer);
|
||||||
|
|
||||||
bool isAyuGramRelated(ID peerId);
|
bool isExteraPeer(ID peerId);
|
||||||
bool isExteraRelated(ID peerId);
|
bool isSupporterPeer(ID peerId);
|
||||||
|
|
||||||
bool isMessageHidden(not_null<HistoryItem*> item);
|
bool isMessageHidden(not_null<HistoryItem*> item);
|
||||||
|
|
||||||
|
|
|
@ -418,9 +418,9 @@ Cover::Cover(
|
||||||
refreshNameGeometry(width());
|
refreshNameGeometry(width());
|
||||||
}, _name->lifetime());
|
}, _name->lifetime());
|
||||||
|
|
||||||
if (isExteraRelated(getBareID(_peer)) || isAyuGramRelated(getBareID(_peer))) {
|
if (isExteraPeer(getBareID(_peer))) {
|
||||||
_devBadge->setContent(Info::Profile::Badge::Content{BadgeType::Extera});
|
_devBadge->setContent(Info::Profile::Badge::Content{BadgeType::Extera});
|
||||||
} else if (false) {
|
} else if (isSupporterPeer(getBareID(_peer))) {
|
||||||
_devBadge->setContent(Info::Profile::Badge::Content{BadgeType::ExteraSupporter});
|
_devBadge->setContent(Info::Profile::Badge::Content{BadgeType::ExteraSupporter});
|
||||||
} else {
|
} else {
|
||||||
_devBadge->setContent(Info::Profile::Badge::Content{BadgeType::None});
|
_devBadge->setContent(Info::Profile::Badge::Content{BadgeType::None});
|
||||||
|
|
Loading…
Add table
Reference in a new issue