mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Respect appconfig starref restrictions.
This commit is contained in:
parent
89058c63c8
commit
a97880132a
10 changed files with 56 additions and 12 deletions
|
@ -1242,7 +1242,9 @@ void Controller::fillManageSection() {
|
|||
&& (channel->isBroadcast() || channel->isGigagroup());
|
||||
const auto hasRecentActions = isChannel
|
||||
&& (channel->hasAdminRights() || channel->amCreator());
|
||||
const auto hasStarRef = isChannel && channel->canPostMessages();
|
||||
const auto hasStarRef = Info::BotStarRef::Join::Allowed(_peer)
|
||||
&& isChannel
|
||||
&& channel->canPostMessages();
|
||||
const auto canEditStickers = isChannel && channel->canEditStickers();
|
||||
const auto canDeleteChannel = isChannel && channel->canDelete();
|
||||
const auto canEditColorIndex = isChannel && channel->canEditEmoji();
|
||||
|
@ -1730,6 +1732,10 @@ void Controller::fillBotCreditsButton() {
|
|||
void Controller::fillBotAffiliateProgram() {
|
||||
Expects(_isBot);
|
||||
|
||||
if (!Info::BotStarRef::Setup::Allowed(_peer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto user = _peer->asUser();
|
||||
auto label = user->session().changes().peerFlagsValue(
|
||||
user,
|
||||
|
|
|
@ -253,7 +253,7 @@ void InnerWidget::fill() {
|
|||
return v ? ToUsd(v, multiplier, kMinorLength) : QString();
|
||||
}));
|
||||
}
|
||||
{
|
||||
if (BotStarRef::Join::Allowed(peer())) {
|
||||
const auto button = BotStarRef::AddViewListButton(
|
||||
container,
|
||||
tr::lng_credits_summary_earn_title(),
|
||||
|
|
|
@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/weak_ptr.h"
|
||||
#include "boxes/peer_list_box.h"
|
||||
#include "core/click_handler_types.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
#include "info/bot/starref/info_bot_starref_common.h"
|
||||
|
@ -20,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "info/info_controller.h"
|
||||
#include "info/info_memento.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_app_config.h"
|
||||
#include "main/main_session.h"
|
||||
#include "settings/settings_common.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
|
@ -680,6 +682,18 @@ std::unique_ptr<Ui::Premium::TopBarAbstract> Widget::setupTop() {
|
|||
return result;
|
||||
}
|
||||
|
||||
bool Allowed(not_null<PeerData*> peer) {
|
||||
if (!peer->session().appConfig().starrefJoinAllowed()) {
|
||||
return false;
|
||||
} else if (const auto user = peer->asUser()) {
|
||||
return user->isSelf()
|
||||
|| (user->isBot() && user->botInfo->canEditInformation);
|
||||
} else if (const auto channel = peer->asChannel()) {
|
||||
return channel->isBroadcast() && channel->canPostMessages();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<Info::Memento> Make(not_null<PeerData*> peer) {
|
||||
return std::make_shared<Info::Memento>(
|
||||
std::vector<std::shared_ptr<ContentMemento>>(
|
||||
|
|
|
@ -79,6 +79,7 @@ private:
|
|||
|
||||
};
|
||||
|
||||
[[nodiscard]] bool Allowed(not_null<PeerData*> peer);
|
||||
[[nodiscard]] std::shared_ptr<Info::Memento> Make(not_null<PeerData*> peer);
|
||||
|
||||
[[nodiscard]] object_ptr<Ui::BoxContent> ProgramsListBox(
|
||||
|
|
|
@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "info/info_controller.h"
|
||||
#include "info/info_memento.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_app_config.h"
|
||||
#include "main/main_session.h"
|
||||
#include "settings/settings_common.h"
|
||||
#include "ui/effects/premium_top_bar.h"
|
||||
|
@ -903,6 +904,12 @@ std::unique_ptr<Ui::RpWidget> Widget::setupBottom() {
|
|||
return result;
|
||||
}
|
||||
|
||||
bool Allowed(not_null<PeerData*> peer) {
|
||||
return peer->isUser()
|
||||
&& peer->asUser()->isBot()
|
||||
&& peer->session().appConfig().starrefSetupAllowed();
|
||||
}
|
||||
|
||||
std::shared_ptr<Info::Memento> Make(not_null<PeerData*> peer) {
|
||||
return std::make_shared<Info::Memento>(
|
||||
std::vector<std::shared_ptr<ContentMemento>>(
|
||||
|
|
|
@ -80,6 +80,7 @@ private:
|
|||
|
||||
};
|
||||
|
||||
[[nodiscard]] bool Allowed(not_null<PeerData*> peer);
|
||||
[[nodiscard]] std::shared_ptr<Info::Memento> Make(not_null<PeerData*> peer);
|
||||
|
||||
} // namespace Info::BotStarRef::Setup
|
||||
|
|
|
@ -963,15 +963,17 @@ void InnerWidget::fill() {
|
|||
) | rpl::map(creditsToUsdMap));
|
||||
}
|
||||
|
||||
const auto button = Info::BotStarRef::AddViewListButton(
|
||||
container,
|
||||
tr::lng_credits_summary_earn_title(),
|
||||
tr::lng_credits_summary_earn_about());
|
||||
button->setClickedCallback([=] {
|
||||
_controller->showSection(Info::BotStarRef::Join::Make(_peer));
|
||||
});
|
||||
Ui::AddSkip(container);
|
||||
Ui::AddDivider(container);
|
||||
if (Info::BotStarRef::Join::Allowed(_peer)) {
|
||||
const auto button = Info::BotStarRef::AddViewListButton(
|
||||
container,
|
||||
tr::lng_credits_summary_earn_title(),
|
||||
tr::lng_credits_summary_earn_about());
|
||||
button->setClickedCallback([=] {
|
||||
_controller->showSection(Info::BotStarRef::Join::Make(_peer));
|
||||
});
|
||||
Ui::AddSkip(container);
|
||||
Ui::AddDivider(container);
|
||||
}
|
||||
Ui::AddSkip(container);
|
||||
|
||||
const auto sectionIndex = container->lifetime().make_state<int>(0);
|
||||
|
|
|
@ -57,6 +57,14 @@ const std::vector<QString> &AppConfig::startRefPrefixes() {
|
|||
return _startRefPrefixes;
|
||||
}
|
||||
|
||||
bool AppConfig::starrefSetupAllowed() const {
|
||||
return get<bool>(u"starref_program_allowed"_q, false);
|
||||
}
|
||||
|
||||
bool AppConfig::starrefJoinAllowed() const {
|
||||
return get<bool>(u"starref_connect_allowed"_q, false);
|
||||
}
|
||||
|
||||
void AppConfig::refresh(bool force) {
|
||||
if (_requestId || !_api) {
|
||||
if (force) {
|
||||
|
|
|
@ -67,6 +67,8 @@ public:
|
|||
[[nodiscard]] int stargiftConvertPeriodMax() const;
|
||||
|
||||
[[nodiscard]] const std::vector<QString> &startRefPrefixes();
|
||||
[[nodiscard]] bool starrefSetupAllowed() const;
|
||||
[[nodiscard]] bool starrefJoinAllowed() const;
|
||||
|
||||
void refresh(bool force = false);
|
||||
|
||||
|
|
|
@ -210,13 +210,16 @@ void Credits::setupSubscriptions(not_null<Ui::VerticalLayout*> container) {
|
|||
}
|
||||
|
||||
void Credits::setupStarRefPromo(not_null<Ui::VerticalLayout*> container) {
|
||||
const auto self = _controller->session().user();
|
||||
if (!Info::BotStarRef::Join::Allowed(self)) {
|
||||
return;
|
||||
}
|
||||
Ui::AddSkip(container);
|
||||
const auto button = Info::BotStarRef::AddViewListButton(
|
||||
container,
|
||||
tr::lng_credits_summary_earn_title(),
|
||||
tr::lng_credits_summary_earn_about());
|
||||
button->setClickedCallback([=] {
|
||||
const auto self = _controller->session().user();
|
||||
_controller->showSection(Info::BotStarRef::Join::Make(self));
|
||||
});
|
||||
Ui::AddSkip(container);
|
||||
|
|
Loading…
Add table
Reference in a new issue