mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Check appconfig start ref prefixes.
This commit is contained in:
parent
747e417809
commit
89058c63c8
5 changed files with 33 additions and 19 deletions
|
@ -63,6 +63,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "settings/settings_premium.h"
|
||||
#include "mainwidget.h"
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_app_config.h"
|
||||
#include "main/main_domain.h"
|
||||
#include "main/main_session.h"
|
||||
#include "main/main_session_settings.h"
|
||||
|
@ -555,14 +556,20 @@ bool ResolveUsernameOrPhone(
|
|||
auto resolveType = params.contains(u"profile"_q)
|
||||
? ResolveType::Profile
|
||||
: ResolveType::Default;
|
||||
auto starref = params.value(u"ref"_q);
|
||||
auto startToken = params.value(u"start"_q);
|
||||
const auto kTgRefPrefix = u"_tgref_"_q;
|
||||
if (startToken.startsWith(kTgRefPrefix)) {
|
||||
startToken = startToken.mid(kTgRefPrefix.size());
|
||||
resolveType = ResolveType::StarRef;
|
||||
} else if (!startToken.isEmpty()) {
|
||||
auto referral = params.value(u"ref"_q);
|
||||
if (!startToken.isEmpty()) {
|
||||
resolveType = ResolveType::BotStart;
|
||||
if (referral.isEmpty()) {
|
||||
const auto appConfig = &controller->session().appConfig();
|
||||
const auto &prefixes = appConfig->startRefPrefixes();
|
||||
for (const auto &prefix : prefixes) {
|
||||
if (startToken.startsWith(prefix)) {
|
||||
referral = startToken.mid(prefix.size());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (params.contains(u"startgroup"_q)) {
|
||||
resolveType = ResolveType::AddToGroup;
|
||||
startToken = params.value(u"startgroup"_q);
|
||||
|
@ -570,8 +577,6 @@ bool ResolveUsernameOrPhone(
|
|||
resolveType = ResolveType::AddToChannel;
|
||||
} else if (params.contains(u"boost"_q)) {
|
||||
resolveType = ResolveType::Boost;
|
||||
} else if (!starref.isEmpty()) {
|
||||
resolveType = ResolveType::StarRef;
|
||||
}
|
||||
auto post = ShowAtUnreadMsgId;
|
||||
auto adminRights = ChatAdminRights();
|
||||
|
@ -620,6 +625,7 @@ bool ResolveUsernameOrPhone(
|
|||
}
|
||||
: Window::RepliesByLinkInfo{ v::null },
|
||||
.resolveType = resolveType,
|
||||
.referral = referral,
|
||||
.startToken = startToken,
|
||||
.startAdminRights = adminRights,
|
||||
.startAutoSubmit = myContext.botStartAutoSubmit,
|
||||
|
|
|
@ -48,6 +48,15 @@ int AppConfig::stargiftConvertPeriodMax() const {
|
|||
_account->mtp().isTestMode() ? 300 : (90 * 86400));
|
||||
}
|
||||
|
||||
const std::vector<QString> &AppConfig::startRefPrefixes() {
|
||||
if (_startRefPrefixes.empty()) {
|
||||
_startRefPrefixes = get<std::vector<QString>>(
|
||||
u"starref_start_param_prefixes"_q,
|
||||
std::vector<QString>());
|
||||
}
|
||||
return _startRefPrefixes;
|
||||
}
|
||||
|
||||
void AppConfig::refresh(bool force) {
|
||||
if (_requestId || !_api) {
|
||||
if (force) {
|
||||
|
|
|
@ -66,6 +66,8 @@ public:
|
|||
[[nodiscard]] int quoteLengthMax() const;
|
||||
[[nodiscard]] int stargiftConvertPeriodMax() const;
|
||||
|
||||
[[nodiscard]] const std::vector<QString> &startRefPrefixes();
|
||||
|
||||
void refresh(bool force = false);
|
||||
|
||||
private:
|
||||
|
@ -109,6 +111,8 @@ private:
|
|||
std::vector<QString> _ignoreRestrictionReasons;
|
||||
rpl::event_stream<std::vector<QString>> _ignoreRestrictionChanges;
|
||||
|
||||
std::vector<QString> _startRefPrefixes;
|
||||
|
||||
rpl::lifetime _lifetime;
|
||||
|
||||
};
|
||||
|
|
|
@ -381,9 +381,6 @@ void SessionNavigation::showPeerByLink(const PeerByLinkInfo &info) {
|
|||
showPeerByLinkResolved(peer, info);
|
||||
});
|
||||
} else if (const auto name = std::get_if<QString>(&info.usernameOrId)) {
|
||||
const auto starref = (info.resolveType == ResolveType::StarRef)
|
||||
? info.startToken
|
||||
: QString();
|
||||
resolveUsername(*name, [=](not_null<PeerData*> peer) {
|
||||
if (info.startAutoSubmit) {
|
||||
peer->session().api().blockedPeers().unblock(
|
||||
|
@ -395,7 +392,7 @@ void SessionNavigation::showPeerByLink(const PeerByLinkInfo &info) {
|
|||
} else {
|
||||
showPeerByLinkResolved(peer, info);
|
||||
}
|
||||
}, starref);
|
||||
}, info.referral);
|
||||
} else if (const auto id = std::get_if<ChannelId>(&info.usernameOrId)) {
|
||||
resolveChannelById(*id, [=](not_null<ChannelData*> channel) {
|
||||
showPeerByLinkResolved(channel, info);
|
||||
|
@ -458,8 +455,8 @@ void SessionNavigation::resolveChatLink(
|
|||
void SessionNavigation::resolveUsername(
|
||||
const QString &username,
|
||||
Fn<void(not_null<PeerData*>)> done,
|
||||
const QString &starref) {
|
||||
if (starref.isEmpty()) {
|
||||
const QString &referral) {
|
||||
if (referral.isEmpty()) {
|
||||
if (const auto peer = _session->data().peerByUsername(username)) {
|
||||
done(peer);
|
||||
return;
|
||||
|
@ -468,9 +465,9 @@ void SessionNavigation::resolveUsername(
|
|||
_api.request(base::take(_resolveRequestId)).cancel();
|
||||
using Flag = MTPcontacts_ResolveUsername::Flag;
|
||||
_resolveRequestId = _api.request(MTPcontacts_ResolveUsername(
|
||||
MTP_flags(starref.isEmpty() ? Flag() : Flag::f_referer),
|
||||
MTP_flags(referral.isEmpty() ? Flag() : Flag::f_referer),
|
||||
MTP_string(username),
|
||||
MTP_string(starref)
|
||||
MTP_string(referral)
|
||||
)).done([=](const MTPcontacts_ResolvedPeer &result) {
|
||||
resolveDone(result, done);
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
|
@ -685,8 +682,6 @@ void SessionNavigation::showPeerByLinkResolved(
|
|||
}
|
||||
} else if (resolveType == ResolveType::Boost && peer->isChannel()) {
|
||||
resolveBoostState(peer->asChannel());
|
||||
} else if (resolveType == ResolveType::StarRef) {
|
||||
showPeerHistory(peer, params);
|
||||
} else {
|
||||
// Show specific posts only in channels / supergroups.
|
||||
const auto msgId = peer->isChannel()
|
||||
|
|
|
@ -24,7 +24,6 @@ enum class ResolveType {
|
|||
Mention,
|
||||
Boost,
|
||||
Profile,
|
||||
StarRef,
|
||||
};
|
||||
|
||||
struct CommentId {
|
||||
|
@ -44,6 +43,7 @@ struct PeerByLinkInfo {
|
|||
QString text;
|
||||
RepliesByLinkInfo repliesInfo;
|
||||
ResolveType resolveType = ResolveType::Default;
|
||||
QString referral;
|
||||
QString startToken;
|
||||
ChatAdminRights startAdminRights;
|
||||
bool startAutoSubmit = false;
|
||||
|
|
Loading…
Add table
Reference in a new issue