2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Restart instead of Unblock for bots.

This commit is contained in:
John Preston
2018-12-04 15:46:07 +04:00
parent 6562a1f6af
commit 61add763ae
9 changed files with 84 additions and 95 deletions

View File

@@ -1907,15 +1907,21 @@ void ApiWrap::blockUser(not_null<UserData*> user) {
void ApiWrap::unblockUser(not_null<UserData*> user) {
if (!user->isBlocked()) {
Notify::peerUpdatedDelayed(user, Notify::PeerUpdate::Flag::UserIsBlocked);
Notify::peerUpdatedDelayed(
user,
Notify::PeerUpdate::Flag::UserIsBlocked);
} else if (_blockRequests.find(user) == end(_blockRequests)) {
auto requestId = request(MTPcontacts_Unblock(user->inputUser)).done([this, user](const MTPBool &result) {
const auto requestId = request(MTPcontacts_Unblock(
user->inputUser
)).done([=](const MTPBool &result) {
_blockRequests.erase(user);
user->setBlockStatus(UserData::BlockStatus::NotBlocked);
}).fail([this, user](const RPCError &error) {
if (user->botInfo) {
sendBotStart(user);
}
}).fail([=](const RPCError &error) {
_blockRequests.erase(user);
}).send();
_blockRequests.emplace(user, requestId);
}
}
@@ -4544,6 +4550,28 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
}
}
void ApiWrap::sendBotStart(not_null<UserData*> bot) {
Expects(bot->botInfo != nullptr);
const auto token = bot->botInfo->startToken;
if (token.isEmpty()) {
auto message = ApiWrap::MessageToSend(App::history(bot));
message.textWithTags = { qsl("/start"), TextWithTags::Tags() };
sendMessage(std::move(message));
} else {
bot->botInfo->startToken = QString();
const auto randomId = rand_value<uint64>();
request(MTPmessages_StartBot(
bot->inputUser,
MTP_inputPeerEmpty(),
MTP_long(randomId),
MTP_string(token)
)).done([=](const MTPUpdates &result) {
applyUpdates(result);
}).send();
}
}
void ApiWrap::sendInlineResult(
not_null<UserData*> bot,
not_null<InlineBots::Result*> data,