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