From be8a3c8a61cc9ed93207e218c2bfbbbf51346d24 Mon Sep 17 00:00:00 2001 From: AlexeyZavar Date: Thu, 19 Feb 2026 17:08:30 +0300 Subject: [PATCH] fix: fetch supporters from mirror if failed --- Telegram/SourceFiles/ayu/utils/rc_manager.cpp | 76 ++++++++++++++----- Telegram/SourceFiles/ayu/utils/rc_manager.h | 6 +- 2 files changed, 61 insertions(+), 21 deletions(-) diff --git a/Telegram/SourceFiles/ayu/utils/rc_manager.cpp b/Telegram/SourceFiles/ayu/utils/rc_manager.cpp index 764551e9b6..86e04767e8 100644 --- a/Telegram/SourceFiles/ayu/utils/rc_manager.cpp +++ b/Telegram/SourceFiles/ayu/utils/rc_manager.cpp @@ -10,25 +10,23 @@ #include #include -#include "base/unixtime.h" +namespace { + +constexpr auto kPrimaryUrl = "https://update.ayugram.one/rc/current/desktop2"; +constexpr auto kExteraUrl = "https://api.exteragram.app/api/v1/profiles/compact"; + +} std::unordered_set default_developers = { - 963080346, 1282540315, 1374434073, 168769611, - 1773117711, 5330087923, 139303278, 1752394339, - 668557709, 1348136086, 6288255532, 7453676178, - 880708503, 2135966128, 7818249287, - // ------------------------------------------- - 778327202, 238292700, 1795176335, 6247153446, - 1183312839, 497855299 + 139303278, 168769611, 668557709, 880708503, 963080346, 1156270028, 1282540315, 1348136086, 1374434073, 1752394339, + 1773117711, 2135966128, 5079320635, 5118627360, 5184725450, 5330087923, 5800413909, 6007644928, 7380551229, + 7738913005, 7818249287, 8083933640, 8512951856 }; std::unordered_set default_channels = { - 1233768168, 1524581881, 1571726392, 1632728092, - 1172503281, 1877362358, 1905581924, 1794457129, - 1434550607, 1947958814, 1815864846, 2130395384, - 1976430343, 1754537498, 1725670701, 2401498637, - 2685666919, 2562664432, 2564770112, 2331068091, - 1559501352, 2641258043 + 1172503281, 1434550607, 1524581881, 1559501352, 1571726392, 1632728092, 1725670701, 1754537498, 1794457129, + 1815864846, 1877362358, 1905581924, 1947958814, 1976430343, 2130395384, 2331068091, 2401498637, 2562664432, + 2564770112, 2685666919, 3116497667, 3212977677, 3572293253 }; void RCManager::start() { @@ -43,15 +41,21 @@ void RCManager::start() { } void RCManager::makeRequest() { + _retryAttempted = false; + sendRequest(); +} + +void RCManager::sendRequest() { if (!_manager) { return; } - LOG(("RCManager: requesting map")); + const auto url = QString::fromLatin1(_useExteraFallback ? kExteraUrl : kPrimaryUrl); + LOG(("RCManager: requesting map").arg(url)); clearSentRequest(); - auto request = QNetworkRequest(QUrl("https://update.ayugram.one/rc/current/desktop2")); + auto request = QNetworkRequest(QUrl(url)); request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); _reply = _manager->get(request); connect(_reply, @@ -68,6 +72,17 @@ void RCManager::makeRequest() { }); } +bool RCManager::tryRetryWithExteraFallback() { + if (_retryAttempted || _useExteraFallback) { + return false; + } + LOG(("RCManager: switching to extera fallback endpoint")); + _useExteraFallback = true; + _retryAttempted = true; + sendRequest(); + return true; +} + void RCManager::gotResponse() { if (!_reply) { return; @@ -167,10 +182,26 @@ bool RCManager::applyResponse(const QByteArray &response) { _customBadges[id] = customBadge; } - _donateUsername = root.value("donateUsername").toString(); - _donateAmountUsd = root.value("donateAmountUsd").toString(); - _donateAmountTon = root.value("donateAmountTon").toString(); - _donateAmountRub = root.value("donateAmountRub").toString(); + if (const auto donateUsername = root.value("donateUsername"); donateUsername.isString()) { + if (const auto value = donateUsername.toString(); !value.isEmpty()) { + _donateUsername = value; + } + } + if (const auto donateAmountUsd = root.value("donateAmountUsd"); donateAmountUsd.isString()) { + if (const auto value = donateAmountUsd.toString(); !value.isEmpty()) { + _donateAmountUsd = value; + } + } + if (const auto donateAmountTon = root.value("donateAmountTon"); donateAmountTon.isString()) { + if (const auto value = donateAmountTon.toString(); !value.isEmpty()) { + _donateAmountTon = value; + } + } + if (const auto donateAmountRub = root.value("donateAmountRub"); donateAmountRub.isString()) { + if (const auto value = donateAmountRub.toString(); !value.isEmpty()) { + _donateAmountRub = value; + } + } initialized = true; @@ -182,6 +213,11 @@ bool RCManager::applyResponse(const QByteArray &response) { void RCManager::gotFailure(QNetworkReply::NetworkError e) { LOG(("RCManager: Error %1").arg(e)); + if (tryRetryWithExteraFallback()) { + LOG(("RCManager: retrying request with extera fallback endpoint")); + return; + } + LOG(("RCManager: no retry left for failed request")); if (const auto reply = base::take(_reply)) { reply->deleteLater(); } diff --git a/Telegram/SourceFiles/ayu/utils/rc_manager.h b/Telegram/SourceFiles/ayu/utils/rc_manager.h index c53466336b..13864b1aee 100644 --- a/Telegram/SourceFiles/ayu/utils/rc_manager.h +++ b/Telegram/SourceFiles/ayu/utils/rc_manager.h @@ -82,6 +82,8 @@ private: ~RCManager(); void makeRequest(); + void sendRequest(); + bool tryRetryWithExteraFallback(); void gotResponse(); void gotFailure(QNetworkReply::NetworkError e); @@ -99,12 +101,14 @@ private: QString _donateUsername = QString("@ayugramOwner"); QString _donateAmountUsd = QString("4.50"); - QString _donateAmountTon = QString("3.00"); + QString _donateAmountTon = QString("3.25"); QString _donateAmountRub = QString("360"); QTimer* _timer = nullptr; std::unique_ptr _manager = nullptr; QNetworkReply *_reply = nullptr; + bool _useExteraFallback = false; + bool _retryAttempted = false; };