feat: disable similar channels

This commit is contained in:
ZavaruKitsu 2023-12-01 19:21:03 +03:00
parent d6457ebcc7
commit 29dd896c83
7 changed files with 153 additions and 180 deletions

View file

@ -4645,7 +4645,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"ayu_HideNextViewsDescriptionAyu" = "Hide my views forever, until Ghost Mode disabled.";
"ayu_EnableGhostModeStories" = "Enable Ghost Mode";
"ayu_GhostModeIsActive" = "Ghost Mode Is Active";
"ayu_SimpleQuotesAndReplies" = "Simple quotes & replies";
"ayu_SimpleQuotesAndReplies" = "Disable colorful replies";
"ayu_DisableSimilarChannels" = "Disable similar channels";
"ayu_CollapseSimilarChannels" = "Collapse similar channels";
"ayu_HideSimilarChannelsTab" = "Hide similar channels tab";
"ayu_MainFont" = "Application font";
"ayu_MonospaceFont" = "Monospace font";
"ayu_FontDefault" = "Default";

View file

@ -1749,7 +1749,11 @@ void ApiWrap::joinChannel(not_null<ChannelData*> channel) {
using Flag = ChannelDataFlag;
chatParticipants().loadSimilarChannels(channel);
channel->setFlags(channel->flags() | Flag::SimilarExpanded);
const auto settings = &AyuSettings::getInstance();
if (!settings->collapseSimilarChannels) {
channel->setFlags(channel->flags() | Flag::SimilarExpanded);
}
}
}

View file

@ -225,12 +225,12 @@ void AyuGramSettings::set_useScheduledMessages(bool val)
useScheduledMessages = val;
}
void AyuGramSettings::set_keepDeletedMessages(bool val)
void AyuGramSettings::set_saveDeletedMessages(bool val)
{
saveDeletedMessages = val;
}
void AyuGramSettings::set_keepMessagesHistory(bool val)
void AyuGramSettings::set_saveMessagesHistory(bool val)
{
saveMessagesHistory = val;
}
@ -245,6 +245,16 @@ void AyuGramSettings::set_disableStories(bool val)
disableStories = val;
}
void AyuGramSettings::set_collapseSimilarChannels(bool val)
{
collapseSimilarChannels = val;
}
void AyuGramSettings::set_hideSimilarChannels(bool val)
{
hideSimilarChannels = val;
}
void AyuGramSettings::set_disableNotificationsDelay(bool val)
{
disableNotificationsDelay = val;

View file

@ -54,6 +54,8 @@ public:
// ~ QoL toggles
disableAds = true;
disableStories = false;
collapseSimilarChannels = true;
hideSimilarChannels = false;
disableNotificationsDelay = false;
localPremium = false;
copyUsernameAsLink = true;
@ -105,6 +107,8 @@ public:
bool saveMessagesHistory;
bool disableAds;
bool disableStories;
bool collapseSimilarChannels;
bool hideSimilarChannels;
bool disableNotificationsDelay;
bool localPremium;
bool copyUsernameAsLink;
@ -149,14 +153,18 @@ public:
void set_useScheduledMessages(bool val);
void set_keepDeletedMessages(bool val);
void set_saveDeletedMessages(bool val);
void set_keepMessagesHistory(bool val);
void set_saveMessagesHistory(bool val);
void set_disableAds(bool val);
void set_disableStories(bool val);
void set_collapseSimilarChannels(bool val);
void set_hideSimilarChannels(bool val);
void set_disableNotificationsDelay(bool val);
void set_localPremium(bool val);
@ -217,6 +225,8 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
saveMessagesHistory,
disableAds,
disableStories,
collapseSimilarChannels,
hideSimilarChannels,
disableNotificationsDelay,
localPremium,
copyUsernameAsLink,

View file

@ -40,9 +40,9 @@ void AddHideMessageAction(not_null<Ui::PopupMenu *> menu, HistoryItem *item)
{
const auto initSaveDeleted = settings->saveDeletedMessages;
settings->set_keepDeletedMessages(false);
settings->set_saveDeletedMessages(false);
history->destroyMessage(item);
settings->set_keepDeletedMessages(initSaveDeleted);
settings->set_saveDeletedMessages(initSaveDeleted);
}, &st::menuIconClear);
}

