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

Save info members list state to memento.

This commit is contained in:
John Preston
2017-10-24 20:11:35 +03:00
parent fb46c33d7f
commit b51f865c54
29 changed files with 875 additions and 220 deletions

View File

@@ -262,15 +262,15 @@ Cover *Cover::setOnlineCount(rpl::producer<int> &&count) {
void Cover::initViewers() {
using Flag = Notify::PeerUpdate::Flag;
PeerUpdateValue(_peer, Flag::PhotoChanged)
Notify::PeerUpdateValue(_peer, Flag::PhotoChanged)
| rpl::start_with_next(
[this] { this->refreshUserpicLink(); },
lifetime());
PeerUpdateValue(_peer, Flag::NameChanged)
Notify::PeerUpdateValue(_peer, Flag::NameChanged)
| rpl::start_with_next(
[this] { this->refreshNameText(); },
lifetime());
PeerUpdateValue(_peer,
Notify::PeerUpdateValue(_peer,
Flag::UserOnlineChanged | Flag::MembersChanged)
| rpl::start_with_next(
[this] { this->refreshStatusText(); },

View File

@@ -416,7 +416,9 @@ object_ptr<Ui::RpWidget> InnerWidget::setupUserActions(
result,
st::infoBlockButtonSkip));
auto text = PeerUpdateValue(user, Notify::PeerUpdate::Flag::UserIsBlocked)
auto text = Notify::PeerUpdateValue(
user,
Notify::PeerUpdate::Flag::UserIsBlocked)
| rpl::map([user]() -> rpl::producer<QString> {
switch (user->blockStatus()) {
case UserData::BlockStatus::Blocked:
@@ -507,11 +509,16 @@ void InnerWidget::visibleTopBottomUpdated(
void InnerWidget::saveState(not_null<Memento*> memento) {
memento->setInfoExpanded(_cover->toggled());
memento->setMediaExpanded(true);
if (_members) {
_members->saveState(memento);
}
}
void InnerWidget::restoreState(not_null<Memento*> memento) {
_cover->toggle(memento->infoExpanded());
if (_members) {
_members->restoreState(memento);
}
if (_infoWrap) {
_infoWrap->finishAnimating();
}

View File

@@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "info/profile/info_profile_members.h"
#include <rpl/combine.h>
#include "info/profile/info_profile_widget.h"
#include "info/profile/info_profile_values.h"
#include "info/profile/info_profile_icon.h"
#include "info/profile/info_profile_values.h"
@@ -92,6 +93,27 @@ rpl::producer<int> Members::onlineCountValue() const {
return _listController->onlineCountValue();
}
void Members::saveState(not_null<Memento*> memento) {
if (_searchShown) {
memento->setMembersSearch(_searchField->getLastText());
}
memento->setMembersState(_listController->saveState());
}
void Members::restoreState(not_null<Memento*> memento) {
_listController->restoreState(memento->membersState());
if (auto text = memento->membersSearch()) {
if (!_searchShown) {
toggleSearch(anim::type::instant);
}
_searchField->setText(*text);
_searchField->updatePlaceholder();
applySearch();
} else if (_searchShown) {
toggleSearch(anim::type::instant);
}
}
object_ptr<Ui::FlatLabel> Members::setupHeader() {
auto result = object_ptr<Ui::FlatLabel>(
_labelWrap,
@@ -265,14 +287,20 @@ void Members::showSearch() {
}
}
void Members::toggleSearch() {
void Members::toggleSearch(anim::type animated) {
_searchShown = !_searchShown;
_cancelSearch->toggleAnimated(_searchShown);
_searchShownAnimation.start(
[this] { searchAnimationCallback(); },
_searchShown ? 0. : 1.,
_searchShown ? 1. : 0.,
st::slideWrapDuration);
if (animated == anim::type::normal) {
_cancelSearch->toggleAnimated(_searchShown);
_searchShownAnimation.start(
[this] { searchAnimationCallback(); },
_searchShown ? 0. : 1.,
_searchShown ? 1. : 0.,
st::slideWrapDuration);
} else {
_cancelSearch->toggleFast(_searchShown);
_searchShownAnimation.finish();
searchAnimationCallback();
}
_search->setDisabled(_searchShown);
if (_searchShown) {
_searchField->show();

View File

@@ -42,6 +42,8 @@ enum class Wrap;
namespace Profile {
class Memento;
class Members
: public Ui::RpWidget
, private PeerListContentDelegate {
@@ -56,6 +58,9 @@ public:
return _scrollToRequests.events();
}
void saveState(not_null<Memento*> memento);
void restoreState(not_null<Memento*> memento);
int desiredHeight() const;
rpl::producer<int> onlineCountValue() const;
@@ -92,7 +97,7 @@ private:
void addMember();
void showSearch();
void toggleSearch();
void toggleSearch(anim::type animated = anim::type::normal);
void cancelSearch();
void applySearch();
void forceSearchSubmit();

View File

@@ -56,6 +56,12 @@ public:
return _onlineCount.value();
}
std::unique_ptr<PeerListRow> createRestoredRow(
not_null<PeerData*> peer) override;
std::unique_ptr<PeerListState> saveState() override;
void restoreState(std::unique_ptr<PeerListState> state) override;
private:
void rebuildRows();
void refreshOnlineCount();
@@ -125,6 +131,24 @@ void ChatMembersController::sortByOnline() {
refreshOnlineCount();
}
std::unique_ptr<PeerListState> ChatMembersController::saveState() {
auto result = PeerListController::saveState();
auto lifetime = rpl::lifetime();
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);
return result;
}
void ChatMembersController::restoreState(
std::unique_ptr<PeerListState> state) {
PeerListController::restoreState(std::move(state));
sortByOnline();
}
void ChatMembersController::rebuildRows() {
if (_chat->participants.empty()) {
while (delegate()->peerListFullRowsCount() > 0) {
@@ -173,7 +197,16 @@ void ChatMembersController::refreshOnlineCount() {
_onlineCount = left;
}
std::unique_ptr<PeerListRow> ChatMembersController::createRow(not_null<UserData*> user) {
std::unique_ptr<PeerListRow> ChatMembersController::createRestoredRow(
not_null<PeerData*> peer) {
if (auto user = peer->asUser()) {
return createRow(user);
}
return nullptr;
}
std::unique_ptr<PeerListRow> ChatMembersController::createRow(
not_null<UserData*> user) {
return std::make_unique<PeerListRow>(user);
}

View File

@@ -33,40 +33,9 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace Info {
namespace Profile {
rpl::producer<Notify::PeerUpdate> PeerUpdateViewer(
Notify::PeerUpdate::Flags flags) {
return [=](const auto &consumer) {
auto lifetime = rpl::lifetime();
lifetime.make_state<base::Subscription>(
Notify::PeerUpdated().add_subscription({ flags, [=](
const Notify::PeerUpdate &update) {
consumer.put_next_copy(update);
}}));
return lifetime;
};
}
rpl::producer<Notify::PeerUpdate> PeerUpdateViewer(
not_null<PeerData*> peer,
Notify::PeerUpdate::Flags flags) {
return PeerUpdateViewer(flags)
| rpl::filter([=](const Notify::PeerUpdate &update) {
return (update.peer == peer);
});
}
rpl::producer<Notify::PeerUpdate> PeerUpdateValue(
not_null<PeerData*> peer,
Notify::PeerUpdate::Flags flags) {
auto initial = Notify::PeerUpdate(peer);
initial.flags = flags;
return rpl::single(initial)
| then(PeerUpdateViewer(peer, flags));
}
rpl::producer<TextWithEntities> PhoneValue(
not_null<UserData*> user) {
return PeerUpdateValue(
return Notify::PeerUpdateValue(
user,
Notify::PeerUpdate::Flag::UserPhoneChanged)
| rpl::map([user] {
@@ -77,7 +46,7 @@ rpl::producer<TextWithEntities> PhoneValue(
rpl::producer<TextWithEntities> BioValue(
not_null<UserData*> user) {
return PeerUpdateValue(
return Notify::PeerUpdateValue(
user,
Notify::PeerUpdate::Flag::AboutChanged)
| rpl::map([user] { return user->about(); })
@@ -86,7 +55,7 @@ rpl::producer<TextWithEntities> BioValue(
rpl::producer<QString> PlainUsernameViewer(
not_null<PeerData*> peer) {
return PeerUpdateValue(
return Notify::PeerUpdateValue(
peer,
Notify::PeerUpdate::Flag::UsernameChanged)
| rpl::map([peer] {
@@ -108,7 +77,7 @@ rpl::producer<TextWithEntities> UsernameValue(
rpl::producer<TextWithEntities> AboutValue(
not_null<PeerData*> peer) {
if (auto channel = peer->asChannel()) {
return PeerUpdateValue(
return Notify::PeerUpdateValue(
channel,
Notify::PeerUpdate::Flag::AboutChanged)
| rpl::map([channel] { return channel->about(); })
@@ -130,7 +99,7 @@ rpl::producer<TextWithEntities> LinkValue(
rpl::producer<bool> NotificationsEnabledValue(
not_null<PeerData*> peer) {
return PeerUpdateValue(
return Notify::PeerUpdateValue(
peer,
Notify::PeerUpdate::Flag::NotificationsEnabled)
| rpl::map([peer] { return !peer->isMuted(); });
@@ -138,7 +107,7 @@ rpl::producer<bool> NotificationsEnabledValue(
rpl::producer<bool> IsContactValue(
not_null<UserData*> user) {
return PeerUpdateValue(
return Notify::PeerUpdateValue(
user,
Notify::PeerUpdate::Flag::UserIsContact)
| rpl::map([user] { return user->isContact(); });
@@ -146,7 +115,7 @@ rpl::producer<bool> IsContactValue(
rpl::producer<bool> CanShareContactValue(
not_null<UserData*> user) {
return PeerUpdateValue(
return Notify::PeerUpdateValue(
user,
Notify::PeerUpdate::Flag::UserCanShareContact)
| rpl::map([user] {
@@ -166,7 +135,7 @@ rpl::producer<bool> CanAddContactValue(
rpl::producer<int> MembersCountValue(
not_null<PeerData*> peer) {
if (auto chat = peer->asChat()) {
return PeerUpdateValue(
return Notify::PeerUpdateValue(
peer,
Notify::PeerUpdate::Flag::MembersChanged)
| rpl::map([chat] {
@@ -176,12 +145,12 @@ rpl::producer<int> MembersCountValue(
});
} else if (auto channel = peer->asChannel()) {
return rpl::combine(
PeerUpdateValue(
channel,
Notify::PeerUpdate::Flag::MembersChanged),
Data::PeerFullFlagValue(
channel,
MTPDchannelFull::Flag::f_can_view_participants))
Notify::PeerUpdateValue(
channel,
Notify::PeerUpdate::Flag::MembersChanged),
Data::PeerFullFlagValue(
channel,
MTPDchannelFull::Flag::f_can_view_participants))
| rpl::map([channel] {
auto canViewCount = channel->canViewMembers()
|| !channel->isMegagroup();
@@ -219,7 +188,7 @@ rpl::producer<int> SharedMediaCountValue(
rpl::producer<int> CommonGroupsCountValue(
not_null<UserData*> user) {
return PeerUpdateValue(
return Notify::PeerUpdateValue(
user,
Notify::PeerUpdate::Flag::UserCommonChatsChanged)
| rpl::map([user] {
@@ -230,14 +199,14 @@ rpl::producer<int> CommonGroupsCountValue(
rpl::producer<bool> CanAddMemberValue(
not_null<PeerData*> peer) {
if (auto chat = peer->asChat()) {
return PeerUpdateValue(
return Notify::PeerUpdateValue(
chat,
Notify::PeerUpdate::Flag::ChatCanEdit)
| rpl::map([chat] {
return chat->canEdit();
});
} else if (auto channel = peer->asChannel()) {
return PeerUpdateValue(
return Notify::PeerUpdateValue(
channel,
Notify::PeerUpdate::Flag::ChannelRightsChanged)
| rpl::map([channel] {

View File

@@ -45,10 +45,6 @@ inline auto ToUpperValue() {
});
}
rpl::producer<Notify::PeerUpdate> PeerUpdateValue(
not_null<PeerData*> peer,
Notify::PeerUpdate::Flags flags);
rpl::producer<TextWithEntities> PhoneValue(
not_null<UserData*> user);
rpl::producer<TextWithEntities> BioValue(

View File

@@ -22,6 +22,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include <rpl/producer.h>
#include "info/info_content_widget.h"
#include "boxes/peer_list_box.h"
namespace Info {
namespace Profile {
@@ -49,16 +50,23 @@ public:
bool infoExpanded() const {
return _infoExpanded;
}
void setMediaExpanded(bool expanded) {
_mediaExpanded = expanded;
void setMembersSearch(QString query) {
_membersSearch = query;
}
bool mediaExpanded() const {
return _mediaExpanded;
base::optional<QString> membersSearch() const {
return _membersSearch;
}
void setMembersState(std::unique_ptr<PeerListState> state) {
_membersState = std::move(state);
}
std::unique_ptr<PeerListState> membersState() {
return std::move(_membersState);
}
private:
bool _infoExpanded = false;
bool _mediaExpanded = false;
base::optional<QString> _membersSearch;
std::unique_ptr<PeerListState> _membersState;
};