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

Support auto-migrate to supergroups.

This commit is contained in:
John Preston
2019-01-13 17:28:05 +04:00
parent b236844c94
commit 3c44bdb6b7
23 changed files with 505 additions and 285 deletions

View File

@@ -28,25 +28,20 @@ void ShowSearchFromBox(
peer,
callback = std::move(callback)
]() -> std::unique_ptr<PeerListController> {
if (peer) {
if (auto chat = peer->asChat()) {
return std::make_unique<Dialogs::ChatSearchFromController>(
navigation,
chat,
std::move(callback));
} else if (auto group = peer->asMegagroup()) {
return std::make_unique<Dialogs::ChannelSearchFromController>(
navigation,
group,
std::move(callback));
}
if (peer && (peer->isChat() || peer->isMegagroup())) {
return std::make_unique<Dialogs::SearchFromController>(
navigation,
peer,
std::move(callback));
}
return nullptr;
};
if (auto controller = createController()) {
auto subscription = std::make_shared<rpl::lifetime>();
auto box = Ui::show(Box<PeerListBox>(std::move(controller), [subscription](not_null<PeerListBox*> box) {
box->addButton(langFactory(lng_cancel), [box, subscription] { box->closeBox(); });
box->addButton(langFactory(lng_cancel), [box, subscription] {
box->closeBox();
});
}), LayerOption::KeepOther);
box->boxClosing() | rpl::start_with_next(
std::move(closedCallback),
@@ -54,106 +49,32 @@ void ShowSearchFromBox(
}
}
ChatSearchFromController::ChatSearchFromController(
SearchFromController::SearchFromController(
not_null<Window::Navigation*> navigation,
not_null<ChatData*> chat,
Fn<void(not_null<UserData*>)> callback)
: PeerListController()
, _chat(chat)
, _callback(std::move(callback)) {
}
void ChatSearchFromController::prepare() {
setSearchNoResultsText(lang(lng_blocked_list_not_found));
delegate()->peerListSetSearchMode(PeerListSearchMode::Enabled);
delegate()->peerListSetTitle(langFactory(lng_search_messages_from));
rebuildRows();
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::MembersChanged, [this](const Notify::PeerUpdate &update) {
if (update.peer == _chat) {
rebuildRows();
}
}));
}
void ChatSearchFromController::rowClicked(not_null<PeerListRow*> row) {
Expects(row->peer()->isUser());
const auto onstack = _callback;
onstack(row->peer()->asUser());
}
void ChatSearchFromController::rebuildRows() {
auto ms = getms();
auto wasEmpty = !delegate()->peerListFullRowsCount();
auto now = unixtime();
const auto byOnline = [&](not_null<UserData*> user) {
return Data::SortByOnlineValue(user, now);
};
auto ordered = QMultiMap<TimeId, not_null<UserData*>>();
if (_chat->noParticipantInfo()) {
Auth().api().requestFullPeer(_chat);
} else if (!_chat->participants.empty()) {
for (const auto user : _chat->participants) {
ordered.insertMulti(byOnline(user), user);
}
}
for_const (auto user, _chat->lastAuthors) {
if (user->isInaccessible()) continue;
appendRow(user);
if (!ordered.isEmpty()) {
ordered.remove(byOnline(user), user);
}
}
if (!ordered.isEmpty()) {
for (auto i = ordered.cend(), b = ordered.cbegin(); i != b;) {
appendRow(*(--i));
}
}
checkForEmptyRows();
delegate()->peerListRefreshRows();
}
void ChatSearchFromController::checkForEmptyRows() {
if (delegate()->peerListFullRowsCount()) {
setDescriptionText(QString());
} else {
setDescriptionText(lang(lng_contacts_loading));
}
}
void ChatSearchFromController::appendRow(not_null<UserData*> user) {
if (!delegate()->peerListFindRow(user->id)) {
delegate()->peerListAppendRow(std::make_unique<PeerListRow>(user));
}
}
ChannelSearchFromController::ChannelSearchFromController(
not_null<Window::Navigation*> navigation,
not_null<ChannelData*> channel,
not_null<PeerData*> peer,
Fn<void(not_null<UserData*>)> callback)
: ParticipantsBoxController(
navigation,
channel,
peer,
ParticipantsBoxController::Role::Members)
, _callback(std::move(callback)) {
}
void ChannelSearchFromController::prepare() {
void SearchFromController::prepare() {
ParticipantsBoxController::prepare();
delegate()->peerListSetTitle(langFactory(lng_search_messages_from));
}
void ChannelSearchFromController::rowClicked(not_null<PeerListRow*> row) {
void SearchFromController::rowClicked(not_null<PeerListRow*> row) {
Expects(row->peer()->isUser());
const auto onstack = _callback;
onstack(row->peer()->asUser());
if (const auto onstack = base::duplicate(_callback)) {
onstack(row->peer()->asUser());
}
}
std::unique_ptr<PeerListRow> ChannelSearchFromController::createRow(not_null<UserData*> user) const {
std::unique_ptr<PeerListRow> SearchFromController::createRow(
not_null<UserData*> user) const {
return std::make_unique<PeerListRow>(user);
}

View File

@@ -18,31 +18,11 @@ void ShowSearchFromBox(
Fn<void(not_null<UserData*>)> callback,
Fn<void()> closedCallback);
class ChatSearchFromController : public PeerListController, protected base::Subscriber {
class SearchFromController : public ParticipantsBoxController {
public:
ChatSearchFromController(
SearchFromController(
not_null<Window::Navigation*> navigation,
not_null<ChatData*> chat,
Fn<void(not_null<UserData*>)> callback);
void prepare() override;
void rowClicked(not_null<PeerListRow*> row) override;
private:
void rebuildRows();
void checkForEmptyRows();
void appendRow(not_null<UserData*> user);
not_null<ChatData*> _chat;
Fn<void(not_null<UserData*>)> _callback;
};
class ChannelSearchFromController : public ParticipantsBoxController {
public:
ChannelSearchFromController(
not_null<Window::Navigation*> navigation,
not_null<ChannelData*> channel,
not_null<PeerData*> peer,
Fn<void(not_null<UserData*>)> callback);
void prepare() override;