mirror of https://github.com/procxx/kepka.git
Suggest filter name by content type.
This commit is contained in:
parent
2dbaee4fe1
commit
b1606821c0
|
@ -2265,6 +2265,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_filters_exclude_muted" = "Muted";
|
"lng_filters_exclude_muted" = "Muted";
|
||||||
"lng_filters_exclude_read" = "Read";
|
"lng_filters_exclude_read" = "Read";
|
||||||
"lng_filters_exclude_archived" = "Archived";
|
"lng_filters_exclude_archived" = "Archived";
|
||||||
|
"lng_filters_name_people" = "People";
|
||||||
|
"lng_filters_name_unread" = "Unread";
|
||||||
|
"lng_filters_name_unmuted" = "Unmuted";
|
||||||
"lng_filters_add" = "Done";
|
"lng_filters_add" = "Done";
|
||||||
"lng_filters_limit" = "Sorry, you have reached folders limit.";
|
"lng_filters_limit" = "Sorry, you have reached folders limit.";
|
||||||
"lng_filters_empty" = "Please choose at least one chat for this folder.";
|
"lng_filters_empty" = "Please choose at least one chat for this folder.";
|
||||||
|
|
|
@ -93,9 +93,16 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct NameEditing {
|
||||||
|
not_null<Ui::InputField*> field;
|
||||||
|
bool custom = false;
|
||||||
|
bool settingDefault = false;
|
||||||
|
};
|
||||||
|
|
||||||
not_null<FilterChatsPreview*> SetupChatsPreview(
|
not_null<FilterChatsPreview*> SetupChatsPreview(
|
||||||
not_null<Ui::VerticalLayout*> content,
|
not_null<Ui::VerticalLayout*> content,
|
||||||
not_null<rpl::variable<Data::ChatFilter>*> data,
|
not_null<rpl::variable<Data::ChatFilter>*> data,
|
||||||
|
Fn<void(const Data::ChatFilter&)> updateDefaultTitle,
|
||||||
Flags flags,
|
Flags flags,
|
||||||
ExceptionPeersGetter peers) {
|
ExceptionPeersGetter peers) {
|
||||||
const auto rules = data->current();
|
const auto rules = data->current();
|
||||||
|
@ -107,7 +114,7 @@ not_null<FilterChatsPreview*> SetupChatsPreview(
|
||||||
preview->flagRemoved(
|
preview->flagRemoved(
|
||||||
) | rpl::start_with_next([=](Flag flag) {
|
) | rpl::start_with_next([=](Flag flag) {
|
||||||
const auto rules = data->current();
|
const auto rules = data->current();
|
||||||
*data = Data::ChatFilter(
|
auto computed = Data::ChatFilter(
|
||||||
rules.id(),
|
rules.id(),
|
||||||
rules.title(),
|
rules.title(),
|
||||||
rules.iconEmoji(),
|
rules.iconEmoji(),
|
||||||
|
@ -115,6 +122,8 @@ not_null<FilterChatsPreview*> SetupChatsPreview(
|
||||||
rules.always(),
|
rules.always(),
|
||||||
rules.pinned(),
|
rules.pinned(),
|
||||||
rules.never());
|
rules.never());
|
||||||
|
updateDefaultTitle(computed);
|
||||||
|
*data = std::move(computed);
|
||||||
}, preview->lifetime());
|
}, preview->lifetime());
|
||||||
|
|
||||||
preview->peerRemoved(
|
preview->peerRemoved(
|
||||||
|
@ -126,7 +135,7 @@ not_null<FilterChatsPreview*> SetupChatsPreview(
|
||||||
always.remove(history);
|
always.remove(history);
|
||||||
pinned.erase(ranges::remove(pinned, history), end(pinned));
|
pinned.erase(ranges::remove(pinned, history), end(pinned));
|
||||||
never.remove(history);
|
never.remove(history);
|
||||||
*data = Data::ChatFilter(
|
auto computed = Data::ChatFilter(
|
||||||
rules.id(),
|
rules.id(),
|
||||||
rules.title(),
|
rules.title(),
|
||||||
rules.iconEmoji(),
|
rules.iconEmoji(),
|
||||||
|
@ -134,6 +143,8 @@ not_null<FilterChatsPreview*> SetupChatsPreview(
|
||||||
std::move(always),
|
std::move(always),
|
||||||
std::move(pinned),
|
std::move(pinned),
|
||||||
std::move(never));
|
std::move(never));
|
||||||
|
updateDefaultTitle(computed);
|
||||||
|
*data = std::move(computed);
|
||||||
}, preview->lifetime());
|
}, preview->lifetime());
|
||||||
|
|
||||||
return preview;
|
return preview;
|
||||||
|
@ -269,6 +280,7 @@ void EditExceptions(
|
||||||
not_null<QObject*> context,
|
not_null<QObject*> context,
|
||||||
Flags options,
|
Flags options,
|
||||||
not_null<rpl::variable<Data::ChatFilter>*> data,
|
not_null<rpl::variable<Data::ChatFilter>*> data,
|
||||||
|
Fn<void(const Data::ChatFilter&)> updateDefaultTitle,
|
||||||
Fn<void()> refresh) {
|
Fn<void()> refresh) {
|
||||||
const auto include = (options & Flag::Contacts) != Flags(0);
|
const auto include = (options & Flag::Contacts) != Flags(0);
|
||||||
const auto rules = data->current();
|
const auto rules = data->current();
|
||||||
|
@ -304,7 +316,7 @@ void EditExceptions(
|
||||||
const auto contains = changed.contains(history);
|
const auto contains = changed.contains(history);
|
||||||
return include ? !contains : contains;
|
return include ? !contains : contains;
|
||||||
}), end(pinned));
|
}), end(pinned));
|
||||||
*data = Data::ChatFilter(
|
auto computed = Data::ChatFilter(
|
||||||
rules.id(),
|
rules.id(),
|
||||||
rules.title(),
|
rules.title(),
|
||||||
rules.iconEmoji(),
|
rules.iconEmoji(),
|
||||||
|
@ -313,6 +325,8 @@ void EditExceptions(
|
||||||
include ? std::move(changed) : std::move(removeFrom),
|
include ? std::move(changed) : std::move(removeFrom),
|
||||||
std::move(pinned),
|
std::move(pinned),
|
||||||
include ? std::move(removeFrom) : std::move(changed));
|
include ? std::move(removeFrom) : std::move(changed));
|
||||||
|
updateDefaultTitle(computed);
|
||||||
|
*data = computed;
|
||||||
refresh();
|
refresh();
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
}));
|
}));
|
||||||
|
@ -413,6 +427,28 @@ void EditExceptions(
|
||||||
installFilterForGeometry(box);
|
installFilterForGeometry(box);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] QString DefaultTitle(const Data::ChatFilter &filter) {
|
||||||
|
using Icon = Ui::FilterIcon;
|
||||||
|
const auto icon = Ui::ComputeDefaultFilterIcon(filter);
|
||||||
|
switch (icon) {
|
||||||
|
case Icon::Private:
|
||||||
|
return (filter.flags() & Data::ChatFilter::Flag::NonContacts)
|
||||||
|
? tr::lng_filters_name_people(tr::now)
|
||||||
|
: tr::lng_filters_include_contacts(tr::now);
|
||||||
|
case Icon::Groups:
|
||||||
|
return tr::lng_filters_include_groups(tr::now);
|
||||||
|
case Icon::Channels:
|
||||||
|
return tr::lng_filters_include_channels(tr::now);
|
||||||
|
case Icon::Bots:
|
||||||
|
return tr::lng_filters_include_bots(tr::now);
|
||||||
|
case Icon::Unread:
|
||||||
|
return tr::lng_filters_name_unread(tr::now);
|
||||||
|
case Icon::Unmuted:
|
||||||
|
return tr::lng_filters_name_unmuted(tr::now);
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void EditFilterBox(
|
void EditFilterBox(
|
||||||
|
@ -433,10 +469,30 @@ void EditFilterBox(
|
||||||
box,
|
box,
|
||||||
st::windowFilterNameInput,
|
st::windowFilterNameInput,
|
||||||
tr::lng_filters_new_name(),
|
tr::lng_filters_new_name(),
|
||||||
data->current().title()),
|
filter.title()),
|
||||||
st::markdownLinkFieldPadding);
|
st::markdownLinkFieldPadding);
|
||||||
name->setMaxLength(kMaxFilterTitleLength);
|
name->setMaxLength(kMaxFilterTitleLength);
|
||||||
|
|
||||||
|
const auto nameEditing = box->lifetime().make_state<NameEditing>(
|
||||||
|
NameEditing{ name });
|
||||||
|
nameEditing->custom = !creating;
|
||||||
|
QObject::connect(name, &Ui::InputField::changed, [=] {
|
||||||
|
if (!nameEditing->settingDefault) {
|
||||||
|
nameEditing->custom = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const auto updateDefaultTitle = [=](const Data::ChatFilter &filter) {
|
||||||
|
if (nameEditing->custom) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto title = DefaultTitle(filter);
|
||||||
|
if (nameEditing->field->getLastText() != title) {
|
||||||
|
nameEditing->settingDefault = true;
|
||||||
|
nameEditing->field->setText(title);
|
||||||
|
nameEditing->settingDefault = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const auto outer = box->getDelegate()->outerContainer();
|
const auto outer = box->getDelegate()->outerContainer();
|
||||||
CreateIconSelector(
|
CreateIconSelector(
|
||||||
outer,
|
outer,
|
||||||
|
@ -466,6 +522,7 @@ void EditFilterBox(
|
||||||
const auto include = SetupChatsPreview(
|
const auto include = SetupChatsPreview(
|
||||||
content,
|
content,
|
||||||
data,
|
data,
|
||||||
|
updateDefaultTitle,
|
||||||
kTypes,
|
kTypes,
|
||||||
&Data::ChatFilter::always);
|
&Data::ChatFilter::always);
|
||||||
|
|
||||||
|
@ -483,6 +540,7 @@ void EditFilterBox(
|
||||||
const auto exclude = SetupChatsPreview(
|
const auto exclude = SetupChatsPreview(
|
||||||
content,
|
content,
|
||||||
data,
|
data,
|
||||||
|
updateDefaultTitle,
|
||||||
kExcludeTypes,
|
kExcludeTypes,
|
||||||
&Data::ChatFilter::never);
|
&Data::ChatFilter::never);
|
||||||
|
|
||||||
|
@ -508,10 +566,22 @@ void EditFilterBox(
|
||||||
data->current().never());
|
data->current().never());
|
||||||
};
|
};
|
||||||
includeAdd->setClickedCallback([=] {
|
includeAdd->setClickedCallback([=] {
|
||||||
EditExceptions(window, box, kTypes, data, refreshPreviews);
|
EditExceptions(
|
||||||
|
window,
|
||||||
|
box,
|
||||||
|
kTypes,
|
||||||
|
data,
|
||||||
|
updateDefaultTitle,
|
||||||
|
refreshPreviews);
|
||||||
});
|
});
|
||||||
excludeAdd->setClickedCallback([=] {
|
excludeAdd->setClickedCallback([=] {
|
||||||
EditExceptions(window, box, kExcludeTypes, data, refreshPreviews);
|
EditExceptions(
|
||||||
|
window,
|
||||||
|
box,
|
||||||
|
kExcludeTypes,
|
||||||
|
data,
|
||||||
|
updateDefaultTitle,
|
||||||
|
refreshPreviews);
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto save = [=] {
|
const auto save = [=] {
|
||||||
|
|
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/wrap/vertical_layout.h"
|
#include "ui/wrap/vertical_layout.h"
|
||||||
#include "base/object_ptr.h"
|
#include "base/object_ptr.h"
|
||||||
#include "styles/style_window.h"
|
#include "styles/style_window.h"
|
||||||
|
#include "styles/style_boxes.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -359,6 +360,9 @@ object_ptr<Ui::RpWidget> EditFilterChatsListController::prepareTypesList() {
|
||||||
container->add(CreateSectionSubtitle(
|
container->add(CreateSectionSubtitle(
|
||||||
container,
|
container,
|
||||||
tr::lng_filters_edit_types()));
|
tr::lng_filters_edit_types()));
|
||||||
|
container->add(object_ptr<Ui::FixedHeightWidget>(
|
||||||
|
container,
|
||||||
|
st::membersMarginTop));
|
||||||
const auto delegate = container->lifetime().make_state<TypeDelegate>();
|
const auto delegate = container->lifetime().make_state<TypeDelegate>();
|
||||||
const auto controller = container->lifetime().make_state<TypeController>(
|
const auto controller = container->lifetime().make_state<TypeController>(
|
||||||
&session(),
|
&session(),
|
||||||
|
@ -381,6 +385,9 @@ object_ptr<Ui::RpWidget> EditFilterChatsListController::prepareTypesList() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
container->add(object_ptr<Ui::FixedHeightWidget>(
|
||||||
|
container,
|
||||||
|
st::membersMarginBottom));
|
||||||
container->add(CreateSectionSubtitle(
|
container->add(CreateSectionSubtitle(
|
||||||
container,
|
container,
|
||||||
tr::lng_filters_edit_chats()));
|
tr::lng_filters_edit_chats()));
|
||||||
|
|
Loading…
Reference in New Issue