Added chats filters tabs strip to share box.

This commit is contained in:
23rd 2024-11-01 17:31:14 +03:00
parent d81c7abf1a
commit 1fa5e424e9
2 changed files with 54 additions and 7 deletions

View file

@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/storage_account.h" #include "storage/storage_account.h"
#include "ui/boxes/confirm_box.h" #include "ui/boxes/confirm_box.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "ui/widgets/chat_filters_tabs_strip.h"
#include "ui/widgets/checkbox.h" #include "ui/widgets/checkbox.h"
#include "ui/widgets/multi_select.h" #include "ui/widgets/multi_select.h"
#include "ui/widgets/scroll_area.h" #include "ui/widgets/scroll_area.h"
@ -39,6 +40,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "chat_helpers/share_message_phrase_factory.h" #include "chat_helpers/share_message_phrase_factory.h"
#include "data/business/data_shortcut_messages.h" #include "data/business/data_shortcut_messages.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "data/data_chat_filters.h"
#include "data/data_game.h" #include "data/data_game.h"
#include "data/data_histories.h" #include "data/data_histories.h"
#include "data/data_user.h" #include "data/data_user.h"
@ -86,6 +88,8 @@ public:
rpl::producer<Ui::ScrollToRequest> scrollToRequests() const; rpl::producer<Ui::ScrollToRequest> scrollToRequests() const;
rpl::producer<> searchRequests() const; rpl::producer<> searchRequests() const;
void applyChatFilter(FilterId id);
protected: protected:
void visibleTopBottomUpdated( void visibleTopBottomUpdated(
int visibleTop, int visibleTop,
@ -166,7 +170,9 @@ private:
int _upon = -1; int _upon = -1;
int _visibleTop = 0; int _visibleTop = 0;
std::unique_ptr<Dialogs::IndexedList> _chatsIndexed; std::unique_ptr<Dialogs::IndexedList> _defaultChatsIndexed;
std::unique_ptr<Dialogs::IndexedList> _customChatsIndexed;
not_null<Dialogs::IndexedList*> _chatsIndexed;
QString _filter; QString _filter;
std::vector<not_null<Dialogs::Row*>> _filtered; std::vector<not_null<Dialogs::Row*>> _filtered;
@ -337,10 +343,25 @@ void ShareBox::prepare() {
{ .suggestCustomEmoji = true }); { .suggestCustomEmoji = true });
_select->raise(); _select->raise();
AddChatFiltersTabsStrip(
this,
_descriptor.session,
_select->heightValue(),
[this](int height) {
_additionalTopScrollSkip = height;
updateScrollSkips();
scrollToY(0);
},
[this](FilterId id) {
_inner->applyChatFilter(id);
scrollToY(0);
});
} }
int ShareBox::getTopScrollSkip() const { int ShareBox::getTopScrollSkip() const {
return _select->isHidden() ? 0 : _select->height(); return (_select->isHidden() ? 0 : _select->height())
+ _additionalTopScrollSkip;
} }
int ShareBox::getBottomScrollSkip() const { int ShareBox::getBottomScrollSkip() const {
@ -671,9 +692,10 @@ ShareBox::Inner::Inner(
, _descriptor(descriptor) , _descriptor(descriptor)
, _show(std::move(show)) , _show(std::move(show))
, _st(_descriptor.st ? *_descriptor.st : st::shareBoxList) , _st(_descriptor.st ? *_descriptor.st : st::shareBoxList)
, _chatsIndexed( , _defaultChatsIndexed(
std::make_unique<Dialogs::IndexedList>( std::make_unique<Dialogs::IndexedList>(
Dialogs::SortMode::Add)) { Dialogs::SortMode::Add))
, _chatsIndexed(_defaultChatsIndexed.get()) {
_rowsTop = st::shareRowsTop; _rowsTop = st::shareRowsTop;
_rowHeight = st::shareRowHeight; _rowHeight = st::shareRowHeight;
setAttribute(Qt::WA_OpaquePaintEvent); setAttribute(Qt::WA_OpaquePaintEvent);
@ -691,7 +713,7 @@ ShareBox::Inner::Inner(
const auto self = _descriptor.session->user(); const auto self = _descriptor.session->user();
const auto selfHistory = self->owner().history(self); const auto selfHistory = self->owner().history(self);
if (_descriptor.filterCallback(selfHistory)) { if (_descriptor.filterCallback(selfHistory)) {
_chatsIndexed->addToEnd(selfHistory); _defaultChatsIndexed->addToEnd(selfHistory);
} }
const auto addList = [&](not_null<Dialogs::IndexedList*> list) { const auto addList = [&](not_null<Dialogs::IndexedList*> list) {
for (const auto &row : list->all()) { for (const auto &row : list->all()) {
@ -699,7 +721,7 @@ ShareBox::Inner::Inner(
if (!history->peer->isSelf() if (!history->peer->isSelf()
&& (history->asForum() && (history->asForum()
|| _descriptor.filterCallback(history))) { || _descriptor.filterCallback(history))) {
_chatsIndexed->addToEnd(history); _defaultChatsIndexed->addToEnd(history);
} }
} }
} }
@ -722,7 +744,7 @@ ShareBox::Inner::Inner(
_descriptor.session->changes().realtimeNameUpdates( _descriptor.session->changes().realtimeNameUpdates(
) | rpl::start_with_next([=](const Data::NameUpdate &update) { ) | rpl::start_with_next([=](const Data::NameUpdate &update) {
_chatsIndexed->peerNameChanged( _defaultChatsIndexed->peerNameChanged(
update.peer, update.peer,
update.oldFirstLetters); update.oldFirstLetters);
}, lifetime()); }, lifetime());
@ -1339,6 +1361,29 @@ rpl::producer<> ShareBox::Inner::searchRequests() const {
return _searchRequests.events(); return _searchRequests.events();
} }
void ShareBox::Inner::applyChatFilter(FilterId id) {
if (!id) {
_chatsIndexed = _defaultChatsIndexed.get();
} else {
_customChatsIndexed = std::make_unique<Dialogs::IndexedList>(
Dialogs::SortMode::Add);
_chatsIndexed = _customChatsIndexed.get();
const auto addList = [&](not_null<Dialogs::IndexedList*> list) {
for (const auto &row : list->all()) {
if (const auto history = row->history()) {
if (_descriptor.filterCallback(history)) {
_customChatsIndexed->addToEnd(history);
}
}
}
};
const auto &data = _descriptor.session->data();
addList(data.chatsFilters().chatsList(id)->indexed());
}
update();
}
void ShareBox::Inner::peopleReceived( void ShareBox::Inner::peopleReceived(
const QString &query, const QString &query,
const QVector<MTPPeer> &my, const QVector<MTPPeer> &my,

View file

@ -174,6 +174,8 @@ private:
bool _peopleFull = false; bool _peopleFull = false;
mtpRequestId _peopleRequest = 0; mtpRequestId _peopleRequest = 0;
int _additionalTopScrollSkip = 0;
using PeopleCache = QMap<QString, MTPcontacts_Found>; using PeopleCache = QMap<QString, MTPcontacts_Found>;
PeopleCache _peopleCache; PeopleCache _peopleCache;