2017-08-14 12:53:49 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-08-14 12:53:49 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-08-14 12:53:49 +00:00
|
|
|
*/
|
|
|
|
#include "boxes/peer_list_controllers.h"
|
|
|
|
|
2017-08-14 12:48:11 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "observer_peer.h"
|
|
|
|
#include "ui/widgets/checkbox.h"
|
2017-08-14 12:53:49 +00:00
|
|
|
#include "auth_session.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_chat.h"
|
|
|
|
#include "data/data_user.h"
|
2019-04-22 18:18:57 +00:00
|
|
|
#include "data/data_folder.h"
|
2017-08-14 12:48:11 +00:00
|
|
|
#include "apiwrap.h"
|
2017-08-14 12:53:49 +00:00
|
|
|
#include "mainwidget.h"
|
|
|
|
#include "lang/lang_keys.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2019-04-22 14:22:39 +00:00
|
|
|
#include "dialogs/dialogs_main_list.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_profile.h"
|
2017-08-14 12:53:49 +00:00
|
|
|
|
2017-08-14 12:48:11 +00:00
|
|
|
namespace {
|
|
|
|
|
2018-11-26 11:00:31 +00:00
|
|
|
void ShareBotGame(not_null<UserData*> bot, not_null<PeerData*> chat) {
|
2019-01-18 12:27:37 +00:00
|
|
|
const auto history = chat->owner().historyLoaded(chat);
|
2018-11-26 11:00:31 +00:00
|
|
|
const auto randomId = rand_value<uint64>();
|
|
|
|
const auto requestId = MTP::send(
|
|
|
|
MTPmessages_SendMedia(
|
|
|
|
MTP_flags(0),
|
|
|
|
chat->input,
|
|
|
|
MTP_int(0),
|
|
|
|
MTP_inputMediaGame(
|
|
|
|
MTP_inputGameShortName(
|
|
|
|
bot->inputUser,
|
|
|
|
MTP_string(bot->botInfo->shareGameShortName))),
|
|
|
|
MTP_string(""),
|
|
|
|
MTP_long(randomId),
|
2019-03-15 15:15:56 +00:00
|
|
|
MTPReplyMarkup(),
|
2018-11-26 11:00:31 +00:00
|
|
|
MTPnullEntities),
|
|
|
|
App::main()->rpcDone(&MainWidget::sentUpdatesReceived),
|
|
|
|
App::main()->rpcFail(&MainWidget::sendMessageFail),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
history ? history->sendRequestId : 0);
|
|
|
|
if (history) {
|
|
|
|
history->sendRequestId = requestId;
|
|
|
|
}
|
|
|
|
Ui::hideLayer();
|
|
|
|
Ui::showPeerHistory(chat, ShowAtUnreadMsgId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddBotToGroup(not_null<UserData*> bot, not_null<PeerData*> chat) {
|
2018-12-28 11:42:58 +00:00
|
|
|
if (bot->botInfo && !bot->botInfo->startGroupToken.isEmpty()) {
|
|
|
|
Auth().api().sendBotStart(bot, chat);
|
2018-11-26 11:00:31 +00:00
|
|
|
} else {
|
2018-12-28 11:42:58 +00:00
|
|
|
Auth().api().addChatParticipants(chat, { 1, bot });
|
2018-11-26 11:00:31 +00:00
|
|
|
}
|
|
|
|
Ui::hideLayer();
|
|
|
|
Ui::showPeerHistory(chat, ShowAtUnreadMsgId);
|
|
|
|
}
|
|
|
|
|
2017-08-14 12:48:11 +00:00
|
|
|
} // namespace
|
|
|
|
|
2017-08-15 09:41:53 +00:00
|
|
|
// Not used for now.
|
|
|
|
//
|
|
|
|
//MembersAddButton::MembersAddButton(QWidget *parent, const style::TwoIconButton &st) : RippleButton(parent, st.ripple)
|
|
|
|
//, _st(st) {
|
|
|
|
// resize(_st.width, _st.height);
|
|
|
|
// setCursor(style::cur_pointer);
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//void MembersAddButton::paintEvent(QPaintEvent *e) {
|
|
|
|
// Painter p(this);
|
|
|
|
//
|
2019-02-19 06:57:53 +00:00
|
|
|
// auto ms = crl::now();
|
2017-08-15 09:41:53 +00:00
|
|
|
// auto over = isOver();
|
|
|
|
// auto down = isDown();
|
|
|
|
//
|
|
|
|
// ((over || down) ? _st.iconBelowOver : _st.iconBelow).paint(p, _st.iconPosition, width());
|
|
|
|
// paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y(), ms);
|
|
|
|
// ((over || down) ? _st.iconAboveOver : _st.iconAbove).paint(p, _st.iconPosition, width());
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//QImage MembersAddButton::prepareRippleMask() const {
|
|
|
|
// return Ui::RippleAnimation::ellipseMask(QSize(_st.rippleAreaSize, _st.rippleAreaSize));
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//QPoint MembersAddButton::prepareRippleStartPosition() const {
|
|
|
|
// return mapFromGlobal(QCursor::pos()) - _st.rippleAreaPosition;
|
|
|
|
//}
|
|
|
|
|
2017-08-14 12:53:49 +00:00
|
|
|
void PeerListRowWithLink::setActionLink(const QString &action) {
|
|
|
|
_action = action;
|
|
|
|
refreshActionLink();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerListRowWithLink::refreshActionLink() {
|
|
|
|
if (!isInitialized()) return;
|
|
|
|
_actionWidth = _action.isEmpty() ? 0 : st::normalFont->width(_action);
|
|
|
|
}
|
|
|
|
|
2017-10-10 20:39:44 +00:00
|
|
|
void PeerListRowWithLink::lazyInitialize(const style::PeerListItem &st) {
|
|
|
|
PeerListRow::lazyInitialize(st);
|
2017-08-14 12:53:49 +00:00
|
|
|
refreshActionLink();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize PeerListRowWithLink::actionSize() const {
|
|
|
|
return QSize(_actionWidth, st::normalFont->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
QMargins PeerListRowWithLink::actionMargins() const {
|
2017-11-07 17:53:00 +00:00
|
|
|
return QMargins(
|
|
|
|
st::contactsCheckPosition.x(),
|
|
|
|
(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom() - st::normalFont->height) / 2,
|
|
|
|
st::defaultPeerListItem.photoPosition.x() + st::contactsCheckPosition.x(),
|
|
|
|
0);
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-07 17:53:00 +00:00
|
|
|
void PeerListRowWithLink::paintAction(
|
|
|
|
Painter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
bool selected,
|
|
|
|
bool actionSelected) {
|
2017-08-14 12:53:49 +00:00
|
|
|
p.setFont(actionSelected ? st::linkOverFont : st::linkFont);
|
|
|
|
p.setPen(actionSelected ? st::defaultLinkButton.overColor : st::defaultLinkButton.color);
|
|
|
|
p.drawTextLeft(x, y, outerWidth, _action, _actionWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
PeerListGlobalSearchController::PeerListGlobalSearchController() {
|
|
|
|
_timer.setCallback([this] { searchOnServer(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerListGlobalSearchController::searchQuery(const QString &query) {
|
|
|
|
if (_query != query) {
|
|
|
|
_query = query;
|
|
|
|
_requestId = 0;
|
2018-01-22 10:58:11 +00:00
|
|
|
if (!_query.isEmpty() && !searchInCache()) {
|
2017-08-14 12:53:49 +00:00
|
|
|
_timer.callOnce(AutoSearchTimeout);
|
|
|
|
} else {
|
|
|
|
_timer.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PeerListGlobalSearchController::searchInCache() {
|
|
|
|
auto it = _cache.find(_query);
|
|
|
|
if (it != _cache.cend()) {
|
|
|
|
_requestId = 0;
|
|
|
|
searchDone(it->second, _requestId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerListGlobalSearchController::searchOnServer() {
|
2018-01-22 10:58:11 +00:00
|
|
|
_requestId = request(MTPcontacts_Search(
|
|
|
|
MTP_string(_query),
|
|
|
|
MTP_int(SearchPeopleLimit)
|
|
|
|
)).done([=](const MTPcontacts_Found &result, mtpRequestId requestId) {
|
2017-08-14 12:53:49 +00:00
|
|
|
searchDone(result, requestId);
|
2018-01-22 10:58:11 +00:00
|
|
|
}).fail([=](const RPCError &error, mtpRequestId requestId) {
|
2017-08-14 12:53:49 +00:00
|
|
|
if (_requestId == requestId) {
|
|
|
|
_requestId = 0;
|
|
|
|
delegate()->peerListSearchRefreshRows();
|
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
_queries.emplace(_requestId, _query);
|
|
|
|
}
|
|
|
|
|
2018-01-22 10:58:11 +00:00
|
|
|
void PeerListGlobalSearchController::searchDone(
|
|
|
|
const MTPcontacts_Found &result,
|
|
|
|
mtpRequestId requestId) {
|
2017-08-14 12:53:49 +00:00
|
|
|
Expects(result.type() == mtpc_contacts_found);
|
|
|
|
|
|
|
|
auto &contacts = result.c_contacts_found();
|
|
|
|
auto query = _query;
|
|
|
|
if (requestId) {
|
2019-01-18 12:27:37 +00:00
|
|
|
Auth().data().processUsers(contacts.vusers);
|
|
|
|
Auth().data().processChats(contacts.vchats);
|
2017-08-14 12:53:49 +00:00
|
|
|
auto it = _queries.find(requestId);
|
|
|
|
if (it != _queries.cend()) {
|
|
|
|
query = it->second;
|
|
|
|
_cache[query] = result;
|
|
|
|
_queries.erase(it);
|
|
|
|
}
|
|
|
|
}
|
2018-01-22 10:58:11 +00:00
|
|
|
const auto feedList = [&](const MTPVector<MTPPeer> &list) {
|
|
|
|
for (const auto &mtpPeer : list.v) {
|
2019-01-18 12:27:37 +00:00
|
|
|
if (const auto peer = Auth().data().peerLoaded(peerFromMTP(mtpPeer))) {
|
2017-08-14 12:53:49 +00:00
|
|
|
delegate()->peerListSearchAddRow(peer);
|
|
|
|
}
|
|
|
|
}
|
2018-01-22 10:58:11 +00:00
|
|
|
};
|
|
|
|
if (_requestId == requestId) {
|
|
|
|
_requestId = 0;
|
|
|
|
feedList(contacts.vmy_results);
|
|
|
|
feedList(contacts.vresults);
|
2017-08-14 12:53:49 +00:00
|
|
|
delegate()->peerListSearchRefreshRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PeerListGlobalSearchController::isLoading() {
|
|
|
|
return _timer.isActive() || _requestId;
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
ChatsListBoxController::Row::Row(not_null<History*> history)
|
|
|
|
: PeerListRow(history->peer)
|
|
|
|
, _history(history) {
|
|
|
|
}
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
ChatsListBoxController::ChatsListBoxController(
|
|
|
|
std::unique_ptr<PeerListSearchController> searchController)
|
|
|
|
: PeerListController(std::move(searchController)) {
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatsListBoxController::prepare() {
|
|
|
|
setSearchNoResultsText(lang(lng_blocked_list_not_found));
|
|
|
|
delegate()->peerListSetSearchMode(PeerListSearchMode::Enabled);
|
|
|
|
|
|
|
|
prepareViewHook();
|
|
|
|
|
2019-04-18 08:28:43 +00:00
|
|
|
if (!Auth().data().chatsListLoaded()) {
|
|
|
|
Auth().data().chatsListLoadedEvents(
|
|
|
|
) | rpl::filter([=](Data::Folder *folder) {
|
|
|
|
return !folder;
|
|
|
|
}) | rpl::start_with_next([=] {
|
|
|
|
checkForEmptyRows();
|
|
|
|
}, lifetime());
|
|
|
|
}
|
2017-08-14 12:53:49 +00:00
|
|
|
|
2019-04-18 08:28:43 +00:00
|
|
|
Auth().data().chatsListChanges(
|
2019-04-22 18:18:57 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
2017-08-14 12:53:49 +00:00
|
|
|
rebuildRows();
|
2019-04-18 08:28:43 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
Auth().data().contactsLoaded().value(
|
|
|
|
) | rpl::start_with_next([=] {
|
2017-08-14 12:53:49 +00:00
|
|
|
rebuildRows();
|
2019-04-18 08:28:43 +00:00
|
|
|
}, lifetime());
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatsListBoxController::rebuildRows() {
|
|
|
|
auto wasEmpty = !delegate()->peerListFullRowsCount();
|
|
|
|
auto appendList = [this](auto chats) {
|
|
|
|
auto count = 0;
|
2018-01-22 09:33:09 +00:00
|
|
|
for (const auto row : chats->all()) {
|
|
|
|
if (const auto history = row->history()) {
|
|
|
|
if (appendRow(history)) {
|
|
|
|
++count;
|
|
|
|
}
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
};
|
2017-12-05 14:07:01 +00:00
|
|
|
auto added = 0;
|
|
|
|
if (respectSavedMessagesChat()) {
|
2019-01-18 12:27:37 +00:00
|
|
|
if (appendRow(Auth().data().history(Auth().user()))) {
|
2018-09-11 12:50:40 +00:00
|
|
|
++added;
|
2017-12-05 14:07:01 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-22 14:22:39 +00:00
|
|
|
added += appendList(Auth().data().chatsList()->indexed());
|
2019-04-22 18:18:57 +00:00
|
|
|
const auto id = Data::Folder::kId;
|
|
|
|
if (const auto folder = Auth().data().folderLoaded(id)) {
|
|
|
|
added += appendList(folder->chatsList()->indexed());
|
|
|
|
}
|
2019-04-16 14:05:56 +00:00
|
|
|
added += appendList(Auth().data().contactsNoChatsList());
|
2017-08-14 12:53:49 +00:00
|
|
|
if (!wasEmpty && added > 0) {
|
|
|
|
// Place dialogs list before contactsNoDialogs list.
|
2017-10-22 17:06:57 +00:00
|
|
|
delegate()->peerListPartitionRows([](const PeerListRow &a) {
|
2019-04-17 13:22:37 +00:00
|
|
|
const auto history = static_cast<const Row&>(a).history();
|
2019-04-22 14:22:39 +00:00
|
|
|
return history->inChatList();
|
2017-08-14 12:53:49 +00:00
|
|
|
});
|
2017-12-05 14:07:01 +00:00
|
|
|
if (respectSavedMessagesChat()) {
|
|
|
|
delegate()->peerListPartitionRows([](const PeerListRow &a) {
|
|
|
|
return a.peer()->isSelf();
|
|
|
|
});
|
|
|
|
}
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
checkForEmptyRows();
|
|
|
|
delegate()->peerListRefreshRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatsListBoxController::checkForEmptyRows() {
|
|
|
|
if (delegate()->peerListFullRowsCount()) {
|
|
|
|
setDescriptionText(QString());
|
|
|
|
} else {
|
2019-04-18 08:28:43 +00:00
|
|
|
const auto loaded = Auth().data().contactsLoaded().current()
|
|
|
|
&& Auth().data().chatsListLoaded();
|
2017-08-15 09:35:19 +00:00
|
|
|
setDescriptionText(loaded ? emptyBoxText() : lang(lng_contacts_loading));
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-15 09:35:19 +00:00
|
|
|
QString ChatsListBoxController::emptyBoxText() const {
|
|
|
|
return lang(lng_contacts_not_found);
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
std::unique_ptr<PeerListRow> ChatsListBoxController::createSearchRow(not_null<PeerData*> peer) {
|
2019-01-18 12:27:37 +00:00
|
|
|
return createRow(peer->owner().history(peer));
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
bool ChatsListBoxController::appendRow(not_null<History*> history) {
|
2017-08-14 12:53:49 +00:00
|
|
|
if (auto row = delegate()->peerListFindRow(history->peer->id)) {
|
|
|
|
updateRowHook(static_cast<Row*>(row));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (auto row = createRow(history)) {
|
|
|
|
delegate()->peerListAppendRow(std::move(row));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
ContactsBoxController::ContactsBoxController(
|
|
|
|
std::unique_ptr<PeerListSearchController> searchController)
|
|
|
|
: PeerListController(std::move(searchController)) {
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContactsBoxController::prepare() {
|
|
|
|
setSearchNoResultsText(lang(lng_blocked_list_not_found));
|
|
|
|
delegate()->peerListSetSearchMode(PeerListSearchMode::Enabled);
|
|
|
|
delegate()->peerListSetTitle(langFactory(lng_contacts_header));
|
|
|
|
|
|
|
|
prepareViewHook();
|
|
|
|
|
2019-04-18 08:28:43 +00:00
|
|
|
Auth().data().contactsLoaded().value(
|
|
|
|
) | rpl::start_with_next([=] {
|
2017-08-14 12:53:49 +00:00
|
|
|
rebuildRows();
|
2019-04-18 08:28:43 +00:00
|
|
|
}, lifetime());
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContactsBoxController::rebuildRows() {
|
2019-04-16 14:05:56 +00:00
|
|
|
const auto appendList = [&](auto chats) {
|
2017-08-14 12:53:49 +00:00
|
|
|
auto count = 0;
|
2018-01-22 09:33:09 +00:00
|
|
|
for (const auto row : chats->all()) {
|
|
|
|
if (const auto history = row->history()) {
|
|
|
|
if (const auto user = history->peer->asUser()) {
|
|
|
|
if (appendRow(user)) {
|
|
|
|
++count;
|
|
|
|
}
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
};
|
2019-04-16 14:05:56 +00:00
|
|
|
appendList(Auth().data().contactsList());
|
2017-08-14 12:53:49 +00:00
|
|
|
checkForEmptyRows();
|
|
|
|
delegate()->peerListRefreshRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContactsBoxController::checkForEmptyRows() {
|
|
|
|
if (delegate()->peerListFullRowsCount()) {
|
|
|
|
setDescriptionText(QString());
|
|
|
|
} else {
|
2019-04-18 08:28:43 +00:00
|
|
|
const auto loaded = Auth().data().contactsLoaded().current();
|
2017-08-14 12:53:49 +00:00
|
|
|
setDescriptionText(lang(loaded ? lng_contacts_not_found : lng_contacts_loading));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
std::unique_ptr<PeerListRow> ContactsBoxController::createSearchRow(
|
|
|
|
not_null<PeerData*> peer) {
|
|
|
|
if (const auto user = peer->asUser()) {
|
2017-09-03 19:30:04 +00:00
|
|
|
return createRow(user);
|
|
|
|
}
|
|
|
|
return nullptr;
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void ContactsBoxController::rowClicked(not_null<PeerListRow*> row) {
|
2017-08-14 12:53:49 +00:00
|
|
|
Ui::showPeerHistory(row->peer(), ShowAtUnreadMsgId);
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
bool ContactsBoxController::appendRow(not_null<UserData*> user) {
|
2017-08-14 12:53:49 +00:00
|
|
|
if (auto row = delegate()->peerListFindRow(user->id)) {
|
|
|
|
updateRowHook(row);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (auto row = createRow(user)) {
|
|
|
|
delegate()->peerListAppendRow(std::move(row));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
std::unique_ptr<PeerListRow> ContactsBoxController::createRow(not_null<UserData*> user) {
|
2017-08-14 12:53:49 +00:00
|
|
|
return std::make_unique<PeerListRow>(user);
|
|
|
|
}
|
2017-08-14 12:48:11 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void AddBotToGroupBoxController::Start(not_null<UserData*> bot) {
|
2018-04-07 08:47:08 +00:00
|
|
|
auto initBox = [=](not_null<PeerListBox*> box) {
|
2017-08-15 09:35:19 +00:00
|
|
|
box->addButton(langFactory(lng_cancel), [box] { box->closeBox(); });
|
|
|
|
};
|
|
|
|
Ui::show(Box<PeerListBox>(std::make_unique<AddBotToGroupBoxController>(bot), std::move(initBox)));
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
AddBotToGroupBoxController::AddBotToGroupBoxController(not_null<UserData*> bot)
|
2017-08-15 09:35:19 +00:00
|
|
|
: ChatsListBoxController(SharingBotGame(bot)
|
|
|
|
? std::make_unique<PeerListGlobalSearchController>()
|
|
|
|
: nullptr)
|
|
|
|
, _bot(bot) {
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void AddBotToGroupBoxController::rowClicked(not_null<PeerListRow*> row) {
|
2017-08-15 09:35:19 +00:00
|
|
|
if (sharingBotGame()) {
|
|
|
|
shareBotGame(row->peer());
|
|
|
|
} else {
|
|
|
|
addBotToGroup(row->peer());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void AddBotToGroupBoxController::shareBotGame(not_null<PeerData*> chat) {
|
2018-11-26 11:00:31 +00:00
|
|
|
auto send = crl::guard(this, [bot = _bot, chat] {
|
|
|
|
ShareBotGame(bot, chat);
|
|
|
|
});
|
2017-08-15 09:35:19 +00:00
|
|
|
auto confirmText = [chat] {
|
|
|
|
if (chat->isUser()) {
|
|
|
|
return lng_bot_sure_share_game(lt_user, App::peerName(chat));
|
|
|
|
}
|
|
|
|
return lng_bot_sure_share_game_group(lt_group, chat->name);
|
2017-12-18 12:40:15 +00:00
|
|
|
}();
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(
|
2017-12-18 12:40:15 +00:00
|
|
|
Box<ConfirmBox>(confirmText, std::move(send)),
|
2017-09-15 17:34:41 +00:00
|
|
|
LayerOption::KeepOther);
|
2017-08-15 09:35:19 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void AddBotToGroupBoxController::addBotToGroup(not_null<PeerData*> chat) {
|
2018-12-28 11:42:58 +00:00
|
|
|
if (const auto megagroup = chat->asMegagroup()) {
|
2017-08-15 09:35:19 +00:00
|
|
|
if (!megagroup->canAddMembers()) {
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(
|
|
|
|
Box<InformBox>(lang(lng_error_cant_add_member)),
|
|
|
|
LayerOption::KeepOther);
|
2017-08-15 09:35:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-11-26 11:00:31 +00:00
|
|
|
auto send = crl::guard(this, [bot = _bot, chat] {
|
|
|
|
AddBotToGroup(bot, chat);
|
|
|
|
});
|
2017-08-15 09:35:19 +00:00
|
|
|
auto confirmText = lng_bot_sure_invite(lt_group, chat->name);
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(
|
|
|
|
Box<ConfirmBox>(confirmText, send),
|
|
|
|
LayerOption::KeepOther);
|
2017-08-15 09:35:19 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
auto AddBotToGroupBoxController::createRow(not_null<History*> history)
|
|
|
|
-> std::unique_ptr<ChatsListBoxController::Row> {
|
2017-08-15 09:35:19 +00:00
|
|
|
if (!needToCreateRow(history->peer)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return std::make_unique<Row>(history);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
bool AddBotToGroupBoxController::needToCreateRow(
|
|
|
|
not_null<PeerData*> peer) const {
|
2017-08-15 09:35:19 +00:00
|
|
|
if (sharingBotGame()) {
|
2019-01-05 10:50:04 +00:00
|
|
|
if (!peer->canWrite()
|
|
|
|
|| peer->amRestricted(ChatRestriction::f_send_games)) {
|
2017-08-15 09:35:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-01-05 10:50:04 +00:00
|
|
|
if (const auto chat = peer->asChat()) {
|
|
|
|
return chat->canAddMembers();
|
|
|
|
} else if (const auto group = peer->asMegagroup()) {
|
2017-08-15 09:35:19 +00:00
|
|
|
return group->canAddMembers();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
bool AddBotToGroupBoxController::SharingBotGame(not_null<UserData*> bot) {
|
2017-08-15 09:35:19 +00:00
|
|
|
auto &info = bot->botInfo;
|
|
|
|
return (info && !info->shareGameShortName.isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AddBotToGroupBoxController::sharingBotGame() const {
|
|
|
|
return SharingBotGame(_bot);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AddBotToGroupBoxController::emptyBoxText() const {
|
2019-04-18 08:28:43 +00:00
|
|
|
return lang(Auth().data().chatsListLoaded()
|
2017-08-15 09:35:19 +00:00
|
|
|
? (sharingBotGame() ? lng_bot_no_chats : lng_bot_no_groups)
|
|
|
|
: lng_contacts_loading);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AddBotToGroupBoxController::noResultsText() const {
|
2019-04-18 08:28:43 +00:00
|
|
|
return lang(Auth().data().chatsListLoaded()
|
2017-08-15 09:35:19 +00:00
|
|
|
? (sharingBotGame() ? lng_bot_chats_not_found : lng_bot_groups_not_found)
|
|
|
|
: lng_contacts_loading);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddBotToGroupBoxController::updateLabels() {
|
|
|
|
setSearchNoResultsText(noResultsText());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddBotToGroupBoxController::prepareViewHook() {
|
|
|
|
delegate()->peerListSetTitle(langFactory(sharingBotGame()
|
|
|
|
? lng_bot_choose_chat
|
|
|
|
: lng_bot_choose_group));
|
|
|
|
updateLabels();
|
2019-04-18 08:28:43 +00:00
|
|
|
Auth().data().chatsListLoadedEvents(
|
|
|
|
) | rpl::filter([=](Data::Folder *folder) {
|
|
|
|
return !folder;
|
|
|
|
}) | rpl::start_with_next([=] {
|
|
|
|
updateLabels();
|
|
|
|
}, lifetime());
|
2017-08-15 09:35:19 +00:00
|
|
|
}
|
2017-11-07 13:13:41 +00:00
|
|
|
|
|
|
|
ChooseRecipientBoxController::ChooseRecipientBoxController(
|
2018-06-04 15:35:11 +00:00
|
|
|
FnMut<void(not_null<PeerData*>)> callback)
|
2017-11-07 13:13:41 +00:00
|
|
|
: _callback(std::move(callback)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChooseRecipientBoxController::prepareViewHook() {
|
|
|
|
delegate()->peerListSetTitle(langFactory(lng_forward_choose));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChooseRecipientBoxController::rowClicked(not_null<PeerListRow*> row) {
|
2018-11-30 05:45:22 +00:00
|
|
|
auto weak = base::make_weak(this);
|
|
|
|
auto callback = std::move(_callback);
|
|
|
|
callback(row->peer());
|
|
|
|
if (weak) {
|
|
|
|
_callback = std::move(callback);
|
|
|
|
}
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto ChooseRecipientBoxController::createRow(
|
|
|
|
not_null<History*> history) -> std::unique_ptr<Row> {
|
|
|
|
return std::make_unique<Row>(history);
|
|
|
|
}
|