mirror of https://github.com/procxx/kepka.git
Remove std::any dependency (for now).
Xcode 9 still doesn't have std::any :(
This commit is contained in:
parent
b51f865c54
commit
9a988d89e3
|
@ -260,6 +260,15 @@ void PeerListController::setSearchNoResultsText(const QString &text) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<PeerListState> PeerListController::saveState() {
|
||||||
|
return delegate()->peerListSaveState();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PeerListController::restoreState(
|
||||||
|
std::unique_ptr<PeerListState> state) {
|
||||||
|
delegate()->peerListRestoreState(std::move(state));
|
||||||
|
}
|
||||||
|
|
||||||
void PeerListBox::addSelectItem(not_null<PeerData*> peer, PeerListRow::SetStyle style) {
|
void PeerListBox::addSelectItem(not_null<PeerData*> peer, PeerListRow::SetStyle style) {
|
||||||
if (!_select) {
|
if (!_select) {
|
||||||
createMultiSelect();
|
createMultiSelect();
|
||||||
|
@ -1230,7 +1239,8 @@ void PeerListContent::searchQueryChanged(QString query) {
|
||||||
|
|
||||||
std::unique_ptr<PeerListState> PeerListContent::saveState() const {
|
std::unique_ptr<PeerListState> PeerListContent::saveState() const {
|
||||||
auto result = std::make_unique<PeerListState>();
|
auto result = std::make_unique<PeerListState>();
|
||||||
result->controllerState = EmptyControllerState();
|
result->controllerState
|
||||||
|
= std::make_unique<PeerListController::SavedStateBase>();
|
||||||
result->list.reserve(_rows.size());
|
result->list.reserve(_rows.size());
|
||||||
for (auto &row : _rows) {
|
for (auto &row : _rows) {
|
||||||
result->list.push_back(row->peer());
|
result->list.push_back(row->peer());
|
||||||
|
@ -1245,7 +1255,7 @@ std::unique_ptr<PeerListState> PeerListContent::saveState() const {
|
||||||
|
|
||||||
void PeerListContent::restoreState(
|
void PeerListContent::restoreState(
|
||||||
std::unique_ptr<PeerListState> state) {
|
std::unique_ptr<PeerListState> state) {
|
||||||
if (!state || !state->controllerState.has_value()) {
|
if (!state || !state->controllerState) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -215,16 +215,7 @@ enum class PeerListSearchMode {
|
||||||
Enabled,
|
Enabled,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PeerListState {
|
struct PeerListState;
|
||||||
PeerListState() = default;
|
|
||||||
PeerListState(PeerListState &&other) = delete;
|
|
||||||
PeerListState &operator=(PeerListState &&other) = delete;
|
|
||||||
|
|
||||||
base::unique_any controllerState;
|
|
||||||
std::vector<not_null<PeerData*>> list;
|
|
||||||
std::vector<not_null<PeerData*>> filterResults;
|
|
||||||
QString searchQuery;
|
|
||||||
};
|
|
||||||
|
|
||||||
class PeerListDelegate {
|
class PeerListDelegate {
|
||||||
public:
|
public:
|
||||||
|
@ -284,6 +275,10 @@ public:
|
||||||
|
|
||||||
class PeerListSearchController {
|
class PeerListSearchController {
|
||||||
public:
|
public:
|
||||||
|
struct SavedStateBase {
|
||||||
|
virtual ~SavedStateBase() = default;
|
||||||
|
};
|
||||||
|
|
||||||
virtual void searchQuery(const QString &query) = 0;
|
virtual void searchQuery(const QString &query) = 0;
|
||||||
virtual bool isLoading() = 0;
|
virtual bool isLoading() = 0;
|
||||||
virtual bool loadMoreRows() = 0;
|
virtual bool loadMoreRows() = 0;
|
||||||
|
@ -293,10 +288,11 @@ public:
|
||||||
_delegate = delegate;
|
_delegate = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual base::unique_any saveState() {
|
virtual std::unique_ptr<SavedStateBase> saveState() {
|
||||||
return {};
|
return nullptr;
|
||||||
}
|
}
|
||||||
virtual void restoreState(base::unique_any &&state) {
|
virtual void restoreState(
|
||||||
|
std::unique_ptr<SavedStateBase> state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -311,6 +307,10 @@ private:
|
||||||
|
|
||||||
class PeerListController : public PeerListSearchDelegate {
|
class PeerListController : public PeerListSearchDelegate {
|
||||||
public:
|
public:
|
||||||
|
struct SavedStateBase {
|
||||||
|
virtual ~SavedStateBase() = default;
|
||||||
|
};
|
||||||
|
|
||||||
// Search works only with RowId == peer->id.
|
// Search works only with RowId == peer->id.
|
||||||
PeerListController(std::unique_ptr<PeerListSearchController> searchController = nullptr);
|
PeerListController(std::unique_ptr<PeerListSearchController> searchController = nullptr);
|
||||||
|
|
||||||
|
@ -343,13 +343,9 @@ public:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::unique_ptr<PeerListState> saveState() {
|
virtual std::unique_ptr<PeerListState> saveState();
|
||||||
return delegate()->peerListSaveState();
|
|
||||||
}
|
|
||||||
virtual void restoreState(
|
virtual void restoreState(
|
||||||
std::unique_ptr<PeerListState> state) {
|
std::unique_ptr<PeerListState> state);
|
||||||
delegate()->peerListRestoreState(std::move(state));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isRowSelected(not_null<PeerData*> peer) {
|
bool isRowSelected(not_null<PeerData*> peer) {
|
||||||
return delegate()->peerListIsRowSelected(peer);
|
return delegate()->peerListIsRowSelected(peer);
|
||||||
|
@ -401,6 +397,17 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct PeerListState {
|
||||||
|
PeerListState() = default;
|
||||||
|
PeerListState(PeerListState &&other) = delete;
|
||||||
|
PeerListState &operator=(PeerListState &&other) = delete;
|
||||||
|
|
||||||
|
std::unique_ptr<PeerListController::SavedStateBase> controllerState;
|
||||||
|
std::vector<not_null<PeerData*>> list;
|
||||||
|
std::vector<not_null<PeerData*>> filterResults;
|
||||||
|
QString searchQuery;
|
||||||
|
};
|
||||||
|
|
||||||
class PeerListContent
|
class PeerListContent
|
||||||
: public Ui::RpWidget
|
: public Ui::RpWidget
|
||||||
, private base::Subscriber {
|
, private base::Subscriber {
|
||||||
|
@ -517,9 +524,6 @@ private:
|
||||||
Selected old;
|
Selected old;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EmptyControllerState {
|
|
||||||
};
|
|
||||||
|
|
||||||
void setSelected(Selected selected);
|
void setSelected(Selected selected);
|
||||||
void setPressed(Selected pressed);
|
void setPressed(Selected pressed);
|
||||||
void setContexted(Selected contexted);
|
void setContexted(Selected contexted);
|
||||||
|
|
|
@ -63,6 +63,9 @@ public:
|
||||||
void restoreState(std::unique_ptr<PeerListState> state) override;
|
void restoreState(std::unique_ptr<PeerListState> state) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct SavedState : SavedStateBase {
|
||||||
|
rpl::lifetime lifetime;
|
||||||
|
};
|
||||||
void rebuildRows();
|
void rebuildRows();
|
||||||
void refreshOnlineCount();
|
void refreshOnlineCount();
|
||||||
std::unique_ptr<PeerListRow> createRow(not_null<UserData*> user);
|
std::unique_ptr<PeerListRow> createRow(not_null<UserData*> user);
|
||||||
|
@ -133,13 +136,13 @@ void ChatMembersController::sortByOnline() {
|
||||||
|
|
||||||
std::unique_ptr<PeerListState> ChatMembersController::saveState() {
|
std::unique_ptr<PeerListState> ChatMembersController::saveState() {
|
||||||
auto result = PeerListController::saveState();
|
auto result = PeerListController::saveState();
|
||||||
auto lifetime = rpl::lifetime();
|
auto my = std::make_unique<SavedState>();
|
||||||
using Flag = Notify::PeerUpdate::Flag;
|
using Flag = Notify::PeerUpdate::Flag;
|
||||||
Notify::PeerUpdateViewer(_chat, Flag::MembersChanged)
|
Notify::PeerUpdateViewer(_chat, Flag::MembersChanged)
|
||||||
| rpl::start_with_next([state = result.get()](auto update) {
|
| rpl::start_with_next([state = result.get()](auto update) {
|
||||||
state->controllerState = base::unique_any{};
|
state->controllerState = nullptr;
|
||||||
}, lifetime);
|
}, my->lifetime);
|
||||||
result->controllerState = std::move(lifetime);
|
result->controllerState = std::move(my);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -251,16 +251,16 @@ std::unique_ptr<PeerListState> ParticipantsBoxController::saveState() {
|
||||||
|
|
||||||
auto result = PeerListController::saveState();
|
auto result = PeerListController::saveState();
|
||||||
|
|
||||||
auto my = SavedState();
|
auto my = std::make_unique<SavedState>();
|
||||||
my.additional = std::move(_additional);
|
my->additional = std::move(_additional);
|
||||||
my.offset = _offset;
|
my->offset = _offset;
|
||||||
my.allLoaded = _allLoaded;
|
my->allLoaded = _allLoaded;
|
||||||
if (auto requestId = base::take(_loadRequestId)) {
|
if (auto requestId = base::take(_loadRequestId)) {
|
||||||
request(requestId).cancel();
|
request(requestId).cancel();
|
||||||
my.wasLoading = true;
|
my->wasLoading = true;
|
||||||
}
|
}
|
||||||
if (auto search = searchController()) {
|
if (auto search = searchController()) {
|
||||||
my.searchState = search->saveState();
|
my->searchState = search->saveState();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto weak = result.get();
|
auto weak = result.get();
|
||||||
|
@ -278,7 +278,7 @@ std::unique_ptr<PeerListState> ParticipantsBoxController::saveState() {
|
||||||
base::stable_partition(weak->list, [user](not_null<PeerData*> peer) {
|
base::stable_partition(weak->list, [user](not_null<PeerData*> peer) {
|
||||||
return (peer == user);
|
return (peer == user);
|
||||||
});
|
});
|
||||||
}, my.lifetime);
|
}, my->lifetime);
|
||||||
Auth().data().megagroupParticipantRemoved(_channel)
|
Auth().data().megagroupParticipantRemoved(_channel)
|
||||||
| rpl::start_with_next([weak](not_null<UserData*> user) {
|
| rpl::start_with_next([weak](not_null<UserData*> user) {
|
||||||
weak->list.erase(std::remove(
|
weak->list.erase(std::remove(
|
||||||
|
@ -289,7 +289,7 @@ std::unique_ptr<PeerListState> ParticipantsBoxController::saveState() {
|
||||||
weak->filterResults.begin(),
|
weak->filterResults.begin(),
|
||||||
weak->filterResults.end(),
|
weak->filterResults.end(),
|
||||||
user), weak->filterResults.end());
|
user), weak->filterResults.end());
|
||||||
}, my.lifetime);
|
}, my->lifetime);
|
||||||
|
|
||||||
result->controllerState = std::move(my);
|
result->controllerState = std::move(my);
|
||||||
return result;
|
return result;
|
||||||
|
@ -297,8 +297,10 @@ std::unique_ptr<PeerListState> ParticipantsBoxController::saveState() {
|
||||||
|
|
||||||
void ParticipantsBoxController::restoreState(
|
void ParticipantsBoxController::restoreState(
|
||||||
std::unique_ptr<PeerListState> state) {
|
std::unique_ptr<PeerListState> state) {
|
||||||
auto typeErasedState = &state->controllerState;
|
auto typeErasedState = state
|
||||||
if (auto my = base::any_cast<SavedState>(typeErasedState)) {
|
? state->controllerState.get()
|
||||||
|
: nullptr;
|
||||||
|
if (auto my = dynamic_cast<SavedState*>(typeErasedState)) {
|
||||||
if (auto requestId = base::take(_loadRequestId)) {
|
if (auto requestId = base::take(_loadRequestId)) {
|
||||||
request(requestId).cancel();
|
request(requestId).cancel();
|
||||||
}
|
}
|
||||||
|
@ -851,21 +853,22 @@ void ParticipantsBoxSearchController::searchQuery(const QString &query) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
base::unique_any ParticipantsBoxSearchController::saveState() {
|
auto ParticipantsBoxSearchController::saveState()
|
||||||
auto result = SavedState();
|
-> std::unique_ptr<SavedStateBase> {
|
||||||
result.query = _query;
|
auto result = std::make_unique<SavedState>();
|
||||||
result.offset = _offset;
|
result->query = _query;
|
||||||
result.allLoaded = _allLoaded;
|
result->offset = _offset;
|
||||||
|
result->allLoaded = _allLoaded;
|
||||||
if (auto requestId = base::take(_requestId)) {
|
if (auto requestId = base::take(_requestId)) {
|
||||||
request(requestId).cancel();
|
request(requestId).cancel();
|
||||||
result.wasLoading = true;
|
result->wasLoading = true;
|
||||||
}
|
}
|
||||||
return result;
|
return std::move(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticipantsBoxSearchController::restoreState(
|
void ParticipantsBoxSearchController::restoreState(
|
||||||
base::unique_any &&state) {
|
std::unique_ptr<SavedStateBase> state) {
|
||||||
if (auto my = base::any_cast<SavedState>(&state)) {
|
if (auto my = dynamic_cast<SavedState*>(state.get())) {
|
||||||
if (auto requestId = base::take(_requestId)) {
|
if (auto requestId = base::take(_requestId)) {
|
||||||
request(requestId).cancel();
|
request(requestId).cancel();
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,8 +102,8 @@ protected:
|
||||||
virtual std::unique_ptr<PeerListRow> createRow(not_null<UserData*> user) const;
|
virtual std::unique_ptr<PeerListRow> createRow(not_null<UserData*> user) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct SavedState {
|
struct SavedState : SavedStateBase {
|
||||||
base::unique_any searchState;
|
std::unique_ptr<PeerListSearchController::SavedStateBase> searchState;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
bool allLoaded = false;
|
bool allLoaded = false;
|
||||||
bool wasLoading = false;
|
bool wasLoading = false;
|
||||||
|
@ -150,7 +150,9 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
// Members, banned and restricted users server side search.
|
// Members, banned and restricted users server side search.
|
||||||
class ParticipantsBoxSearchController : public PeerListSearchController, private MTP::Sender {
|
class ParticipantsBoxSearchController
|
||||||
|
: public PeerListSearchController
|
||||||
|
, private MTP::Sender {
|
||||||
public:
|
public:
|
||||||
using Role = ParticipantsBoxController::Role;
|
using Role = ParticipantsBoxController::Role;
|
||||||
using Additional = ParticipantsBoxController::Additional;
|
using Additional = ParticipantsBoxController::Additional;
|
||||||
|
@ -161,11 +163,11 @@ public:
|
||||||
bool isLoading() override;
|
bool isLoading() override;
|
||||||
bool loadMoreRows() override;
|
bool loadMoreRows() override;
|
||||||
|
|
||||||
base::unique_any saveState() override;
|
std::unique_ptr<SavedStateBase> saveState() override;
|
||||||
void restoreState(base::unique_any &&state) override;
|
void restoreState(std::unique_ptr<SavedStateBase> state) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct SavedState {
|
struct SavedState : SavedStateBase {
|
||||||
QString query;
|
QString query;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
bool allLoaded = false;
|
bool allLoaded = false;
|
||||||
|
|
|
@ -84,7 +84,6 @@ namespace func = base::functors;
|
||||||
|
|
||||||
#include "base/flat_set.h"
|
#include "base/flat_set.h"
|
||||||
#include "base/flat_map.h"
|
#include "base/flat_map.h"
|
||||||
#include "base/unique_any.h"
|
|
||||||
|
|
||||||
#include "core/basic_types.h"
|
#include "core/basic_types.h"
|
||||||
#include "logs.h"
|
#include "logs.h"
|
||||||
|
|
Loading…
Reference in New Issue