mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Show business section settings only when loaded.
This commit is contained in:
parent
2c03d90fc8
commit
d729e625e6
5 changed files with 79 additions and 12 deletions
|
@ -43,10 +43,21 @@ void Chatbots::preload() {
|
||||||
.recipients = FromMTP(_owner, bot.vrecipients()),
|
.recipients = FromMTP(_owner, bot.vrecipients()),
|
||||||
.repliesAllowed = bot.is_can_reply(),
|
.repliesAllowed = bot.is_can_reply(),
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
_settings.force_assign(ChatbotsSettings());
|
||||||
}
|
}
|
||||||
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
_requestId = 0;
|
||||||
|
LOG(("API Error: Could not get connected bots %1 (%2)"
|
||||||
|
).arg(error.code()
|
||||||
|
).arg(error.type()));
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Chatbots::loaded() const {
|
||||||
|
return _loaded;
|
||||||
|
}
|
||||||
|
|
||||||
const ChatbotsSettings &Chatbots::current() const {
|
const ChatbotsSettings &Chatbots::current() const {
|
||||||
return _settings.current();
|
return _settings.current();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
~Chatbots();
|
~Chatbots();
|
||||||
|
|
||||||
void preload();
|
void preload();
|
||||||
|
[[nodiscard]] bool loaded() const;
|
||||||
[[nodiscard]] const ChatbotsSettings ¤t() const;
|
[[nodiscard]] const ChatbotsSettings ¤t() const;
|
||||||
[[nodiscard]] rpl::producer<ChatbotsSettings> changes() const;
|
[[nodiscard]] rpl::producer<ChatbotsSettings> changes() const;
|
||||||
[[nodiscard]] rpl::producer<ChatbotsSettings> value() const;
|
[[nodiscard]] rpl::producer<ChatbotsSettings> value() const;
|
||||||
|
|
|
@ -220,6 +220,10 @@ rpl::producer<Timezones> BusinessInfo::timezonesValue() const {
|
||||||
return _timezones.value();
|
return _timezones.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BusinessInfo::timezonesLoaded() const {
|
||||||
|
return !_timezones.current().list.empty();
|
||||||
|
}
|
||||||
|
|
||||||
QString FindClosestTimezoneId(const std::vector<Timezone> &list) {
|
QString FindClosestTimezoneId(const std::vector<Timezone> &list) {
|
||||||
const auto local = QDateTime::currentDateTime();
|
const auto local = QDateTime::currentDateTime();
|
||||||
const auto utc = QDateTime(local.date(), local.time(), Qt::UTC);
|
const auto utc = QDateTime(local.date(), local.time(), Qt::UTC);
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
[[nodiscard]] rpl::producer<> greetingSettingsChanged() const;
|
[[nodiscard]] rpl::producer<> greetingSettingsChanged() const;
|
||||||
|
|
||||||
void preloadTimezones();
|
void preloadTimezones();
|
||||||
|
[[nodiscard]] bool timezonesLoaded() const;
|
||||||
[[nodiscard]] rpl::producer<Timezones> timezonesValue() const;
|
[[nodiscard]] rpl::producer<Timezones> timezonesValue() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -12,8 +12,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/business/data_business_info.h"
|
#include "data/business/data_business_info.h"
|
||||||
#include "data/business/data_business_chatbots.h"
|
#include "data/business/data_business_chatbots.h"
|
||||||
#include "data/business/data_shortcut_messages.h"
|
#include "data/business/data_shortcut_messages.h"
|
||||||
|
#include "data/data_changes.h"
|
||||||
#include "data/data_peer_values.h" // AmPremiumValue.
|
#include "data/data_peer_values.h" // AmPremiumValue.
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
#include "data/data_user.h"
|
||||||
#include "info/info_wrap_widget.h" // Info::Wrap.
|
#include "info/info_wrap_widget.h" // Info::Wrap.
|
||||||
#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData.
|
#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData.
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
@ -317,6 +319,8 @@ private:
|
||||||
rpl::event_stream<> _showFinished;
|
rpl::event_stream<> _showFinished;
|
||||||
rpl::variable<QString> _buttonText;
|
rpl::variable<QString> _buttonText;
|
||||||
|
|
||||||
|
PremiumFeature _waitingToShow = PremiumFeature::Business;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Business::Business(
|
Business::Business(
|
||||||
|
@ -355,20 +359,14 @@ void Business::setStepDataReference(std::any &data) {
|
||||||
void Business::setupContent() {
|
void Business::setupContent() {
|
||||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||||
|
|
||||||
_controller->session().data().chatbots().preload();
|
const auto owner = &_controller->session().data();
|
||||||
_controller->session().data().businessInfo().preload();
|
owner->chatbots().preload();
|
||||||
_controller->session().data().shortcutMessages().preloadShortcuts();
|
owner->businessInfo().preload();
|
||||||
|
owner->shortcutMessages().preloadShortcuts();
|
||||||
|
|
||||||
Ui::AddSkip(content, st::settingsFromFileTop);
|
Ui::AddSkip(content, st::settingsFromFileTop);
|
||||||
|
|
||||||
AddBusinessSummary(content, _controller, [=](PremiumFeature feature) {
|
const auto showFeature = [=](PremiumFeature feature) {
|
||||||
if (!_controller->session().premium()) {
|
|
||||||
_setPaused(true);
|
|
||||||
const auto hidden = crl::guard(this, [=] { _setPaused(false); });
|
|
||||||
|
|
||||||
ShowPremiumPreviewToBuy(_controller, feature, hidden);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
showOther([&] {
|
showOther([&] {
|
||||||
switch (feature) {
|
switch (feature) {
|
||||||
case PremiumFeature::AwayMessage: return AwayMessageId();
|
case PremiumFeature::AwayMessage: return AwayMessageId();
|
||||||
|
@ -378,8 +376,60 @@ void Business::setupContent() {
|
||||||
case PremiumFeature::QuickReplies: return QuickRepliesId();
|
case PremiumFeature::QuickReplies: return QuickRepliesId();
|
||||||
case PremiumFeature::BusinessBots: return ChatbotsId();
|
case PremiumFeature::BusinessBots: return ChatbotsId();
|
||||||
}
|
}
|
||||||
Unexpected("Feature in Business::setupContent.");
|
Unexpected("Feature in showFeature.");
|
||||||
}());
|
}());
|
||||||
|
};
|
||||||
|
const auto isReady = [=](PremiumFeature feature) {
|
||||||
|
switch (feature) {
|
||||||
|
case PremiumFeature::AwayMessage:
|
||||||
|
return owner->businessInfo().awaySettingsLoaded()
|
||||||
|
&& owner->shortcutMessages().shortcutsLoaded();
|
||||||
|
case PremiumFeature::BusinessHours:
|
||||||
|
return owner->session().user()->isFullLoaded()
|
||||||
|
&& owner->businessInfo().timezonesLoaded();
|
||||||
|
case PremiumFeature::BusinessLocation:
|
||||||
|
return owner->session().user()->isFullLoaded();
|
||||||
|
case PremiumFeature::GreetingMessage:
|
||||||
|
return owner->businessInfo().greetingSettingsLoaded()
|
||||||
|
&& owner->shortcutMessages().shortcutsLoaded();
|
||||||
|
case PremiumFeature::QuickReplies:
|
||||||
|
return owner->shortcutMessages().shortcutsLoaded();
|
||||||
|
case PremiumFeature::BusinessBots:
|
||||||
|
return owner->chatbots().loaded();
|
||||||
|
}
|
||||||
|
Unexpected("Feature in isReady.");
|
||||||
|
};
|
||||||
|
const auto check = [=] {
|
||||||
|
if (_waitingToShow != PremiumFeature::Business
|
||||||
|
&& isReady(_waitingToShow)) {
|
||||||
|
showFeature(
|
||||||
|
std::exchange(_waitingToShow, PremiumFeature::Business));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
rpl::merge(
|
||||||
|
owner->businessInfo().awaySettingsChanged(),
|
||||||
|
owner->businessInfo().greetingSettingsChanged(),
|
||||||
|
owner->businessInfo().timezonesValue() | rpl::to_empty,
|
||||||
|
owner->shortcutMessages().shortcutsChanged(),
|
||||||
|
owner->chatbots().changes() | rpl::to_empty,
|
||||||
|
owner->session().changes().peerUpdates(
|
||||||
|
owner->session().user(),
|
||||||
|
Data::PeerUpdate::Flag::FullInfo) | rpl::to_empty
|
||||||
|
) | rpl::start_with_next(check, content->lifetime());
|
||||||
|
|
||||||
|
AddBusinessSummary(content, _controller, [=](PremiumFeature feature) {
|
||||||
|
if (!_controller->session().premium()) {
|
||||||
|
_setPaused(true);
|
||||||
|
const auto hidden = crl::guard(this, [=] { _setPaused(false); });
|
||||||
|
|
||||||
|
ShowPremiumPreviewToBuy(_controller, feature, hidden);
|
||||||
|
return;
|
||||||
|
} else if (!isReady(feature)) {
|
||||||
|
_waitingToShow = feature;
|
||||||
|
} else {
|
||||||
|
showFeature(feature);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Ui::ResizeFitChild(this, content);
|
Ui::ResizeFitChild(this, content);
|
||||||
|
|
Loading…
Add table
Reference in a new issue