2017-09-26 17:57:01 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#include "info/profile/info_profile_members_controllers.h"
|
|
|
|
|
|
|
|
#include "profile/profile_channel_controllers.h"
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "auth_session.h"
|
|
|
|
#include "observer_peer.h"
|
2017-10-03 13:05:58 +00:00
|
|
|
#include "window/window_controller.h"
|
2017-09-26 17:57:01 +00:00
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
namespace Profile {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ChatMembersController
|
|
|
|
: public PeerListController
|
|
|
|
, private base::Subscriber {
|
|
|
|
public:
|
2017-10-03 13:05:58 +00:00
|
|
|
ChatMembersController(
|
|
|
|
not_null<Window::Controller*> window,
|
|
|
|
not_null<ChatData*> chat);
|
2017-09-26 17:57:01 +00:00
|
|
|
|
|
|
|
void prepare() override;
|
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void rebuildRows();
|
|
|
|
std::unique_ptr<PeerListRow> createRow(not_null<UserData*> user);
|
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
not_null<Window::Controller*> _window;
|
2017-09-26 17:57:01 +00:00
|
|
|
not_null<ChatData*> _chat;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
ChatMembersController::ChatMembersController(
|
|
|
|
not_null<Window::Controller*> window,
|
|
|
|
not_null<ChatData*> chat)
|
2017-09-26 17:57:01 +00:00
|
|
|
: PeerListController()
|
2017-10-03 13:05:58 +00:00
|
|
|
, _window(window)
|
2017-09-26 17:57:01 +00:00
|
|
|
, _chat(chat) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatMembersController::prepare() {
|
|
|
|
setSearchNoResultsText(lang(lng_blocked_list_not_found));
|
|
|
|
delegate()->peerListSetSearchMode(PeerListSearchMode::Enabled);
|
|
|
|
delegate()->peerListSetTitle(langFactory(lng_channel_admins));
|
|
|
|
|
|
|
|
rebuildRows();
|
|
|
|
if (!delegate()->peerListFullRowsCount()) {
|
|
|
|
Auth().api().requestFullPeer(_chat);
|
|
|
|
}
|
2017-09-26 18:44:58 +00:00
|
|
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
2017-09-26 17:57:01 +00:00
|
|
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(
|
2017-09-26 18:44:58 +00:00
|
|
|
UpdateFlag::MembersChanged | UpdateFlag::UserOnlineChanged,
|
2017-09-26 17:57:01 +00:00
|
|
|
[this](const Notify::PeerUpdate &update) {
|
2017-09-26 18:44:58 +00:00
|
|
|
if (update.flags & UpdateFlag::MembersChanged) {
|
|
|
|
if (update.peer == _chat) {
|
|
|
|
rebuildRows();
|
|
|
|
}
|
|
|
|
} else if (update.flags & UpdateFlag::UserOnlineChanged) {
|
|
|
|
auto now = unixtime();
|
|
|
|
delegate()->peerListSortRows([now](const PeerListRow &a, const PeerListRow &b) {
|
|
|
|
return App::onlineForSort(a.peer()->asUser(), now) >
|
|
|
|
App::onlineForSort(b.peer()->asUser(), now);
|
|
|
|
});
|
2017-09-26 17:57:01 +00:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatMembersController::rebuildRows() {
|
|
|
|
if (_chat->participants.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<not_null<UserData*>> users;
|
|
|
|
auto &participants = _chat->participants;
|
|
|
|
for (auto i = participants.cbegin(), e = participants.cend();
|
|
|
|
i != e;
|
|
|
|
++i) {
|
|
|
|
users.push_back(i.key());
|
|
|
|
}
|
|
|
|
auto now = unixtime();
|
|
|
|
base::sort(users, [now](auto a, auto b) {
|
|
|
|
return App::onlineForSort(a, now)
|
|
|
|
> App::onlineForSort(b, now);
|
|
|
|
});
|
|
|
|
base::for_each(users, [this](not_null<UserData*> user) {
|
|
|
|
if (auto row = createRow(user)) {
|
|
|
|
delegate()->peerListAppendRow(std::move(row));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
delegate()->peerListRefreshRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<PeerListRow> ChatMembersController::createRow(not_null<UserData*> user) {
|
|
|
|
return std::make_unique<PeerListRow>(user);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatMembersController::rowClicked(not_null<PeerListRow*> row) {
|
2017-10-03 13:05:58 +00:00
|
|
|
_window->showPeerInfo(row->peer());
|
2017-09-26 17:57:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
std::unique_ptr<PeerListController> CreateMembersController(
|
2017-10-03 13:05:58 +00:00
|
|
|
not_null<Window::Controller*> window,
|
2017-09-26 17:57:01 +00:00
|
|
|
not_null<PeerData*> peer) {
|
|
|
|
if (auto chat = peer->asChat()) {
|
2017-10-03 13:05:58 +00:00
|
|
|
return std::make_unique<ChatMembersController>(
|
|
|
|
window,
|
|
|
|
chat);
|
2017-09-26 17:57:01 +00:00
|
|
|
} else if (auto channel = peer->asChannel()) {
|
|
|
|
using ChannelMembersController
|
|
|
|
= ::Profile::ParticipantsBoxController;
|
|
|
|
return std::make_unique<ChannelMembersController>(
|
2017-10-03 13:05:58 +00:00
|
|
|
window,
|
2017-09-26 17:57:01 +00:00
|
|
|
channel,
|
|
|
|
ChannelMembersController::Role::Profile);
|
|
|
|
}
|
|
|
|
Unexpected("Peer type in CreateMembersController()");
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Profile
|
|
|
|
} // namespace Info
|