View file

@ -247,35 +247,18 @@ not_null<Ui::RpWidget *> AddInnerToggle(not_null<Ui::VerticalLayout *> container
return button;
}
namespace Settings
struct NestedEntry
{
QString checkboxLabel;
bool initial;
std::function<void(bool)> callback;
};
rpl::producer<QString> Ayu::title()
void AddCollapsibleToggle(not_null<Ui::VerticalLayout *> container,
rpl::producer<QString> title,
std::vector<NestedEntry> checkboxes,
bool toggledWhenAll)
{
return tr::ayu_AyuPreferences();
}
Ayu::Ayu(
QWidget *parent,
not_null<Window::SessionController *> controller)
: Section(parent)
{
setupContent(controller);
}
void Ayu::SetupGhostModeToggle(not_null<Ui::VerticalLayout *> container)
{
auto settings = &AyuSettings::getInstance();
const auto widget = object_ptr<Ui::VerticalLayout>(this);
widget->add(
object_ptr<Ui::FlatLabel>(
container,
tr::ayu_GhostEssentialsHeader(),
st::rightsHeaderLabel),
st::rightsHeaderMargin);
const auto addCheckbox = [&](
not_null<Ui::VerticalLayout *> verticalLayout,
const QString &label,
@ -320,12 +303,59 @@ void Ayu::SetupGhostModeToggle(not_null<Ui::VerticalLayout *> container)
return checkView;
};
struct NestedEntry
{
QString checkboxLabel;
bool initial;
std::function<void(bool)> callback;
};
auto wrap = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container,
object_ptr<Ui::VerticalLayout>(container));
const auto verticalLayout = wrap->entity();
auto innerChecks = std::vector<not_null<Ui::AbstractCheckView *>>();
for (const auto &entry : checkboxes) {
const auto c = addCheckbox(verticalLayout, entry.checkboxLabel, entry.initial);
c->checkedValue(
) | start_with_next([=](bool enabled)
{
entry.callback(enabled);
}, container->lifetime());
innerChecks.push_back(c);
}
const auto raw = wrap.data();
raw->hide(anim::type::instant);
AddInnerToggle(
container,
st::powerSavingButtonNoIcon,
innerChecks,
raw,
std::move(title),
toggledWhenAll);
container->add(std::move(wrap));
container->widthValue(
) | start_with_next([=](int w)
{
raw->resizeToWidth(w);
}, raw->lifetime());
}
namespace Settings
{
rpl::producer<QString> Ayu::title()
{
return tr::ayu_AyuPreferences();
}
Ayu::Ayu(
QWidget *parent,
not_null<Window::SessionController *> controller)
: Section(parent)
{
setupContent(controller);
}
void Ayu::SetupGhostModeToggle(not_null<Ui::VerticalLayout *> container)
{
auto settings = &AyuSettings::getInstance();
AddSubsectionTitle(container, tr::ayu_GhostEssentialsHeader());
std::vector checkboxes{
NestedEntry{
@ -365,102 +395,13 @@ void Ayu::SetupGhostModeToggle(not_null<Ui::VerticalLayout *> container)
},
};
auto wrap = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container,
object_ptr<Ui::VerticalLayout>(container));
const auto verticalLayout = wrap->entity();
auto innerChecks = std::vector<not_null<Ui::AbstractCheckView *>>();
for (const auto &entry : checkboxes) {
const auto c = addCheckbox(verticalLayout, entry.checkboxLabel, entry.initial);
c->checkedValue(
) | start_with_next([=](bool enabled)
{
entry.callback(enabled);
}, container->lifetime());
innerChecks.push_back(c);
}
const auto raw = wrap.data();
raw->hide(anim::type::instant);
AddInnerToggle(
container,
st::powerSavingButtonNoIcon,
innerChecks,
raw,
tr::ayu_GhostModeToggle(),
true);
container->add(std::move(wrap));
container->widthValue(
) | start_with_next([=](int w)
{
raw->resizeToWidth(w);
}, raw->lifetime());
AddCollapsibleToggle(container, tr::ayu_GhostEssentialsHeader(), checkboxes, true);
}
void Ayu::SetupReadAfterActionToggle(not_null<Ui::VerticalLayout *> container)
{
auto settings = &AyuSettings::getInstance();
const auto widget = object_ptr<Ui::VerticalLayout>(this);
widget->add(
object_ptr<Ui::FlatLabel>(
container,
tr::ayu_MarkReadAfterAction(),
st::rightsHeaderLabel),
st::rightsHeaderMargin);
const auto addCheckbox = [&](
not_null<Ui::VerticalLayout *> verticalLayout,
const QString &label,
const bool isCheckedOrig)
{
const auto checkView = [&]() -> not_null<Ui::AbstractCheckView *>
{
const auto checkbox = verticalLayout->add(
object_ptr<Ui::Checkbox>(
verticalLayout,
label,
isCheckedOrig,
st::settingsCheckbox),
st::powerSavingButton.padding);
const auto button = Ui::CreateChild<Ui::RippleButton>(
verticalLayout.get(),
st::defaultRippleAnimation);
button->stackUnder(checkbox);
combine(
verticalLayout->widthValue(),
checkbox->geometryValue()
) | start_with_next([=](int w, const QRect &r)
{
button->setGeometry(0, r.y(), w, r.height());
}, button->lifetime());
checkbox->setAttribute(Qt::WA_TransparentForMouseEvents);
const auto checkView = checkbox->checkView();
button->setClickedCallback([=]
{
checkView->setChecked(
!checkView->checked(),
anim::type::normal);
});
return checkView;
}();
checkView->checkedChanges(
) | start_with_next([=](bool checked)
{
}, verticalLayout->lifetime());
return checkView;
};
struct NestedEntry
{
QString checkboxLabel;
bool initial;
std::function<void(bool)> callback;
};
std::vector checkboxes{
NestedEntry{
tr::ayu_MarkReadAfterSend(tr::now), settings->markReadAfterSend, [=](bool enabled)
@ -485,44 +426,13 @@ void Ayu::SetupReadAfterActionToggle(not_null<Ui::VerticalLayout *> container)
},
};
auto wrap = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container,
object_ptr<Ui::VerticalLayout>(container));
const auto verticalLayout = wrap->entity();
auto innerChecks = std::vector<not_null<Ui::AbstractCheckView *>>();
for (const auto &entry : checkboxes) {
const auto c = addCheckbox(verticalLayout, entry.checkboxLabel, entry.initial);
c->checkedValue(
) | start_with_next([=](bool enabled)
{
entry.callback(enabled);
}, container->lifetime());
innerChecks.push_back(c);
}
const auto raw = wrap.data();
raw->hide(anim::type::instant);
AddInnerToggle(
container,
st::powerSavingButtonNoIcon,
innerChecks,
raw,
tr::ayu_MarkReadAfterAction(),
false);
container->add(std::move(wrap));
container->widthValue(
) | start_with_next([=](int w)
{
raw->resizeToWidth(w);
}, raw->lifetime());
AddCollapsibleToggle(container, tr::ayu_MarkReadAfterAction(), checkboxes, false);
}
void Ayu::SetupGhostEssentials(not_null<Ui::VerticalLayout *> container)
{
auto settings = &AyuSettings::getInstance();
AddSubsectionTitle(container, tr::ayu_GhostEssentialsHeader());
SetupGhostModeToggle(container);
SetupReadAfterActionToggle(container);
@ -564,7 +474,7 @@ void Ayu::SetupSpyEssentials(not_null<Ui::VerticalLayout *> container)
return (enabled != settings->saveDeletedMessages);
}) | start_with_next([=](bool enabled)
{
settings->set_keepDeletedMessages(enabled);
settings->set_saveDeletedMessages(enabled);
AyuSettings::save();
}, container->lifetime());
@ -580,7 +490,7 @@ void Ayu::SetupSpyEssentials(not_null<Ui::VerticalLayout *> container)
return (enabled != settings->saveMessagesHistory);
}) | start_with_next([=](bool enabled)
{
settings->set_keepMessagesHistory(enabled);
settings->set_saveMessagesHistory(enabled);
AyuSettings::save();
}, container->lifetime());
}
@ -623,6 +533,45 @@ void Ayu::SetupQoLToggles(not_null<Ui::VerticalLayout *> container)
AyuSettings::save();
}, container->lifetime());
AddButtonWithIcon(
container,
tr::ayu_SimpleQuotesAndReplies(),
st::settingsButtonNoIcon
)->toggleOn(
rpl::single(settings->simpleQuotesAndReplies)
)->toggledValue(
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->simpleQuotesAndReplies);
}) | start_with_next([=](bool enabled)
{
settings->set_simpleQuotesAndReplies(enabled);
AyuSettings::save();
}, container->lifetime());
std::vector checkboxes = {
NestedEntry{
tr::ayu_CollapseSimilarChannels(tr::now), settings->collapseSimilarChannels, [=](bool enabled)
{
settings->set_collapseSimilarChannels(enabled);
AyuSettings::save();
}
},
NestedEntry{
tr::ayu_HideSimilarChannelsTab(tr::now), settings->hideSimilarChannels, [=](bool enabled)
{
settings->set_hideSimilarChannels(enabled);
AyuSettings::save();
}
}
};
AddCollapsibleToggle(container, tr::ayu_DisableSimilarChannels(), checkboxes, true);
AddSkip(container);
AddDivider(container);
AddSkip(container);
AddButtonWithIcon(
container,
tr::ayu_DisableNotificationsDelay(),
@ -688,6 +637,9 @@ void Ayu::SetupCustomization(not_null<Ui::VerticalLayout *> container,
SetupAppIcon(container);
AddDivider(container);
AddSkip(container);
auto btn = AddButtonWithLabel(
container,
tr::ayu_DeletedMarkText(),
@ -740,22 +692,6 @@ void Ayu::SetupCustomization(not_null<Ui::VerticalLayout *> container,
AyuSettings::save();
}, container->lifetime());
AddButtonWithIcon(
container,
tr::ayu_SimpleQuotesAndReplies(),
st::settingsButtonNoIcon
)->toggleOn(
rpl::single(settings->simpleQuotesAndReplies)
)->toggledValue(
) | rpl::filter([=](bool enabled)
{
return (enabled != settings->simpleQuotesAndReplies);
}) | start_with_next([=](bool enabled)
{
settings->set_simpleQuotesAndReplies(enabled);
AyuSettings::save();
}, container->lifetime());
AddButtonWithIcon(
container,
tr::ayu_SettingsShowMessageSeconds(),

View file

@ -44,6 +44,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_info.h"
#include "styles/style_boxes.h"
// AyuGram includes
#include "ayu/ayu_settings.h"
namespace Info {
namespace Profile {
@ -155,6 +159,8 @@ object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
using namespace rpl::mappers;
using MediaType = Media::Type;
const auto settings = &AyuSettings::getInstance();
auto content = object_ptr<Ui::VerticalLayout>(parent);
auto tracker = Ui::MultiSlideTracker();
auto addMediaButton = [&](
@ -189,6 +195,10 @@ object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
const auto addSimilarChannelsButton = [&](
not_null<ChannelData*> channel,
const style::icon &icon) {
if (settings->hideSimilarChannels) {
return;
}
auto result = Media::AddSimilarChannelsButton(
content,
_controller,