mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-13 04:37:11 +02:00
feat: channel bottom button configuration
Co-authored-by: Eric Kotato <radrussianrus@gmail.com>
This commit is contained in:
parent
bbeeaa95c0
commit
257b8552f7
6 changed files with 145 additions and 6 deletions
|
@ -5457,6 +5457,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"ayu_SemiTransparentDeletedMessages" = "Translucent Deleted Messages";
|
||||
"ayu_HideNotificationCounters" = "Hide Notification Counters";
|
||||
"ayu_HideAllChats" = "Hide \"All Chats\" Tab";
|
||||
"ayu_ChannelBottomButton" = "Channel Bottom Button";
|
||||
"ayu_ChannelBottomButtonHide" = "Hide";
|
||||
"ayu_ChannelBottomButtonMute" = "Mute";
|
||||
"ayu_ChannelBottomButtonDiscuss" = "Discuss";
|
||||
"ayu_SettingsShowID" = "Show Peer ID";
|
||||
"ayu_SettingsShowID_Hide" = "Hide";
|
||||
"ayu_SettingsShowMessageShot" = "Show Message Shot";
|
||||
|
|
|
@ -251,6 +251,13 @@ AyuGramSettings::AyuGramSettings() {
|
|||
hideNotificationCounters = false;
|
||||
hideAllChatsFolder = false;
|
||||
|
||||
/*
|
||||
* channelBottomButton = 0 means "Hide"
|
||||
* channelBottomButton = 1 means "Mute"/"Unmute"
|
||||
* channelBottomButton = 2 means "Discuss" + fallback to "Mute"/"Unmute"
|
||||
*/
|
||||
channelBottomButton = 2;
|
||||
|
||||
/*
|
||||
* showPeerId = 0 means no ID shown
|
||||
* showPeerId = 1 means ID shown as for Telegram API devs
|
||||
|
@ -448,6 +455,10 @@ void AyuGramSettings::set_hideAllChatsFolder(bool val) {
|
|||
hideAllChatsFolder = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_channelBottomButton(int val) {
|
||||
channelBottomButton = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_showMessageSeconds(bool val) {
|
||||
showMessageSeconds = val;
|
||||
}
|
||||
|
|
|
@ -69,6 +69,8 @@ public:
|
|||
bool hideNotificationCounters;
|
||||
bool hideAllChatsFolder;
|
||||
|
||||
int channelBottomButton;
|
||||
|
||||
int showPeerId;
|
||||
bool showMessageSeconds;
|
||||
bool showMessageShot;
|
||||
|
@ -131,6 +133,8 @@ public:
|
|||
void set_hideNotificationCounters(bool val);
|
||||
void set_hideAllChatsFolder(bool val);
|
||||
|
||||
void set_channelBottomButton(int val);
|
||||
|
||||
void set_showPeerId(int val);
|
||||
void set_showMessageSeconds(bool val);
|
||||
void set_showMessageShot(bool val);
|
||||
|
@ -181,6 +185,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
|
|||
monoFont,
|
||||
hideNotificationCounters,
|
||||
hideAllChatsFolder,
|
||||
channelBottomButton,
|
||||
showPeerId,
|
||||
showMessageSeconds,
|
||||
showMessageShot,
|
||||
|
|
|
@ -343,13 +343,14 @@ void AddCollapsibleToggle(not_null<Ui::VerticalLayout*> container,
|
|||
raw->lifetime());
|
||||
}
|
||||
|
||||
void AddChooseButtonWithIconAndRightText(not_null<Ui::VerticalLayout*> container,
|
||||
void AddChooseButtonWithIconAndRightTextInner(not_null<Ui::VerticalLayout*> container,
|
||||
not_null<Window::SessionController*> controller,
|
||||
int initialState,
|
||||
std::vector<QString> options,
|
||||
rpl::producer<QString> text,
|
||||
rpl::producer<QString> boxTitle,
|
||||
const style::icon &icon,
|
||||
const style::SettingsButton & st,
|
||||
Settings::IconDescriptor && descriptor,
|
||||
const Fn<void(int)> &setter) {
|
||||
auto reactiveVal = container->lifetime().make_state<rpl::variable<int>>(initialState);
|
||||
|
||||
|
@ -363,8 +364,8 @@ void AddChooseButtonWithIconAndRightText(not_null<Ui::VerticalLayout*> container
|
|||
container,
|
||||
std::move(text),
|
||||
rightTextReactive,
|
||||
st::settingsButton,
|
||||
{&icon})->addClickHandler(
|
||||
st,
|
||||
std::move(descriptor))->addClickHandler(
|
||||
[=]
|
||||
{
|
||||
controller->show(Box(
|
||||
|
@ -387,6 +388,45 @@ void AddChooseButtonWithIconAndRightText(not_null<Ui::VerticalLayout*> container
|
|||
});
|
||||
}
|
||||
|
||||
void AddChooseButtonWithIconAndRightText(not_null<Ui::VerticalLayout*> container,
|
||||
not_null<Window::SessionController*> controller,
|
||||
int initialState,
|
||||
std::vector<QString> options,
|
||||
rpl::producer<QString> text,
|
||||
rpl::producer<QString> boxTitle,
|
||||
const style::icon &icon,
|
||||
const Fn<void(int)> &setter) {
|
||||
AddChooseButtonWithIconAndRightTextInner(
|
||||
container,
|
||||
controller,
|
||||
initialState,
|
||||
options,
|
||||
std::move(text),
|
||||
std::move(boxTitle),
|
||||
st::settingsButton,
|
||||
{&icon},
|
||||
setter);
|
||||
}
|
||||
|
||||
void AddChooseButtonWithIconAndRightText(not_null<Ui::VerticalLayout*> container,
|
||||
not_null<Window::SessionController*> controller,
|
||||
int initialState,
|
||||
std::vector<QString> options,
|
||||
rpl::producer<QString> text,
|
||||
rpl::producer<QString> boxTitle,
|
||||
const Fn<void(int)> &setter) {
|
||||
AddChooseButtonWithIconAndRightTextInner(
|
||||
container,
|
||||
controller,
|
||||
initialState,
|
||||
options,
|
||||
std::move(text),
|
||||
std::move(boxTitle),
|
||||
st::settingsButtonNoIcon,
|
||||
{},
|
||||
setter);
|
||||
}
|
||||
|
||||
namespace Settings {
|
||||
|
||||
rpl::producer<QString> Ayu::title() {
|
||||
|
@ -1205,6 +1245,29 @@ void SetupFolderSettings(not_null<Ui::VerticalLayout*> container) {
|
|||
container->lifetime());
|
||||
}
|
||||
|
||||
void SetupChannelSettings(not_null<Ui::VerticalLayout*> container, not_null<Window::SessionController*> controller) {
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
|
||||
const auto options = std::vector{
|
||||
tr::ayu_ChannelBottomButtonHide(tr::now),
|
||||
tr::ayu_ChannelBottomButtonMute(tr::now),
|
||||
tr::ayu_ChannelBottomButtonDiscuss(tr::now),
|
||||
};
|
||||
|
||||
AddChooseButtonWithIconAndRightText(
|
||||
container,
|
||||
controller,
|
||||
settings->channelBottomButton,
|
||||
options,
|
||||
tr::ayu_ChannelBottomButton(),
|
||||
tr::ayu_ChannelBottomButton(),
|
||||
[=](int index)
|
||||
{
|
||||
settings->set_channelBottomButton(index);
|
||||
AyuSettings::save();
|
||||
});
|
||||
}
|
||||
|
||||
void SetupNerdSettings(not_null<Ui::VerticalLayout*> container, not_null<Window::SessionController*> controller) {
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
|
||||
|
@ -1318,6 +1381,11 @@ void SetupCustomization(not_null<Ui::VerticalLayout*> container,
|
|||
AddSkip(container);
|
||||
AddDivider(container);
|
||||
|
||||
AddSkip(container);
|
||||
SetupChannelSettings(container, controller);
|
||||
AddSkip(container);
|
||||
AddDivider(container);
|
||||
|
||||
AddSkip(container);
|
||||
SetupNerdSettings(container, controller);
|
||||
|
||||
|
|
|
@ -262,6 +262,9 @@ HistoryWidget::HistoryWidget(
|
|||
this,
|
||||
tr::lng_channel_mute(tr::now).toUpper(),
|
||||
st::historyComposeButton)
|
||||
, _discuss(this,
|
||||
tr::ayu_ChannelBottomButtonDiscuss(tr::now).toUpper(),
|
||||
st::historyComposeButton)
|
||||
, _reportMessages(this, QString(), st::historyComposeButton)
|
||||
, _attachToggle(this, st::historyAttach)
|
||||
, _tabbedSelectorToggle(this, st::historyAttachEmoji)
|
||||
|
@ -353,6 +356,7 @@ HistoryWidget::HistoryWidget(
|
|||
_botStart->addClickHandler([=] { sendBotStartCommand(); });
|
||||
_joinChannel->addClickHandler([=] { joinChannel(); });
|
||||
_muteUnmute->addClickHandler([=] { toggleMuteUnmute(); });
|
||||
_discuss->addClickHandler([=] { goToDiscussionGroup(); });
|
||||
_reportMessages->addClickHandler([=] { reportSelectedMessages(); });
|
||||
_field->submits(
|
||||
) | rpl::start_with_next([=](Qt::KeyboardModifiers modifiers) {
|
||||
|
@ -573,6 +577,7 @@ HistoryWidget::HistoryWidget(
|
|||
_botStart->hide();
|
||||
_joinChannel->hide();
|
||||
_muteUnmute->hide();
|
||||
_discuss->hide();
|
||||
_reportMessages->hide();
|
||||
|
||||
initVoiceRecordBar();
|
||||
|
@ -2978,12 +2983,23 @@ void HistoryWidget::updateControlsVisibility() {
|
|||
toggle(_reportMessages);
|
||||
} else if (isBlocked()) {
|
||||
toggle(_unblock);
|
||||
_discuss->hide();
|
||||
} else if (isJoinChannel()) {
|
||||
toggle(_joinChannel);
|
||||
_discuss->hide();
|
||||
} else if (isMuteUnmute()) {
|
||||
toggle(_muteUnmute);
|
||||
if (hasDiscussionGroup()) {
|
||||
if (_discuss->isHidden()) {
|
||||
_discuss->clearState();
|
||||
_discuss->show();
|
||||
}
|
||||
} else {
|
||||
_discuss->hide();
|
||||
}
|
||||
} else if (isBotStart()) {
|
||||
toggle(_botStart);
|
||||
_discuss->hide();
|
||||
}
|
||||
_kbShown = false;
|
||||
_fieldAutocomplete->hide();
|
||||
|
@ -3035,6 +3051,7 @@ void HistoryWidget::updateControlsVisibility() {
|
|||
_botStart->hide();
|
||||
_joinChannel->hide();
|
||||
_muteUnmute->hide();
|
||||
_discuss->hide();
|
||||
_reportMessages->hide();
|
||||
_send->show();
|
||||
updateSendButtonType();
|
||||
|
@ -3146,6 +3163,7 @@ void HistoryWidget::updateControlsVisibility() {
|
|||
_botStart->hide();
|
||||
_joinChannel->hide();
|
||||
_muteUnmute->hide();
|
||||
_discuss->hide();
|
||||
_reportMessages->hide();
|
||||
_attachToggle->hide();
|
||||
if (_silent) {
|
||||
|
@ -4346,6 +4364,27 @@ void HistoryWidget::toggleMuteUnmute() {
|
|||
session().data().notifySettings().update(_peer, muteForSeconds);
|
||||
}
|
||||
|
||||
void HistoryWidget::goToDiscussionGroup() {
|
||||
const auto channel = _peer ? _peer->asChannel() : nullptr;
|
||||
const auto chat = channel ? channel->linkedChat() : nullptr;
|
||||
if (!chat) {
|
||||
return;
|
||||
}
|
||||
controller()->showPeerHistory(chat, Window::SectionShow::Way::Forward);
|
||||
}
|
||||
|
||||
bool HistoryWidget::hasDiscussionGroup() const {
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
if (settings->channelBottomButton != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto channel = _peer ? _peer->asChannel() : nullptr;
|
||||
return channel
|
||||
&& channel->isBroadcast()
|
||||
&& (channel->flags() & ChannelDataFlag::HasLink);
|
||||
}
|
||||
|
||||
void HistoryWidget::reportSelectedMessages() {
|
||||
if (!_list || !_chooseForReport || !_list->getSelectionState().count) {
|
||||
return;
|
||||
|
@ -4884,6 +4923,11 @@ bool HistoryWidget::isChoosingTheme() const {
|
|||
}
|
||||
|
||||
bool HistoryWidget::isMuteUnmute() const {
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
if (settings->channelBottomButton == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return _peer
|
||||
&& ((_peer->isBroadcast() && !_peer->asChannel()->canPostMessages())
|
||||
|| (_peer->isGigagroup() && !Data::CanSendAnything(_peer))
|
||||
|
@ -5392,6 +5436,7 @@ void HistoryWidget::moveFieldControls() {
|
|||
_unblock->setGeometry(fullWidthButtonRect);
|
||||
_joinChannel->setGeometry(fullWidthButtonRect);
|
||||
_muteUnmute->setGeometry(fullWidthButtonRect);
|
||||
_discuss->setGeometry(fullWidthButtonRect);
|
||||
_reportMessages->setGeometry(fullWidthButtonRect);
|
||||
if (_sendRestriction) {
|
||||
_sendRestriction->setGeometry(fullWidthButtonRect);
|
||||
|
@ -5842,6 +5887,7 @@ void HistoryWidget::handleHistoryChange(not_null<const History*> history) {
|
|||
const auto botStart = isBotStart();
|
||||
const auto joinChannel = isJoinChannel();
|
||||
const auto muteUnmute = isMuteUnmute();
|
||||
const auto discuss = muteUnmute && hasDiscussionGroup();
|
||||
const auto reportMessages = isReportMessages();
|
||||
const auto update = false
|
||||
|| (_reportMessages->isHidden() == reportMessages)
|
||||
|
@ -5857,7 +5903,7 @@ void HistoryWidget::handleHistoryChange(not_null<const History*> history) {
|
|||
&& !unblock
|
||||
&& !botStart
|
||||
&& !joinChannel
|
||||
&& _muteUnmute->isHidden() == muteUnmute);
|
||||
&& (_muteUnmute->isHidden() == muteUnmute || _discuss->isHidden() == discuss));
|
||||
if (update) {
|
||||
updateControlsVisibility();
|
||||
updateControlsGeometry();
|
||||
|
@ -8009,7 +8055,8 @@ void HistoryWidget::handlePeerUpdate() {
|
|||
}
|
||||
if (!_showAnimation) {
|
||||
if (_unblock->isHidden() == isBlocked()
|
||||
|| (!isBlocked() && _joinChannel->isHidden() == isJoinChannel())) {
|
||||
|| (!isBlocked() && _joinChannel->isHidden() == isJoinChannel())
|
||||
|| (isMuteUnmute() && _discuss->isHidden() == hasDiscussionGroup())) {
|
||||
resize = true;
|
||||
}
|
||||
if (updateCanSendMessage()) {
|
||||
|
|
|
@ -424,6 +424,9 @@ private:
|
|||
void unblockUser();
|
||||
void sendBotStartCommand();
|
||||
void joinChannel();
|
||||
void goToDiscussionGroup();
|
||||
|
||||
[[nodiscard]] bool hasDiscussionGroup() const;
|
||||
|
||||
void supportInitAutocomplete();
|
||||
void supportInsertText(const QString &text);
|
||||
|
@ -755,6 +758,7 @@ private:
|
|||
object_ptr<Ui::FlatButton> _botStart;
|
||||
object_ptr<Ui::FlatButton> _joinChannel;
|
||||
object_ptr<Ui::FlatButton> _muteUnmute;
|
||||
object_ptr<Ui::FlatButton> _discuss;
|
||||
object_ptr<Ui::FlatButton> _reportMessages;
|
||||
struct {
|
||||
object_ptr<Ui::RoundButton> button = { nullptr };
|
||||
|
|
Loading…
Add table
Reference in a new issue