mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-09-05 00:46:08 +00:00
Implement preview and save of chatbots.
This commit is contained in:
@@ -32,102 +32,6 @@ constexpr auto kSetOnlineAfterActivity = TimeId(30);
|
||||
|
||||
using UpdateFlag = Data::PeerUpdate::Flag;
|
||||
|
||||
[[nodiscard]] Data::BusinessDetails FromMTP(
|
||||
const tl::conditional<MTPBusinessWorkHours> &hours,
|
||||
const tl::conditional<MTPBusinessLocation> &location) {
|
||||
auto result = Data::BusinessDetails();
|
||||
if (hours) {
|
||||
const auto &data = hours->data();
|
||||
result.hours.timezoneId = qs(data.vtimezone_id());
|
||||
result.hours.intervals.list = ranges::views::all(
|
||||
data.vweekly_open().v
|
||||
) | ranges::views::transform([](const MTPBusinessWeeklyOpen &open) {
|
||||
const auto &data = open.data();
|
||||
return Data::WorkingInterval{
|
||||
data.vstart_minute().v * 60,
|
||||
data.vend_minute().v * 60,
|
||||
};
|
||||
}) | ranges::to_vector;
|
||||
}
|
||||
if (location) {
|
||||
const auto &data = location->data();
|
||||
result.location.address = qs(data.vaddress());
|
||||
if (const auto point = data.vgeo_point()) {
|
||||
point->match([&](const MTPDgeoPoint &data) {
|
||||
result.location.point = Data::LocationPoint(data);
|
||||
}, [&](const MTPDgeoPointEmpty &) {
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Data::BusinessRecipients FromMTP(
|
||||
not_null<Data::Session*> owner,
|
||||
const MTPBusinessRecipients &recipients) {
|
||||
using Type = Data::BusinessChatType;
|
||||
|
||||
const auto &data = recipients.data();
|
||||
auto result = Data::BusinessRecipients{
|
||||
.allButExcluded = data.is_exclude_selected(),
|
||||
};
|
||||
auto &chats = result.allButExcluded
|
||||
? result.excluded
|
||||
: result.included;
|
||||
chats.types = Type()
|
||||
| (data.is_new_chats() ? Type::NewChats : Type())
|
||||
| (data.is_existing_chats() ? Type::ExistingChats : Type())
|
||||
| (data.is_contacts() ? Type::Contacts : Type())
|
||||
| (data.is_non_contacts() ? Type::NonContacts : Type());
|
||||
if (const auto users = data.vusers()) {
|
||||
for (const auto &userId : users->v) {
|
||||
chats.list.push_back(owner->user(UserId(userId.v)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] Data::AwaySettings FromMTP(
|
||||
not_null<Data::Session*> owner,
|
||||
const tl::conditional<MTPBusinessAwayMessage> &message) {
|
||||
if (!message) {
|
||||
return Data::AwaySettings();
|
||||
}
|
||||
const auto &data = message->data();
|
||||
auto result = Data::AwaySettings{
|
||||
.recipients = FromMTP(owner, data.vrecipients()),
|
||||
.shortcutId = data.vshortcut_id().v,
|
||||
.offlineOnly = data.is_offline_only(),
|
||||
};
|
||||
data.vschedule().match([&](
|
||||
const MTPDbusinessAwayMessageScheduleAlways &) {
|
||||
result.schedule.type = Data::AwayScheduleType::Always;
|
||||
}, [&](const MTPDbusinessAwayMessageScheduleOutsideWorkHours &) {
|
||||
result.schedule.type = Data::AwayScheduleType::OutsideWorkingHours;
|
||||
}, [&](const MTPDbusinessAwayMessageScheduleCustom &data) {
|
||||
result.schedule.type = Data::AwayScheduleType::Custom;
|
||||
result.schedule.customInterval = Data::WorkingInterval{
|
||||
data.vstart_date().v,
|
||||
data.vend_date().v,
|
||||
};
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] Data::GreetingSettings FromMTP(
|
||||
not_null<Data::Session*> owner,
|
||||
const tl::conditional<MTPBusinessGreetingMessage> &message) {
|
||||
if (!message) {
|
||||
return Data::GreetingSettings();
|
||||
}
|
||||
const auto &data = message->data();
|
||||
return Data::GreetingSettings{
|
||||
.recipients = FromMTP(owner, data.vrecipients()),
|
||||
.noActivityDays = data.vno_activity_days().v,
|
||||
.shortcutId = data.vshortcut_id().v,
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
BotInfo::BotInfo() = default;
|
||||
|
Reference in New Issue
Block a user