@@ -154,6 +154,7 @@ ListWidget::ListWidget(
154154 _provider->type (),
155155 [=] { scrollDateCheck (); },
156156 [=] { scrollDateHide (); }))
157+ , _selectedLimit(MaxSelectedItems)
157158, _storiesAddToAlbumId(controller->storiesAddToAlbumId ())
158159, _hiddenMark(std::make_unique<StickerPremiumMark>(
159160 &_controller->session (),
@@ -275,6 +276,7 @@ void ListWidget::setupStoriesTrackIds() {
275276 }
276277 const auto peerId = _controller->storiesPeer ()->id ;
277278 const auto stories = &session ().data ().stories ();
279+
278280 constexpr auto kArchive = Data::kStoriesAlbumIdArchive ;
279281 const auto key = Data::StoryAlbumIdsKey{ peerId, kArchive };
280282 rpl::single (rpl::empty) | rpl::then (
@@ -302,6 +304,32 @@ void ListWidget::setupStoriesTrackIds() {
302304 }
303305 }
304306 }, lifetime ());
307+
308+ if (!stories->albumIdsCountKnown (peerId, _storiesAddToAlbumId)) {
309+ stories->albumIdsLoadMore (peerId, _storiesAddToAlbumId);
310+ }
311+
312+ const auto akey = Data::StoryAlbumIdsKey{ peerId, _storiesAddToAlbumId };
313+ rpl::single (rpl::empty) | rpl::then (
314+ stories->albumIdsChanged () | rpl::filter (
315+ rpl::mappers::_1 == akey
316+ ) | rpl::to_empty
317+ ) | rpl::start_with_next ([=] {
318+ _storiesAddToAlbumTotal = stories->albumIdsCount (
319+ peerId,
320+ _storiesAddToAlbumId);
321+
322+ const auto albumId = _storiesAddToAlbumId;
323+ const auto &ids = stories->albumKnownInArchive (peerId, albumId);
324+ const auto loadedCount = int (ids.size ());
325+ const auto total = std::max (_storiesAddToAlbumTotal, loadedCount);
326+ const auto nonLoadedInAlbum = total - loadedCount;
327+
328+ const auto appConfig = &_controller->session ().appConfig ();
329+ const auto totalLimit = appConfig->storiesAlbumLimit ();
330+
331+ _selectedLimit = std::max (totalLimit - nonLoadedInAlbum, 0 );
332+ }, lifetime ());
305333}
306334
307335rpl::producer<int > ListWidget::scrollToRequests () const {
@@ -603,8 +631,6 @@ void ListWidget::markStoryMsgsSelected() {
603631 pushSelectedItems ();
604632 }
605633 });
606- const auto &appConfig = _controller->session ().appConfig ();
607- const auto selectLimit = appConfig.storiesAlbumLimit ();
608634 const auto selection = FullSelection;
609635 for (const auto §ion : _sections) {
610636 for (const auto &entry : section.items ()) {
@@ -616,7 +642,7 @@ void ListWidget::markStoryMsgsSelected() {
616642 _selected,
617643 item,
618644 _provider->computeSelectionData (item, selection),
619- selectLimit );
645+ _selectedLimit );
620646 repaintItem (item);
621647 _storyMsgsToMarkSelected.erase (i);
622648 if (_storyMsgsToMarkSelected.empty ()) {
@@ -1263,7 +1289,7 @@ void ListWidget::showContextMenu(
12631289 crl::guard (this , [=] {
12641290 if (hasSelectedText ()) {
12651291 clearSelected ();
1266- } else if (_selected.size () == MaxSelectedItems ) {
1292+ } else if (_selected.size () == _selectedLimit ) {
12671293 return ;
12681294 } else if (_selected.empty ()) {
12691295 update ();
@@ -1583,15 +1609,12 @@ void ListWidget::switchToWordSelection() {
15831609void ListWidget::applyItemSelection (
15841610 HistoryItem *item,
15851611 TextSelection selection) {
1586- const auto selectLimit = _storiesAddToAlbumId
1587- ? _controller->session ().appConfig ().storiesAlbumLimit ()
1588- : MaxSelectedItems;
15891612 if (item
15901613 && ChangeItemSelection (
15911614 _selected,
15921615 item,
15931616 _provider->computeSelectionData (item, selection),
1594- selectLimit )) {
1617+ _selectedLimit )) {
15951618 repaintItem (item);
15961619 pushSelectedItems ();
15971620 }
@@ -2133,15 +2156,12 @@ void ListWidget::applyDragSelection() {
21332156
21342157void ListWidget::applyDragSelection (SelectedMap &applyTo) const {
21352158 if (_dragSelectAction == DragSelectAction::Selecting) {
2136- const auto selectLimit = _storiesAddToAlbumId
2137- ? _controller->session ().appConfig ().storiesAlbumLimit ()
2138- : MaxSelectedItems;
21392159 for (auto &[item, data] : _dragSelected) {
21402160 ChangeItemSelection (
21412161 applyTo,
21422162 item,
21432163 _provider->computeSelectionData (item, FullSelection),
2144- selectLimit );
2164+ _selectedLimit );
21452165 }
21462166 } else if (_dragSelectAction == DragSelectAction::Deselecting) {
21472167 for (auto &[item, data] : _dragSelected) {
0 commit comments