Remove hidden stories from contacts box.

This commit is contained in:
John Preston 2023-07-11 19:41:23 +04:00
parent 7b911897fc
commit 06469270d0
1 changed files with 0 additions and 278 deletions

View File

@ -53,63 +53,6 @@ namespace {
constexpr auto kSortByOnlineThrottle = 3 * crl::time(1000);
constexpr auto kSearchPerPage = 50;
class StoriesRow final : public PeerListRow {
public:
StoriesRow(
not_null<Main::Session*> session,
const QBrush &unread,
const Dialogs::Stories::Element &element,
int position);
void applySegments(const Dialogs::Stories::Element &element);
void updateGradient(QBrush unread);
int position = 0;
private:
void refreshSegments();
QBrush _unread;
int _count = 0;
int _unreadCount = 0;
};
class StoriesController final
: public PeerListController
, public base::has_weak_ptr {
public:
using Content = Dialogs::Stories::Content;
using Row = StoriesRow;
StoriesController(
not_null<Window::SessionController*> window,
rpl::producer<Content> content,
Fn<void(uint64)> open,
Fn<void()> loadMore);
Main::Session &session() const override;
void prepare() override;
void loadMoreRows() override;
void rowClicked(not_null<PeerListRow*> row) override;
base::unique_qptr<Ui::PopupMenu> rowContextMenu(
QWidget *parent,
not_null<PeerListRow*> row) override;
private:
void refresh(const Content &content);
const not_null<Window::SessionController*> _window;
QBrush _unread;
rpl::producer<Content> _content;
Fn<void(uint64)> _open;
Fn<void()> _loadMore;
bool _positionPositive = false;
rpl::lifetime _lifetime;
};
[[nodiscard]] std::vector<Ui::RoundImageCheckboxSegment> PrepareSegments(
int count,
int unread,
@ -150,221 +93,6 @@ private:
return QBrush(gradient);
}
StoriesRow::StoriesRow(
not_null<Main::Session*> session,
const QBrush &unread,
const Dialogs::Stories::Element &element,
int position)
: PeerListRow(session->data().peer(PeerId(element.id)))
, position(position)
, _unread(unread) {
}
void StoriesRow::applySegments(const Dialogs::Stories::Element &element) {
Expects(element.unreadCount <= element.count);
_count = int(std::max(element.count, 1U));
_unreadCount = element.unreadCount;
refreshSegments();
setCustomStatus(_unreadCount
? tr::lng_contacts_stories_status_new(
tr::now,
lt_count,
_unreadCount)
: tr::lng_contacts_stories_status(tr::now, lt_count, _count));
}
void StoriesRow::updateGradient(QBrush unread) {
_unread = std::move(unread);
refreshSegments();
}
void StoriesRow::refreshSegments() {
setCustomizedCheckSegments(
PrepareSegments(_count, _unreadCount, _unread));
}
StoriesController::StoriesController(
not_null<Window::SessionController*> window,
rpl::producer<Content> content,
Fn<void(uint64)> open,
Fn<void()> loadMore)
: _window(window)
, _content(std::move(content))
, _open(std::move(open))
, _loadMore(std::move(loadMore)) {
_unread = CreateStoriesGradient();
style::PaletteChanged(
) | rpl::start_with_next([=] {
_unread = CreateStoriesGradient();
for (auto i = 0, count = int(delegate()->peerListFullRowsCount())
; i != count
; ++i) {
const auto row = delegate()->peerListRowAt(i).get();
static_cast<Row*>(row)->updateGradient(_unread);
}
}, _lifetime);
}
Main::Session &StoriesController::session() const {
return _window->session();
}
void StoriesController::prepare() {
if (_loadMore) {
_loadMore();
}
std::move(
_content
) | rpl::start_with_next([=](Content content) {
refresh(content);
}, _lifetime);
}
void StoriesController::loadMoreRows() {
if (_loadMore) {
_loadMore();
}
}
void StoriesController::rowClicked(not_null<PeerListRow*> row) {
if (_open) {
_open(row->id());
}
}
base::unique_qptr<Ui::PopupMenu> StoriesController::rowContextMenu(
QWidget *parent,
not_null<PeerListRow*> row) {
auto result = base::make_unique_q<Ui::PopupMenu>(
parent,
st::popupMenuWithIcons);
Dialogs::Stories::FillSourceMenu(_window, {
.id = row->id(),
.callback = Ui::Menu::CreateAddActionCallback(result.get()),
});
if (result->empty()) {
return nullptr;
}
return result;
}
void StoriesController::refresh(const Content &content) {
const auto session = &_window->session();
const auto positive = _positionPositive = !_positionPositive;
auto position = positive ? 1 : -int(content.elements.size());
for (const auto &element : content.elements) {
if (const auto row = delegate()->peerListFindRow(element.id)) {
static_cast<Row*>(row)->position = position;
static_cast<Row*>(row)->applySegments(element);
} else {
auto added = std::make_unique<Row>(
session,
_unread,
element,
position);
const auto raw = added.get();
delegate()->peerListAppendRow(std::move(added));
delegate()->peerListSetRowChecked(raw, true);
raw->applySegments(element);
raw->finishCheckedAnimation();
}
++position;
}
auto count = delegate()->peerListFullRowsCount();
for (auto i = 0; i != count;) {
const auto row = delegate()->peerListRowAt(i);
const auto position = static_cast<Row*>(row.get())->position;
if (positive ? (position > 0) : (position < 0)) {
++i;
} else {
delegate()->peerListRemoveRow(row);
--count;
}
}
delegate()->peerListSortRows([](
const PeerListRow &a,
const PeerListRow &b) {
return static_cast<const Row&>(a).position
< static_cast<const Row&>(b).position;
});
delegate()->peerListRefreshRows();
}
[[nodiscard]] object_ptr<Ui::RpWidget> PrepareHiddenStoriesList(
not_null<PeerListBox*> box,
not_null<Window::SessionController*> sessionController,
rpl::producer<ContactsBoxController::SortMode> mode) {
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
box,
object_ptr<Ui::VerticalLayout>(box));
const auto container = result->entity();
const auto stories = &sessionController->session().data().stories();
container->add(CreatePeerListSectionSubtitle(
container,
tr::lng_contacts_hidden_stories()));
auto &lifetime = container->lifetime();
auto list = Dialogs::Stories::ContentForSession(
&sessionController->session(),
Data::StorySourcesList::Hidden
) | rpl::start_spawning(lifetime);
const auto delegate = lifetime.make_state<
PeerListContentDelegateSimple
>();
const auto open = [=](uint64 id) {
sessionController->openPeerStories(
PeerId(int64(id)),
Data::StorySourcesList::Hidden);
};
const auto loadMore = [=] {
stories->loadMore(Data::StorySourcesList::Hidden);
};
const auto controller = lifetime.make_state<StoriesController>(
sessionController,
rpl::duplicate(
list
) | rpl::filter([](const Dialogs::Stories::Content &list) {
return !list.elements.empty();
}),
open,
loadMore);
controller->setStyleOverrides(&st::contactsWithStories);
const auto content = container->add(object_ptr<PeerListContent>(
container,
controller));
delegate->setContent(content);
controller->setDelegate(delegate);
container->add(CreatePeerListSectionSubtitle(
container,
rpl::conditional(
std::move(
mode
) | rpl::map(
rpl::mappers::_1 == ContactsBoxController::SortMode::Online
),
tr::lng_contacts_by_online(),
tr::lng_contacts_by_name())));
stories->incrementPreloadingHiddenSources();
lifetime.add([=] {
stories->decrementPreloadingHiddenSources();
});
result->toggleOn(rpl::duplicate(
list
) | rpl::map([](const Dialogs::Stories::Content &list) {
return !list.elements.empty();
}));
result->finishAnimating();
return result;
}
} // namespace
object_ptr<Ui::BoxContent> PrepareContactsBox(
@ -384,7 +112,6 @@ object_ptr<Ui::BoxContent> PrepareContactsBox(
::Ui::Animations::Simple scrollAnimation;
};
const auto stories = &sessionController->session().data().stories();
const auto state = box->lifetime().make_state<State>();
box->addButton(tr::lng_close(), [=] { box->closeBox(); });
box->addLeftButton(
@ -400,11 +127,6 @@ object_ptr<Ui::BoxContent> PrepareContactsBox(
online ? &st::contactsSortOnlineIconOver : nullptr);
});
raw->setSortMode(Mode::Online);
box->peerListSetAboveWidget(PrepareHiddenStoriesList(
box,
sessionController,
state->mode.value()));
};
return Box<PeerListBox>(std::move(controller), std::move(init));
}