mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Support business working hours API.
This commit is contained in:
@@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "storage/localstorage.h"
|
||||
#include "storage/storage_user_photos.h"
|
||||
#include "main/main_session.h"
|
||||
#include "data/business/data_business_common.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_changes.h"
|
||||
#include "data/data_peer_bot_command.h"
|
||||
@@ -30,6 +31,34 @@ 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());
|
||||
data.vgeo_point().match([&](const MTPDgeoPoint &data) {
|
||||
result.location.point = Data::LocationPoint(data);
|
||||
}, [&](const MTPDgeoPointEmpty &) {
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
BotInfo::BotInfo() = default;
|
||||
@@ -62,6 +91,8 @@ UserData::UserData(not_null<Data::Session*> owner, PeerId id)
|
||||
, _flags((id == owner->session().userPeerId()) ? Flag::Self : Flag(0)) {
|
||||
}
|
||||
|
||||
UserData::~UserData() = default;
|
||||
|
||||
bool UserData::canShareThisContact() const {
|
||||
return canShareThisContactFast()
|
||||
|| !owner().findContactPhone(peerToUser(id)).isEmpty();
|
||||
@@ -174,6 +205,22 @@ void UserData::setStoriesState(StoriesState state) {
|
||||
}
|
||||
}
|
||||
|
||||
const Data::BusinessDetails &UserData::businessDetails() const {
|
||||
static const auto empty = Data::BusinessDetails();
|
||||
return _businessDetails ? *_businessDetails : empty;
|
||||
}
|
||||
|
||||
void UserData::setBusinessDetails(Data::BusinessDetails details) {
|
||||
if ((!details && !_businessDetails)
|
||||
|| (details && _businessDetails && details == *_businessDetails)) {
|
||||
return;
|
||||
}
|
||||
_businessDetails = details
|
||||
? std::make_unique<Data::BusinessDetails>(std::move(details))
|
||||
: nullptr;
|
||||
session().changes().peerUpdated(this, UpdateFlag::BusinessDetails);
|
||||
}
|
||||
|
||||
void UserData::setName(const QString &newFirstName, const QString &newLastName, const QString &newPhoneName, const QString &newUsername) {
|
||||
bool changeName = !newFirstName.isEmpty() || !newLastName.isEmpty();
|
||||
|
||||
@@ -572,6 +619,10 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
|
||||
user->setWallPaper({});
|
||||
}
|
||||
|
||||
user->setBusinessDetails(FromMTP(
|
||||
update.vbusiness_work_hours(),
|
||||
update.vbusiness_location()));
|
||||
|
||||
user->owner().stories().apply(user, update.vstories());
|
||||
|
||||
user->fullUpdated();
|
||||
|
Reference in New Issue
Block a user