mirror of
https://github.com/Qz3rK/tdesktop.git
synced 2026-07-03 14:15:08 +02:00
Start editing chat intro in Telegram Business.
This commit is contained in:
@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "data/business/data_business_common.h"
|
||||
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
|
||||
@@ -333,4 +334,22 @@ WorkingIntervals ReplaceDayIntervals(
|
||||
return result.normalized();
|
||||
}
|
||||
|
||||
ChatIntro FromMTP(
|
||||
not_null<Session*> owner,
|
||||
const tl::conditional<MTPBusinessIntro> &intro) {
|
||||
auto result = ChatIntro();
|
||||
if (intro) {
|
||||
const auto &data = intro->data();
|
||||
result.title = qs(data.vtitle());
|
||||
result.description = qs(data.vdescription());
|
||||
if (const auto document = data.vsticker()) {
|
||||
result.sticker = owner->processDocument(*document);
|
||||
if (!result.sticker->sticker()) {
|
||||
result.sticker = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Data
|
||||
|
||||
@@ -252,4 +252,22 @@ struct GreetingSettings {
|
||||
not_null<Session*> owner,
|
||||
const tl::conditional<MTPBusinessGreetingMessage> &message);
|
||||
|
||||
struct ChatIntro {
|
||||
QString title;
|
||||
QString description;
|
||||
DocumentData *sticker = nullptr;
|
||||
|
||||
explicit operator bool() const {
|
||||
return !title.isEmpty() || !description.isEmpty();
|
||||
}
|
||||
|
||||
friend inline bool operator==(
|
||||
const ChatIntro &a,
|
||||
const ChatIntro &b) = default;
|
||||
};
|
||||
|
||||
[[nodiscard]] ChatIntro FromMTP(
|
||||
not_null<Session*> owner,
|
||||
const tl::conditional<MTPBusinessIntro> &intro);
|
||||
|
||||
} // namespace Data
|
||||
|
||||
@@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "apiwrap.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "data/business/data_business_common.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
#include "main/main_session.h"
|
||||
@@ -183,6 +184,54 @@ rpl::producer<> BusinessInfo::greetingSettingsChanged() const {
|
||||
return _greetingSettingsChanged.events();
|
||||
}
|
||||
|
||||
void BusinessInfo::saveChatIntro(ChatIntro data, Fn<void(QString)> fail) {
|
||||
const auto &was = _chatIntro;
|
||||
if (was == data) {
|
||||
return;
|
||||
} else {
|
||||
const auto session = &_owner->session();
|
||||
using Flag = MTPaccount_UpdateBusinessIntro::Flag;
|
||||
session->api().request(MTPaccount_UpdateBusinessIntro(
|
||||
MTP_flags(data ? Flag::f_intro : Flag()),
|
||||
MTP_inputBusinessIntro(
|
||||
MTP_flags(data.sticker ? MTPDinputBusinessIntro::Flag::f_sticker : MTPDinputBusinessIntro::Flag()),
|
||||
MTP_string(data.title),
|
||||
MTP_string(data.description),
|
||||
(data.sticker
|
||||
? data.sticker->mtpInput()
|
||||
: MTP_inputDocumentEmpty()))
|
||||
)).fail([=](const MTP::Error &error) {
|
||||
_chatIntro = was;
|
||||
_chatIntroChanged.fire({});
|
||||
if (fail) {
|
||||
fail(error.type());
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
_chatIntro = std::move(data);
|
||||
_chatIntroChanged.fire({});
|
||||
}
|
||||
|
||||
void BusinessInfo::applyChatIntro(ChatIntro data) {
|
||||
if (_chatIntro == data) {
|
||||
return;
|
||||
}
|
||||
_chatIntro = data;
|
||||
_chatIntroChanged.fire({});
|
||||
}
|
||||
|
||||
ChatIntro BusinessInfo::chatIntro() const {
|
||||
return _chatIntro.value_or(ChatIntro());
|
||||
}
|
||||
|
||||
bool BusinessInfo::chatIntroLoaded() const {
|
||||
return _chatIntro.has_value();
|
||||
}
|
||||
|
||||
rpl::producer<> BusinessInfo::chatIntroChanged() const {
|
||||
return _chatIntroChanged.events();
|
||||
}
|
||||
|
||||
void BusinessInfo::preload() {
|
||||
preloadTimezones();
|
||||
}
|
||||
|
||||
@@ -36,6 +36,12 @@ public:
|
||||
[[nodiscard]] bool greetingSettingsLoaded() const;
|
||||
[[nodiscard]] rpl::producer<> greetingSettingsChanged() const;
|
||||
|
||||
void saveChatIntro(ChatIntro data, Fn<void(QString)> fail);
|
||||
void applyChatIntro(ChatIntro data);
|
||||
[[nodiscard]] ChatIntro chatIntro() const;
|
||||
[[nodiscard]] bool chatIntroLoaded() const;
|
||||
[[nodiscard]] rpl::producer<> chatIntroChanged() const;
|
||||
|
||||
void preloadTimezones();
|
||||
[[nodiscard]] bool timezonesLoaded() const;
|
||||
[[nodiscard]] rpl::producer<Timezones> timezonesValue() const;
|
||||
@@ -51,6 +57,9 @@ private:
|
||||
std::optional<GreetingSettings> _greetingSettings;
|
||||
rpl::event_stream<> _greetingSettingsChanged;
|
||||
|
||||
std::optional<ChatIntro> _chatIntro;
|
||||
rpl::event_stream<> _chatIntroChanged;
|
||||
|
||||
mtpRequestId _timezonesRequestId = 0;
|
||||
int32 _timezonesHash = 0;
|
||||
|
||||
|
||||
@@ -601,6 +601,8 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
|
||||
FromMTP(&user->owner(), update.vbusiness_away_message()));
|
||||
user->owner().businessInfo().applyGreetingSettings(
|
||||
FromMTP(&user->owner(), update.vbusiness_greeting_message()));
|
||||
user->owner().businessInfo().applyChatIntro(
|
||||
FromMTP(&user->owner(), update.vbusiness_intro()));
|
||||
}
|
||||
|
||||
user->owner().stories().apply(user, update.vstories());
|
||||
|
||||
Reference in New Issue
Block a user