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