mirror of https://github.com/procxx/kepka.git
Unblock bots without restarting from Settings.
This commit is contained in:
parent
0e964b06dc
commit
9d09cee1cc
|
@ -592,7 +592,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_blocked_list_title" = "Blocked users";
|
"lng_blocked_list_title" = "Blocked users";
|
||||||
"lng_blocked_list_unknown_phone" = "unknown phone number";
|
"lng_blocked_list_unknown_phone" = "unknown phone number";
|
||||||
"lng_blocked_list_unblock" = "Unblock";
|
"lng_blocked_list_unblock" = "Unblock";
|
||||||
"lng_blocked_list_restart" = "Restart";
|
|
||||||
"lng_blocked_list_add" = "Block user";
|
"lng_blocked_list_add" = "Block user";
|
||||||
"lng_blocked_list_add_title" = "Select user to block";
|
"lng_blocked_list_add_title" = "Select user to block";
|
||||||
"lng_blocked_list_already_blocked" = "blocked already";
|
"lng_blocked_list_already_blocked" = "blocked already";
|
||||||
|
|
|
@ -2224,38 +2224,40 @@ void ApiWrap::blockUser(not_null<UserData*> user) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiWrap::unblockUser(not_null<UserData*> user) {
|
void ApiWrap::unblockUser(not_null<UserData*> user, Fn<void()> onDone) {
|
||||||
if (!user->isBlocked()) {
|
if (!user->isBlocked()) {
|
||||||
Notify::peerUpdatedDelayed(
|
Notify::peerUpdatedDelayed(
|
||||||
user,
|
user,
|
||||||
Notify::PeerUpdate::Flag::UserIsBlocked);
|
Notify::PeerUpdate::Flag::UserIsBlocked);
|
||||||
} else if (_blockRequests.find(user) == end(_blockRequests)) {
|
return;
|
||||||
const auto requestId = request(MTPcontacts_Unblock(
|
} else if (_blockRequests.find(user) != end(_blockRequests)) {
|
||||||
user->inputUser
|
return;
|
||||||
)).done([=](const MTPBool &result) {
|
|
||||||
_blockRequests.erase(user);
|
|
||||||
user->setIsBlocked(false);
|
|
||||||
if (_blockedUsersSlice) {
|
|
||||||
auto &list = _blockedUsersSlice->list;
|
|
||||||
for (auto i = list.begin(); i != list.end(); ++i) {
|
|
||||||
if (i->user == user) {
|
|
||||||
list.erase(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (_blockedUsersSlice->total > list.size()) {
|
|
||||||
--_blockedUsersSlice->total;
|
|
||||||
}
|
|
||||||
_blockedUsersChanges.fire_copy(*_blockedUsersSlice);
|
|
||||||
}
|
|
||||||
if (user->isBot() && !user->isSupport()) {
|
|
||||||
sendBotStart(user);
|
|
||||||
}
|
|
||||||
}).fail([=](const RPCError &error) {
|
|
||||||
_blockRequests.erase(user);
|
|
||||||
}).send();
|
|
||||||
_blockRequests.emplace(user, requestId);
|
|
||||||
}
|
}
|
||||||
|
const auto requestId = request(MTPcontacts_Unblock(
|
||||||
|
user->inputUser
|
||||||
|
)).done([=](const MTPBool &result) {
|
||||||
|
_blockRequests.erase(user);
|
||||||
|
user->setIsBlocked(false);
|
||||||
|
if (_blockedUsersSlice) {
|
||||||
|
auto &list = _blockedUsersSlice->list;
|
||||||
|
for (auto i = list.begin(); i != list.end(); ++i) {
|
||||||
|
if (i->user == user) {
|
||||||
|
list.erase(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_blockedUsersSlice->total > list.size()) {
|
||||||
|
--_blockedUsersSlice->total;
|
||||||
|
}
|
||||||
|
_blockedUsersChanges.fire_copy(*_blockedUsersSlice);
|
||||||
|
}
|
||||||
|
if (onDone) {
|
||||||
|
onDone();
|
||||||
|
}
|
||||||
|
}).fail([=](const RPCError &error) {
|
||||||
|
_blockRequests.erase(user);
|
||||||
|
}).send();
|
||||||
|
_blockRequests.emplace(user, requestId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiWrap::exportInviteLink(not_null<PeerData*> peer) {
|
void ApiWrap::exportInviteLink(not_null<PeerData*> peer) {
|
||||||
|
|
|
@ -249,7 +249,7 @@ public:
|
||||||
void leaveChannel(not_null<ChannelData*> channel);
|
void leaveChannel(not_null<ChannelData*> channel);
|
||||||
|
|
||||||
void blockUser(not_null<UserData*> user);
|
void blockUser(not_null<UserData*> user);
|
||||||
void unblockUser(not_null<UserData*> user);
|
void unblockUser(not_null<UserData*> user, Fn<void()> onDone = nullptr);
|
||||||
|
|
||||||
void exportInviteLink(not_null<PeerData*> peer);
|
void exportInviteLink(not_null<PeerData*> peer);
|
||||||
void requestNotifySettings(const MTPInputNotifyPeer &peer);
|
void requestNotifySettings(const MTPInputNotifyPeer &peer);
|
||||||
|
|
|
@ -2831,11 +2831,11 @@ void HistoryWidget::send(Qt::KeyboardModifiers modifiers) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::unblockUser() {
|
void HistoryWidget::unblockUser() {
|
||||||
if (!_peer || !_peer->isUser()) {
|
if (const auto user = _peer ? _peer->asUser() : nullptr) {
|
||||||
|
Window::PeerMenuUnblockUserWithBotRestart(user);
|
||||||
|
} else {
|
||||||
updateControlsVisibility();
|
updateControlsVisibility();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
session().api().unblockUser(_peer->asUser());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::sendBotStartCommand() {
|
void HistoryWidget::sendBotStartCommand() {
|
||||||
|
|
|
@ -615,14 +615,12 @@ void ActionsFiller::addBlockAction(not_null<UserData*> user) {
|
||||||
});
|
});
|
||||||
auto callback = [=] {
|
auto callback = [=] {
|
||||||
if (user->isBlocked()) {
|
if (user->isBlocked()) {
|
||||||
user->session().api().unblockUser(user);
|
Window::PeerMenuUnblockUserWithBotRestart(user);
|
||||||
if (user->botInfo) {
|
if (user->botInfo) {
|
||||||
Ui::showPeerHistory(user, ShowAtUnreadMsgId);
|
Ui::showPeerHistory(user, ShowAtUnreadMsgId);
|
||||||
}
|
}
|
||||||
} else if (user->isBot()) {
|
|
||||||
user->session().api().blockUser(user);
|
|
||||||
} else {
|
} else {
|
||||||
window->show(Box(Window::PeerMenuBlockUserBox, window, user));
|
user->session().api().blockUser(user);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
AddActionButton(
|
AddActionButton(
|
||||||
|
|
|
@ -286,9 +286,7 @@ bool BlockedBoxController::prependRow(not_null<UserData*> user) {
|
||||||
std::unique_ptr<PeerListRow> BlockedBoxController::createRow(
|
std::unique_ptr<PeerListRow> BlockedBoxController::createRow(
|
||||||
not_null<UserData*> user) const {
|
not_null<UserData*> user) const {
|
||||||
auto row = std::make_unique<PeerListRowWithLink>(user);
|
auto row = std::make_unique<PeerListRowWithLink>(user);
|
||||||
row->setActionLink((user->isBot() && !user->isSupport())
|
row->setActionLink(tr::lng_blocked_list_unblock(tr::now));
|
||||||
? tr::lng_blocked_list_restart(tr::now)
|
|
||||||
: tr::lng_blocked_list_unblock(tr::now));
|
|
||||||
const auto status = [&] {
|
const auto status = [&] {
|
||||||
if (!user->phone().isEmpty()) {
|
if (!user->phone().isEmpty()) {
|
||||||
return App::formatPhone(user->phone());
|
return App::formatPhone(user->phone());
|
||||||
|
|
|
@ -344,7 +344,7 @@ void Filler::addBlockUser(not_null<UserData*> user) {
|
||||||
};
|
};
|
||||||
const auto blockAction = _addAction(blockText(user), [=] {
|
const auto blockAction = _addAction(blockText(user), [=] {
|
||||||
if (user->isBlocked()) {
|
if (user->isBlocked()) {
|
||||||
user->session().api().unblockUser(user);
|
PeerMenuUnblockUserWithBotRestart(user);
|
||||||
} else if (user->isBot()) {
|
} else if (user->isBot()) {
|
||||||
user->session().api().blockUser(user);
|
user->session().api().blockUser(user);
|
||||||
} else {
|
} else {
|
||||||
|
@ -778,6 +778,14 @@ void PeerMenuBlockUserBox(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PeerMenuUnblockUserWithBotRestart(not_null<UserData*> user) {
|
||||||
|
user->session().api().unblockUser(user, [=] {
|
||||||
|
if (user->isBot() && !user->isSupport()) {
|
||||||
|
user->session().api().sendBotStart(user);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
QPointer<Ui::RpWidget> ShowForwardMessagesBox(
|
QPointer<Ui::RpWidget> ShowForwardMessagesBox(
|
||||||
MessageIdsList &&items,
|
MessageIdsList &&items,
|
||||||
FnMut<void()> &&successCallback) {
|
FnMut<void()> &&successCallback) {
|
||||||
|
|
|
@ -57,6 +57,7 @@ void PeerMenuBlockUserBox(
|
||||||
not_null<GenericBox*> box,
|
not_null<GenericBox*> box,
|
||||||
not_null<Window::Controller*> window,
|
not_null<Window::Controller*> window,
|
||||||
not_null<UserData*> user);
|
not_null<UserData*> user);
|
||||||
|
void PeerMenuUnblockUserWithBotRestart(not_null<UserData*> user);
|
||||||
|
|
||||||
void ToggleHistoryArchived(not_null<History*> history, bool archived);
|
void ToggleHistoryArchived(not_null<History*> history, bool archived);
|
||||||
Fn<void()> ClearHistoryHandler(not_null<PeerData*> peer);
|
Fn<void()> ClearHistoryHandler(not_null<PeerData*> peer);
|
||||||
|
|
Loading…
Reference in New Issue