mirror of https://github.com/procxx/kepka.git
Improve sorting by online in info profile.
This commit is contained in:
parent
292e57ffc7
commit
2c75b4836d
|
@ -399,6 +399,7 @@ public:
|
||||||
callback(searchEntity.second.begin(), searchEntity.second.end());
|
callback(searchEntity.second.begin(), searchEntity.second.end());
|
||||||
}
|
}
|
||||||
refreshIndices();
|
refreshIndices();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<Ui::ScrollToRequest> scrollToRequests() const {
|
rpl::producer<Ui::ScrollToRequest> scrollToRequests() const {
|
||||||
|
|
|
@ -61,11 +61,20 @@ void ChatMembersController::prepare() {
|
||||||
if (!delegate()->peerListFullRowsCount()) {
|
if (!delegate()->peerListFullRowsCount()) {
|
||||||
Auth().api().requestFullPeer(_chat);
|
Auth().api().requestFullPeer(_chat);
|
||||||
}
|
}
|
||||||
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
||||||
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(
|
||||||
Notify::PeerUpdate::Flag::MembersChanged,
|
UpdateFlag::MembersChanged | UpdateFlag::UserOnlineChanged,
|
||||||
[this](const Notify::PeerUpdate &update) {
|
[this](const Notify::PeerUpdate &update) {
|
||||||
if (update.peer == _chat) {
|
if (update.flags & UpdateFlag::MembersChanged) {
|
||||||
rebuildRows();
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
|
#include "observer_peer.h"
|
||||||
#include "dialogs/dialogs_indexed_list.h"
|
#include "dialogs/dialogs_indexed_list.h"
|
||||||
|
|
||||||
namespace Profile {
|
namespace Profile {
|
||||||
|
@ -35,16 +36,56 @@ namespace {
|
||||||
|
|
||||||
constexpr auto kParticipantsFirstPageCount = 16;
|
constexpr auto kParticipantsFirstPageCount = 16;
|
||||||
constexpr auto kParticipantsPerPage = 200;
|
constexpr auto kParticipantsPerPage = 200;
|
||||||
|
constexpr auto kSortByOnlineDelay = TimeMs(1000);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ParticipantsBoxController::ParticipantsBoxController(not_null<ChannelData*> channel, Role role)
|
ParticipantsBoxController::ParticipantsBoxController(
|
||||||
|
not_null<ChannelData*> channel,
|
||||||
|
Role role)
|
||||||
: PeerListController(CreateSearchController(channel, role, &_additional))
|
: PeerListController(CreateSearchController(channel, role, &_additional))
|
||||||
, _channel(channel)
|
, _channel(channel)
|
||||||
, _role(role) {
|
, _role(role) {
|
||||||
if (_channel->mgInfo) {
|
if (_channel->mgInfo) {
|
||||||
_additional.creator = _channel->mgInfo->creator;
|
_additional.creator = _channel->mgInfo->creator;
|
||||||
}
|
}
|
||||||
|
if (_role == Role::Profile) {
|
||||||
|
setupSortByOnline();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticipantsBoxController::setupSortByOnline() {
|
||||||
|
_sortByOnlineTimer.setCallback([this] { sortByOnline(); });
|
||||||
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
||||||
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(
|
||||||
|
UpdateFlag::UserOnlineChanged,
|
||||||
|
[this](const Notify::PeerUpdate &update) {
|
||||||
|
if (auto row = delegate()->peerListFindRow(
|
||||||
|
update.peer->id)) {
|
||||||
|
row->refreshStatus();
|
||||||
|
sortByOnlineDelayed();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticipantsBoxController::sortByOnlineDelayed() {
|
||||||
|
if (!_sortByOnlineTimer.isActive()) {
|
||||||
|
_sortByOnlineTimer.callOnce(kSortByOnlineDelay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticipantsBoxController::sortByOnline() {
|
||||||
|
if (_role != Role::Profile
|
||||||
|
|| _channel->membersCount() > Global::ChatSizeMax()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<PeerListSearchController>
|
std::unique_ptr<PeerListSearchController>
|
||||||
|
@ -278,6 +319,7 @@ void ParticipantsBoxController::loadMoreRows() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sortByOnline();
|
||||||
delegate()->peerListRefreshRows();
|
delegate()->peerListRefreshRows();
|
||||||
}).fail([this](const RPCError &error) {
|
}).fail([this](const RPCError &error) {
|
||||||
_loadRequestId = 0;
|
_loadRequestId = 0;
|
||||||
|
@ -327,6 +369,7 @@ bool ParticipantsBoxController::feedMegagroupLastParticipants() {
|
||||||
appendRow(user);
|
appendRow(user);
|
||||||
++_offset;
|
++_offset;
|
||||||
}
|
}
|
||||||
|
sortByOnline();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
|
|
||||||
#include "boxes/peer_list_box.h"
|
#include "boxes/peer_list_box.h"
|
||||||
#include "mtproto/sender.h"
|
#include "mtproto/sender.h"
|
||||||
|
#include "base/timer.h"
|
||||||
#include "base/weak_unique_ptr.h"
|
#include "base/weak_unique_ptr.h"
|
||||||
|
|
||||||
namespace Profile {
|
namespace Profile {
|
||||||
|
@ -76,6 +77,9 @@ protected:
|
||||||
private:
|
private:
|
||||||
static std::unique_ptr<PeerListSearchController> CreateSearchController(not_null<ChannelData*> channel, Role role, not_null<Additional*> additional);
|
static std::unique_ptr<PeerListSearchController> CreateSearchController(not_null<ChannelData*> channel, Role role, not_null<Additional*> additional);
|
||||||
|
|
||||||
|
void setupSortByOnline();
|
||||||
|
void sortByOnlineDelayed();
|
||||||
|
void sortByOnline();
|
||||||
void showAdmin(not_null<UserData*> user);
|
void showAdmin(not_null<UserData*> user);
|
||||||
void editAdminDone(not_null<UserData*> user, const MTPChannelAdminRights &rights);
|
void editAdminDone(not_null<UserData*> user, const MTPChannelAdminRights &rights);
|
||||||
void showRestricted(not_null<UserData*> user);
|
void showRestricted(not_null<UserData*> user);
|
||||||
|
@ -98,6 +102,8 @@ private:
|
||||||
QPointer<BoxContent> _editBox;
|
QPointer<BoxContent> _editBox;
|
||||||
QPointer<PeerListBox> _addBox;
|
QPointer<PeerListBox> _addBox;
|
||||||
|
|
||||||
|
base::Timer _sortByOnlineTimer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Members, banned and restricted users server side search.
|
// Members, banned and restricted users server side search.
|
||||||
|
|
Loading…
Reference in New Issue