Skip to content

Commit

Permalink
wip fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jun 26, 2024
1 parent c5d72a5 commit 370d42f
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 4 deletions.
15 changes: 15 additions & 0 deletions Telegram/SourceFiles/api/api_chat_links.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ For license and copyright information please follow this link:
#include "data/data_session.h"
#include "main/main_session.h"

#include "tdb/tdb_sender.h"
#include "tdb/tdb_tl_scheme.h"

namespace Api {
namespace {

using namespace Tdb;

#if 0 // mtp
[[nodiscard]] ChatLink FromMTP(
not_null<Main::Session*> session,
const MTPBusinessChatLink &link) {
Expand Down Expand Up @@ -49,6 +55,7 @@ namespace {
std::move(entities),
MTP_string(title));
}
#endif

} // namespace

Expand All @@ -60,6 +67,7 @@ void ChatLinks::create(
const TextWithEntities &message,
Fn<void(Link)> done) {
const auto session = &_api->session();
#if 0 // tdlib todo
_api->request(MTPaccount_CreateBusinessChatLink(
ToMTP(session, title, message)
)).done([=](const MTPBusinessChatLink &result) {
Expand All @@ -71,6 +79,7 @@ void ChatLinks::create(
const auto type = error.type();
if (done) done(Link());
}).send();
#endif
}

void ChatLinks::edit(
Expand All @@ -79,6 +88,7 @@ void ChatLinks::edit(
const TextWithEntities &message,
Fn<void(Link)> done) {
const auto session = &_api->session();
#if 0 // tdlib todo
_api->request(MTPaccount_EditBusinessChatLink(
MTP_string(link),
ToMTP(session, title, message)
Expand All @@ -102,11 +112,13 @@ void ChatLinks::edit(
const auto type = error.type();
if (done) done(Link());
}).send();
#endif
}

void ChatLinks::destroy(
const QString &link,
Fn<void()> done) {
#if 0 // tdlib todo
_api->request(MTPaccount_DeleteBusinessChatLink(
MTP_string(link)
)).done([=] {
Expand All @@ -123,12 +135,14 @@ void ChatLinks::destroy(
const auto type = error.type();
if (done) done();
}).send();
#endif
}

void ChatLinks::preload() {
if (_loaded || _requestId) {
return;
}
#if 0 // tdlib todo
_requestId = _api->request(MTPaccount_GetBusinessChatLinks(
)).done([=](const MTPaccount_BusinessChatLinks &result) {
const auto &data = result.data();
Expand All @@ -149,6 +163,7 @@ void ChatLinks::preload() {
_loaded = true;
_loadedUpdates.fire({});
}).send();
#endif
}

const std::vector<ChatLink> &ChatLinks::list() const {
Expand Down
4 changes: 4 additions & 0 deletions Telegram/SourceFiles/api/api_earn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void RestrictSponsored(
not_null<ChannelData*> channel,
bool restricted,
Fn<void(QString)> failed) {
#if 0 // tdlib todo
channel->session().api().request(MTPchannels_RestrictSponsoredMessages(
channel->inputChannel,
MTP_bool(restricted))
Expand All @@ -31,6 +32,7 @@ void RestrictSponsored(
}).fail([=](const MTP::Error &error) {
failed(error.type());
}).send();
#endif
}

void HandleWithdrawalButton(
Expand Down Expand Up @@ -77,6 +79,7 @@ void HandleWithdrawalButton(
const auto fail = [=](const QString &error) {
show->showToast(error);
};
#if 0 // tdlib todo
session->api().request(
MTPstats_GetBroadcastRevenueWithdrawalUrl(
channel->inputChannel,
Expand All @@ -86,6 +89,7 @@ void HandleWithdrawalButton(
}).fail([=](const MTP::Error &error) {
fail(error.type());
}).send();
#endif
});
show->show(Box<PasscodeBox>(session, fields));
});
Expand Down
74 changes: 74 additions & 0 deletions Telegram/SourceFiles/data/business/data_business_chatbots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ For license and copyright information please follow this link:
#include "data/data_user.h"
#include "main/main_session.h"

#include "tdb/tdb_sender.h"
#include "tdb/tdb_tl_scheme.h"

namespace Data {
namespace {

using namespace Tdb;

} // namespace

Chatbots::Chatbots(not_null<Session*> owner)
: _owner(owner) {
Expand All @@ -26,6 +34,30 @@ void Chatbots::preload() {
if (_loaded || _requestId) {
return;
}
_requestId = _owner->session().sender().request(
TLgetBusinessConnectedBot()
).done([=](const TLbusinessConnectedBot &result) {
_requestId = 0;
_loaded = true;

const auto &data = result.data();
const auto botId = UserId(data.vbot_user_id().v);
_settings = ChatbotsSettings{
.bot = _owner->session().data().user(botId),
.recipients = FromTL(_owner, data.vrecipients()),
.repliesAllowed = data.vcan_reply().v,
};
}).fail([=](const Error &error) {
_requestId = 0;
if (error.code == 404) {
_loaded = true;
_settings.force_assign(ChatbotsSettings());
} else {
LOG(("API Error: Could not get connected bot (%1)"
).arg(error.message));
}
}).send();
#if 0 // mtp
_requestId = _owner->session().api().request(
MTPaccount_GetConnectedBots()
).done([=](const MTPaccount_ConnectedBots &result) {
Expand All @@ -52,6 +84,7 @@ void Chatbots::preload() {
).arg(error.code()
).arg(error.type()));
}).send();
#endif
}

bool Chatbots::loaded() const {
Expand All @@ -77,6 +110,33 @@ void Chatbots::save(
const auto was = _settings.current();
if (was == settings) {
return;
} else if (settings.bot) {
_owner->session().sender().request(TLsetBusinessConnectedBot(
tl_businessConnectedBot(
tl_int53(peerToUser(settings.bot->id).bare),
ForBotsToTL(settings.recipients),
tl_bool(settings.repliesAllowed))
)).done([=] {
if (done) {
done();
}
}).fail([=](const Error &error) {
if (fail) {
fail(error.message);
}
}).send();
} else if (was.bot) {
_owner->session().sender().request(TLdeleteBusinessConnectedBot(
)).done([=] {
if (done) {
done();
}
}).fail([=](const Error &error) {
if (fail) {
fail(error.message);
}
}).send();
#if 0 // mtp
} else if (was.bot || settings.bot) {
using Flag = MTPaccount_UpdateConnectedBot::Flag;
const auto api = &_owner->session().api();
Expand All @@ -99,6 +159,7 @@ void Chatbots::save(
fail(error.type());
}
}).send();
#endif
}
_settings = settings;
}
Expand All @@ -107,7 +168,10 @@ void Chatbots::togglePaused(not_null<PeerData*> peer, bool paused) {
const auto type = paused
? SentRequestType::Pause
: SentRequestType::Unpause;
#if 0 // mtp
const auto api = &_owner->session().api();
#endif
const auto api = &_owner->session().sender();
const auto i = _sentRequests.find(peer);
if (i != end(_sentRequests)) {
const auto already = i->second.type;
Expand All @@ -117,6 +181,7 @@ void Chatbots::togglePaused(not_null<PeerData*> peer, bool paused) {
api->request(i->second.requestId).cancel();
_sentRequests.erase(i);
}
#if 0 // tdlib todo
const auto id = api->request(MTPaccount_ToggleConnectedBotPaused(
peer->input,
MTP_bool(paused)
Expand All @@ -141,11 +206,15 @@ void Chatbots::togglePaused(not_null<PeerData*> peer, bool paused) {
_sentRequests.remove(peer);
}).send();
_sentRequests[peer] = SentRequest{ type, id };
#endif
}

void Chatbots::removeFrom(not_null<PeerData*> peer) {
const auto type = SentRequestType::Remove;
#if 0 // mtp
const auto api = &_owner->session().api();
#endif
const auto api = &_owner->session().sender();
const auto i = _sentRequests.find(peer);
if (i != end(_sentRequests)) {
const auto already = i->second.type;
Expand All @@ -155,6 +224,7 @@ void Chatbots::removeFrom(not_null<PeerData*> peer) {
api->request(i->second.requestId).cancel();
_sentRequests.erase(i);
}
#if 0 // tdlib todo
const auto id = api->request(MTPaccount_DisablePeerConnectedBot(
peer->input
)).done([=] {
Expand All @@ -172,11 +242,15 @@ void Chatbots::removeFrom(not_null<PeerData*> peer) {
_sentRequests.remove(peer);
}).send();
_sentRequests[peer] = SentRequest{ type, id };
#endif
}

void Chatbots::reload() {
_loaded = false;
#if 0 // mtp
_owner->session().api().request(base::take(_requestId)).cancel();
#endif
_owner->session().sender().request(base::take(_requestId)).cancel();
preload();
}

Expand Down
Loading

0 comments on commit 370d42f

Please sign in to comment.