2020-03-03 12:07:22 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "window/window_filters_menu.h"
|
|
|
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "window/window_session_controller.h"
|
|
|
|
#include "main/main_session.h"
|
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "data/data_chat_filters.h"
|
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
#include "styles/style_window.h"
|
|
|
|
|
|
|
|
namespace Window {
|
2020-03-06 13:12:22 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
enum class Type {
|
|
|
|
Unread,
|
|
|
|
Unmuted,
|
|
|
|
Custom,
|
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] Type ComputeType(const Data::ChatFilter &filter) {
|
|
|
|
using Flag = Data::ChatFilter::Flag;
|
|
|
|
|
|
|
|
const auto all = Flag::Contacts
|
|
|
|
| Flag::NonContacts
|
|
|
|
| Flag::Groups
|
|
|
|
| Flag::Broadcasts
|
|
|
|
| Flag::Bots
|
|
|
|
| Flag::NoArchive;
|
|
|
|
if (!filter.always().empty()) {
|
|
|
|
return Type::Custom;
|
|
|
|
} else if (filter.flags() == (all | Flag::NoRead)) {
|
|
|
|
return Type::Unread;
|
|
|
|
} else if (filter.flags() == (all | Flag::NoMuted)) {
|
|
|
|
return Type::Unmuted;
|
|
|
|
}
|
|
|
|
return Type::Custom;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] std::array<const style::icon*, 2> ComputeIcons(Type type) {
|
|
|
|
switch (type) {
|
|
|
|
case Type::Unread:
|
|
|
|
return {
|
|
|
|
&st::windowFiltersUnread,
|
|
|
|
&st::windowFiltersUnreadActive
|
|
|
|
};
|
|
|
|
case Type::Unmuted:
|
|
|
|
return {
|
|
|
|
&st::windowFiltersUnmuted,
|
|
|
|
&st::windowFiltersUnmutedActive
|
|
|
|
};
|
|
|
|
case Type::Custom:
|
|
|
|
return {
|
|
|
|
&st::windowFiltersCustom,
|
|
|
|
&st::windowFiltersCustomActive
|
|
|
|
};
|
|
|
|
}
|
|
|
|
Unexpected("Filter type in FiltersMenu::refresh.");
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2020-03-03 12:07:22 +00:00
|
|
|
|
2020-03-06 11:37:48 +00:00
|
|
|
FiltersMenu::FiltersMenu(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
not_null<SessionController*> session)
|
2020-03-03 12:07:22 +00:00
|
|
|
: _session(session)
|
2020-03-06 11:37:48 +00:00
|
|
|
, _parent(parent)
|
|
|
|
, _widget(_parent, st::defaultSideBarMenu) {
|
2020-03-03 12:07:22 +00:00
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FiltersMenu::setup() {
|
2020-03-06 11:37:48 +00:00
|
|
|
_parent->heightValue(
|
|
|
|
) | rpl::start_with_next([=](int height) {
|
|
|
|
_widget.setGeometry({ 0, 0, st::windowFiltersWidth, height });
|
2020-03-03 12:07:22 +00:00
|
|
|
}, _widget.lifetime());
|
|
|
|
|
|
|
|
const auto filters = &_session->session().data().chatsFilters();
|
|
|
|
rpl::single(
|
|
|
|
rpl::empty_value()
|
|
|
|
) | rpl::then(
|
|
|
|
filters->changed()
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
refresh();
|
|
|
|
}, _widget.lifetime());
|
|
|
|
|
|
|
|
_session->activeChatsFilter(
|
|
|
|
) | rpl::start_with_next([=](FilterId id) {
|
|
|
|
_widget.setActive(QString::number(id));
|
|
|
|
}, _widget.lifetime());
|
|
|
|
|
|
|
|
_widget.activateRequests(
|
|
|
|
) | rpl::start_with_next([=](const QString &id) {
|
2020-03-06 12:20:50 +00:00
|
|
|
if (id == "main_menu") {
|
|
|
|
_session->widget()->showMainMenu();
|
|
|
|
} else if (id == "setup") {
|
2020-03-03 12:07:22 +00:00
|
|
|
} else if (const auto filterId = id.toInt()) {
|
|
|
|
_session->setActiveChatsFilter(filterId);
|
|
|
|
} else {
|
|
|
|
_session->setActiveChatsFilter(0);
|
|
|
|
}
|
|
|
|
}, _widget.lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
void FiltersMenu::refresh() {
|
|
|
|
auto items = std::vector<Ui::SideBarMenu::Item>();
|
2020-03-06 12:20:50 +00:00
|
|
|
items.push_back({
|
|
|
|
"main_menu",
|
|
|
|
QString(),
|
|
|
|
QString(),
|
|
|
|
&st::windowFiltersMainMenu,
|
|
|
|
&st::windowFiltersMainMenu,
|
|
|
|
st::windowFiltersMainMenuIconTop
|
|
|
|
});
|
2020-03-03 12:07:22 +00:00
|
|
|
items.push_back({
|
|
|
|
QString::number(0),
|
|
|
|
"All Chats",
|
|
|
|
QString(),
|
2020-03-06 13:12:22 +00:00
|
|
|
&st::windowFiltersAll,
|
|
|
|
&st::windowFiltersAllActive,
|
2020-03-03 12:07:22 +00:00
|
|
|
st::windowFiltersIconTop
|
|
|
|
});
|
|
|
|
const auto filters = &_session->session().data().chatsFilters();
|
|
|
|
for (const auto &filter : filters->list()) {
|
2020-03-06 13:12:22 +00:00
|
|
|
const auto type = ComputeType(filter);
|
|
|
|
const auto icons = ComputeIcons(type);
|
2020-03-03 12:07:22 +00:00
|
|
|
items.push_back({
|
|
|
|
QString::number(filter.id()),
|
|
|
|
filter.title(),
|
|
|
|
QString(),
|
2020-03-06 13:12:22 +00:00
|
|
|
icons[0],
|
|
|
|
icons[1],
|
2020-03-03 12:07:22 +00:00
|
|
|
st::windowFiltersIconTop
|
|
|
|
});
|
|
|
|
}
|
|
|
|
items.push_back({
|
|
|
|
"setup",
|
|
|
|
"Setup",
|
|
|
|
QString(),
|
|
|
|
&st::windowFiltersSetup,
|
|
|
|
&st::windowFiltersSetup,
|
|
|
|
st::windowFiltersIconTop
|
|
|
|
});
|
|
|
|
_widget.setItems(items);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Window
|