mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 22:54:01 +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_SemiTransparentDeletedMessages" = "Translucent Deleted Messages";
|
||||||
"ayu_HideNotificationCounters" = "Hide Notification Counters";
|
"ayu_HideNotificationCounters" = "Hide Notification Counters";
|
||||||
"ayu_HideAllChats" = "Hide \"All Chats\" Tab";
|
"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" = "Show Peer ID";
|
||||||
"ayu_SettingsShowID_Hide" = "Hide";
|
"ayu_SettingsShowID_Hide" = "Hide";
|
||||||
"ayu_SettingsShowMessageShot" = "Show Message Shot";
|
"ayu_SettingsShowMessageShot" = "Show Message Shot";
|
||||||
|
|
|
@ -251,6 +251,13 @@ AyuGramSettings::AyuGramSettings() {
|
||||||
hideNotificationCounters = false;
|
hideNotificationCounters = false;
|
||||||
hideAllChatsFolder = 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 = 0 means no ID shown
|
||||||
* showPeerId = 1 means ID shown as for Telegram API devs
|
* showPeerId = 1 means ID shown as for Telegram API devs
|
||||||
|
@ -448,6 +455,10 @@ void AyuGramSettings::set_hideAllChatsFolder(bool val) {
|
||||||
hideAllChatsFolder = val;
|
hideAllChatsFolder = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AyuGramSettings::set_channelBottomButton(int val) {
|
||||||
|
channelBottomButton = val;
|
||||||
|
}
|
||||||
|
|
||||||
void AyuGramSettings::set_showMessageSeconds(bool val) {
|
void AyuGramSettings::set_showMessageSeconds(bool val) {
|
||||||
showMessageSeconds = val;
|
showMessageSeconds = val;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,8 @@ public:
|
||||||
bool hideNotificationCounters;
|
bool hideNotificationCounters;
|
||||||
bool hideAllChatsFolder;
|
bool hideAllChatsFolder;
|
||||||
|
|
||||||
|
int channelBottomButton;
|
||||||
|
|
||||||
int showPeerId;
|
int showPeerId;
|
||||||
bool showMessageSeconds;
|
bool showMessageSeconds;
|
||||||
bool showMessageShot;
|
bool showMessageShot;
|
||||||
|
@ -131,6 +133,8 @@ public:
|
||||||
void set_hideNotificationCounters(bool val);
|
void set_hideNotificationCounters(bool val);
|
||||||
void set_hideAllChatsFolder(bool val);
|
void set_hideAllChatsFolder(bool val);
|
||||||
|
|
||||||
|
void set_channelBottomButton(int val);
|
||||||
|
|
||||||
void set_showPeerId(int val);
|
void set_showPeerId(int val);
|
||||||
void set_showMessageSeconds(bool val);
|
void set_showMessageSeconds(bool val);
|
||||||
void set_showMessageShot(bool val);
|
void set_showMessageShot(bool val);
|
||||||
|
@ -181,6 +185,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
|
||||||
monoFont,
|
monoFont,
|
||||||
hideNotificationCounters,
|
hideNotificationCounters,
|
||||||
hideAllChatsFolder,
|
hideAllChatsFolder,
|
||||||
|
channelBottomButton,
|
||||||
showPeerId,
|
showPeerId,
|
||||||
showMessageSeconds,
|
showMessageSeconds,
|
||||||
showMessageShot,
|
showMessageShot,
|
||||||
|
|
|
@ -343,13 +343,14 @@ void AddCollapsibleToggle(not_null<Ui::VerticalLayout*> container,
|
||||||
raw->lifetime());
|
raw->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddChooseButtonWithIconAndRightText(not_null<Ui::VerticalLayout*> container,
|
void AddChooseButtonWithIconAndRightTextInner(not_null<Ui::VerticalLayout*> container,
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
int initialState,
|
int initialState,
|
||||||
std::vector<QString> options,
|
std::vector<QString> options,
|
||||||
rpl::producer<QString> text,
|
rpl::producer<QString> text,
|
||||||
rpl::producer<QString> boxTitle,
|
rpl::producer<QString> boxTitle,
|
||||||
const style::icon &icon,
|
const style::SettingsButton & st,
|
||||||
|
Settings::IconDescriptor && descriptor,
|
||||||
const Fn<void(int)> &setter) {
|
const Fn<void(int)> &setter) {
|
||||||
auto reactiveVal = container->lifetime().make_state<rpl::variable<int>>(initialState);
|
auto reactiveVal = container->lifetime().make_state<rpl::variable<int>>(initialState);
|
||||||
|
|
||||||
|
@ -363,8 +364,8 @@ void AddChooseButtonWithIconAndRightText(not_null<Ui::VerticalLayout*> container
|
||||||
container,
|
container,
|
||||||
std::move(text),
|
std::move(text),
|
||||||
rightTextReactive,
|
rightTextReactive,
|
||||||
st::settingsButton,
|
st,
|
||||||
{&icon})->addClickHandler(
|
std::move(descriptor))->addClickHandler(
|
||||||
[=]
|
[=]
|
||||||
{
|
{
|
||||||
controller->show(Box(
|
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 {
|
namespace Settings {
|
||||||
|
|
||||||
rpl::producer<QString> Ayu::title() {
|
rpl::producer<QString> Ayu::title() {
|
||||||
|
@ -1205,6 +1245,29 @@ void SetupFolderSettings(not_null<Ui::VerticalLayout*> container) {
|
||||||
container->lifetime());
|
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) {
|
void SetupNerdSettings(not_null<Ui::VerticalLayout*> container, not_null<Window::SessionController*> controller) {
|
||||||
auto settings = &AyuSettings::getInstance();
|
auto settings = &AyuSettings::getInstance();
|
||||||
|
|
||||||
|
@ -1318,6 +1381,11 @@ void SetupCustomization(not_null<Ui::VerticalLayout*> container,
|
||||||
AddSkip(container);
|
AddSkip(container);
|
||||||
AddDivider(container);
|
AddDivider(container);
|
||||||
|
|
||||||
|
AddSkip(container);
|
||||||
|
SetupChannelSettings(container, controller);
|
||||||
|
AddSkip(container);
|
||||||
|
AddDivider(container);
|
||||||
|
|
||||||
AddSkip(container);
|
AddSkip(container);
|
||||||
SetupNerdSettings(container, controller);
|
SetupNerdSettings(container, controller);
|
||||||
|
|
||||||
|
|
|
@ -262,6 +262,9 @@ HistoryWidget::HistoryWidget(
|
||||||
this,
|
this,
|
||||||
tr::lng_channel_mute(tr::now).toUpper(),
|
tr::lng_channel_mute(tr::now).toUpper(),
|
||||||
st::historyComposeButton)
|
st::historyComposeButton)
|
||||||
|
, _discuss(this,
|
||||||
|
tr::ayu_ChannelBottomButtonDiscuss(tr::now).toUpper(),
|
||||||
|
st::historyComposeButton)
|
||||||
, _reportMessages(this, QString(), st::historyComposeButton)
|
, _reportMessages(this, QString(), st::historyComposeButton)
|
||||||
, _attachToggle(this, st::historyAttach)
|
, _attachToggle(this, st::historyAttach)
|
||||||
, _tabbedSelectorToggle(this, st::historyAttachEmoji)
|
, _tabbedSelectorToggle(this, st::historyAttachEmoji)
|
||||||
|
@ -353,6 +356,7 @@ HistoryWidget::HistoryWidget(
|
||||||
_botStart->addClickHandler([=] { sendBotStartCommand(); });
|
_botStart->addClickHandler([=] { sendBotStartCommand(); });
|
||||||
_joinChannel->addClickHandler([=] { joinChannel(); });
|
_joinChannel->addClickHandler([=] { joinChannel(); });
|
||||||
_muteUnmute->addClickHandler([=] { toggleMuteUnmute(); });
|
_muteUnmute->addClickHandler([=] { toggleMuteUnmute(); });
|
||||||
|
_discuss->addClickHandler([=] { goToDiscussionGroup(); });
|
||||||
_reportMessages->addClickHandler([=] { reportSelectedMessages(); });
|
_reportMessages->addClickHandler([=] { reportSelectedMessages(); });
|
||||||
_field->submits(
|
_field->submits(
|
||||||
) | rpl::start_with_next([=](Qt::KeyboardModifiers modifiers) {
|
) | rpl::start_with_next([=](Qt::KeyboardModifiers modifiers) {
|
||||||
|
@ -573,6 +577,7 @@ HistoryWidget::HistoryWidget(
|
||||||
_botStart->hide();
|
_botStart->hide();
|
||||||
_joinChannel->hide();
|
_joinChannel->hide();
|
||||||
_muteUnmute->hide();
|
_muteUnmute->hide();
|
||||||
|
_discuss->hide();
|
||||||
_reportMessages->hide();
|
_reportMessages->hide();
|
||||||
|
|
||||||
initVoiceRecordBar();
|
initVoiceRecordBar();
|
||||||
|
@ -2978,12 +2983,23 @@ void HistoryWidget::updateControlsVisibility() {
|
||||||
toggle(_reportMessages);
|
toggle(_reportMessages);
|
||||||
} else if (isBlocked()) {
|
} else if (isBlocked()) {
|
||||||
toggle(_unblock);
|
toggle(_unblock);
|
||||||
|
_discuss->hide();
|
||||||
} else if (isJoinChannel()) {
|
} else if (isJoinChannel()) {
|
||||||
toggle(_joinChannel);
|
toggle(_joinChannel);
|
||||||
|
_discuss->hide();
|
||||||
} else if (isMuteUnmute()) {
|
} else if (isMuteUnmute()) {
|
||||||
toggle(_muteUnmute);
|
toggle(_muteUnmute);
|
||||||
|
if (hasDiscussionGroup()) {
|
||||||
|
if (_discuss->isHidden()) {
|
||||||
|
_discuss->clearState();
|
||||||
|
_discuss->show();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_discuss->hide();
|
||||||
|
}
|
||||||
} else if (isBotStart()) {
|
} else if (isBotStart()) {
|
||||||
toggle(_botStart);
|
toggle(_botStart);
|
||||||
|
_discuss->hide();
|
||||||
}
|
}
|
||||||
_kbShown = false;
|
_kbShown = false;
|
||||||
_fieldAutocomplete->hide();
|
_fieldAutocomplete->hide();
|
||||||
|
@ -3035,6 +3051,7 @@ void HistoryWidget::updateControlsVisibility() {
|
||||||
_botStart->hide();
|
_botStart->hide();
|
||||||
_joinChannel->hide();
|
_joinChannel->hide();
|
||||||
_muteUnmute->hide();
|
_muteUnmute->hide();
|
||||||
|
_discuss->hide();
|
||||||
_reportMessages->hide();
|
_reportMessages->hide();
|
||||||
_send->show();
|
_send->show();
|
||||||
updateSendButtonType();
|
updateSendButtonType();
|
||||||
|
@ -3146,6 +3163,7 @@ void HistoryWidget::updateControlsVisibility() {
|
||||||
_botStart->hide();
|
_botStart->hide();
|
||||||
_joinChannel->hide();
|
_joinChannel->hide();
|
||||||
_muteUnmute->hide();
|
_muteUnmute->hide();
|
||||||
|
_discuss->hide();
|
||||||
_reportMessages->hide();
|
_reportMessages->hide();
|
||||||
_attachToggle->hide();
|
_attachToggle->hide();
|
||||||
if (_silent) {
|
if (_silent) {
|
||||||
|
@ -4346,6 +4364,27 @@ void HistoryWidget::toggleMuteUnmute() {
|
||||||
session().data().notifySettings().update(_peer, muteForSeconds);
|
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() {
|
void HistoryWidget::reportSelectedMessages() {
|
||||||
if (!_list || !_chooseForReport || !_list->getSelectionState().count) {
|
if (!_list || !_chooseForReport || !_list->getSelectionState().count) {
|
||||||
return;
|
return;
|
||||||
|
@ -4884,6 +4923,11 @@ bool HistoryWidget::isChoosingTheme() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HistoryWidget::isMuteUnmute() const {
|
bool HistoryWidget::isMuteUnmute() const {
|
||||||
|
const auto settings = &AyuSettings::getInstance();
|
||||||
|
if (settings->channelBottomButton == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return _peer
|
return _peer
|
||||||
&& ((_peer->isBroadcast() && !_peer->asChannel()->canPostMessages())
|
&& ((_peer->isBroadcast() && !_peer->asChannel()->canPostMessages())
|
||||||
|| (_peer->isGigagroup() && !Data::CanSendAnything(_peer))
|
|| (_peer->isGigagroup() && !Data::CanSendAnything(_peer))
|
||||||
|
@ -5392,6 +5436,7 @@ void HistoryWidget::moveFieldControls() {
|
||||||
_unblock->setGeometry(fullWidthButtonRect);
|
_unblock->setGeometry(fullWidthButtonRect);
|
||||||
_joinChannel->setGeometry(fullWidthButtonRect);
|
_joinChannel->setGeometry(fullWidthButtonRect);
|
||||||
_muteUnmute->setGeometry(fullWidthButtonRect);
|
_muteUnmute->setGeometry(fullWidthButtonRect);
|
||||||
|
_discuss->setGeometry(fullWidthButtonRect);
|
||||||
_reportMessages->setGeometry(fullWidthButtonRect);
|
_reportMessages->setGeometry(fullWidthButtonRect);
|
||||||
if (_sendRestriction) {
|
if (_sendRestriction) {
|
||||||
_sendRestriction->setGeometry(fullWidthButtonRect);
|
_sendRestriction->setGeometry(fullWidthButtonRect);
|
||||||
|
@ -5842,6 +5887,7 @@ void HistoryWidget::handleHistoryChange(not_null<const History*> history) {
|
||||||
const auto botStart = isBotStart();
|
const auto botStart = isBotStart();
|
||||||
const auto joinChannel = isJoinChannel();
|
const auto joinChannel = isJoinChannel();
|
||||||
const auto muteUnmute = isMuteUnmute();
|
const auto muteUnmute = isMuteUnmute();
|
||||||
|
const auto discuss = muteUnmute && hasDiscussionGroup();
|
||||||
const auto reportMessages = isReportMessages();
|
const auto reportMessages = isReportMessages();
|
||||||
const auto update = false
|
const auto update = false
|
||||||
|| (_reportMessages->isHidden() == reportMessages)
|
|| (_reportMessages->isHidden() == reportMessages)
|
||||||
|
@ -5857,7 +5903,7 @@ void HistoryWidget::handleHistoryChange(not_null<const History*> history) {
|
||||||
&& !unblock
|
&& !unblock
|
||||||
&& !botStart
|
&& !botStart
|
||||||
&& !joinChannel
|
&& !joinChannel
|
||||||
&& _muteUnmute->isHidden() == muteUnmute);
|
&& (_muteUnmute->isHidden() == muteUnmute || _discuss->isHidden() == discuss));
|
||||||
if (update) {
|
if (update) {
|
||||||
updateControlsVisibility();
|
updateControlsVisibility();
|
||||||
updateControlsGeometry();
|
updateControlsGeometry();
|
||||||
|
@ -8009,7 +8055,8 @@ void HistoryWidget::handlePeerUpdate() {
|
||||||
}
|
}
|
||||||
if (!_showAnimation) {
|
if (!_showAnimation) {
|
||||||
if (_unblock->isHidden() == isBlocked()
|
if (_unblock->isHidden() == isBlocked()
|
||||||
|| (!isBlocked() && _joinChannel->isHidden() == isJoinChannel())) {
|
|| (!isBlocked() && _joinChannel->isHidden() == isJoinChannel())
|
||||||
|
|| (isMuteUnmute() && _discuss->isHidden() == hasDiscussionGroup())) {
|
||||||
resize = true;
|
resize = true;
|
||||||
}
|
}
|
||||||
if (updateCanSendMessage()) {
|
if (updateCanSendMessage()) {
|
||||||
|
|
|
@ -424,6 +424,9 @@ private:
|
||||||
void unblockUser();
|
void unblockUser();
|
||||||
void sendBotStartCommand();
|
void sendBotStartCommand();
|
||||||
void joinChannel();
|
void joinChannel();
|
||||||
|
void goToDiscussionGroup();
|
||||||
|
|
||||||
|
[[nodiscard]] bool hasDiscussionGroup() const;
|
||||||
|
|
||||||
void supportInitAutocomplete();
|
void supportInitAutocomplete();
|
||||||
void supportInsertText(const QString &text);
|
void supportInsertText(const QString &text);
|
||||||
|
@ -755,6 +758,7 @@ private:
|
||||||
object_ptr<Ui::FlatButton> _botStart;
|
object_ptr<Ui::FlatButton> _botStart;
|
||||||
object_ptr<Ui::FlatButton> _joinChannel;
|
object_ptr<Ui::FlatButton> _joinChannel;
|
||||||
object_ptr<Ui::FlatButton> _muteUnmute;
|
object_ptr<Ui::FlatButton> _muteUnmute;
|
||||||
|
object_ptr<Ui::FlatButton> _discuss;
|
||||||
object_ptr<Ui::FlatButton> _reportMessages;
|
object_ptr<Ui::FlatButton> _reportMessages;
|
||||||
struct {
|
struct {
|
||||||
object_ptr<Ui::RoundButton> button = { nullptr };
|
object_ptr<Ui::RoundButton> button = { nullptr };
|
||||||
|
|
Loading…
Add table
Reference in a new issue