[Improvement] Restore discussion group button

This commit is contained in:
Eric Kotato 2022-09-11 05:32:38 +03:00 committed by Eric Kotato
parent 94feda0b77
commit b926ac04fd
4 changed files with 184 additions and 8 deletions

View file

@ -2952,6 +2952,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_restart_button" = "Restart"; "lng_restart_button" = "Restart";
"lng_channel_mute" = "Mute"; "lng_channel_mute" = "Mute";
"lng_channel_unmute" = "Unmute"; "lng_channel_unmute" = "Unmute";
"lng_channel_discuss" = "Discuss";
"lng_saved_messages" = "Saved Messages"; "lng_saved_messages" = "Saved Messages";
"lng_saved_short" = "Save"; "lng_saved_short" = "Save";
"lng_saved_forward_here" = "Forward messages here for quick access"; "lng_saved_forward_here" = "Forward messages here for quick access";

View file

@ -838,6 +838,10 @@ historyComposeButton: FlatButton {
color: historyComposeButtonBgRipple; color: historyComposeButtonBgRipple;
} }
} }
historyComposeButtonLabel: FlatLabel(defaultFlatLabel) {
textFg: windowActiveTextFg;
style: semiboldTextStyle;
}
historyUnblock: FlatButton(historyComposeButton) { historyUnblock: FlatButton(historyComposeButton) {
color: attentionButtonFg; color: attentionButtonFg;
overColor: attentionButtonFgOver; overColor: attentionButtonFgOver;

View file

@ -198,6 +198,105 @@ constexpr auto kCommonModifiers = 0
| Qt::ControlModifier; | Qt::ControlModifier;
const auto kPsaAboutPrefix = "cloud_lng_about_psa_"; const auto kPsaAboutPrefix = "cloud_lng_about_psa_";
object_ptr<Ui::FlatButton> SetupDiscussButton(
not_null<QWidget*> parent,
not_null<Window::SessionController*> controller) {
auto result = object_ptr<Ui::FlatButton>(
parent,
QString(),
st::historyComposeButton);
const auto button = result.data();
const auto label = Ui::CreateChild<Ui::FlatLabel>(
button,
tr::lng_channel_discuss() | Ui::Text::ToUpper(),
st::historyComposeButtonLabel);
const auto badge = Ui::CreateChild<Ui::UnreadBadge>(button);
label->show();
controller->activeChatValue(
) | rpl::map([=](Dialogs::Key chat) {
return chat.history();
}) | rpl::map([=](History *history) {
return history ? history->peer->asChannel() : nullptr;
}) | rpl::map([=](ChannelData *channel) -> rpl::producer<ChannelData*> {
if (channel && channel->isBroadcast()) {
return channel->session().changes().peerFlagsValue(
channel,
Data::PeerUpdate::Flag::ChannelLinkedChat
) | rpl::map([=] {
return channel->linkedChat();
});
}
return rpl::single<ChannelData*>(nullptr);
}) | rpl::flatten_latest(
) | rpl::distinct_until_changed(
) | rpl::map([=](ChannelData *chat)
-> rpl::producer<std::tuple<int, bool>> {
if (chat) {
using UpdateFlag = Data::PeerUpdate::Flag;
return rpl::merge(
chat->session().changes().historyUpdates(
Data::HistoryUpdate::Flag::UnreadView
) | rpl::filter([=](const Data::HistoryUpdate &update) {
return (update.history->peer == chat);
}) | rpl::to_empty,
chat->session().changes().peerFlagsValue(
chat,
UpdateFlag::Notifications | UpdateFlag::ChannelAmIn
) | rpl::to_empty
) | rpl::map([=] {
const auto history = chat->amIn()
? chat->owner().historyLoaded(chat)
: nullptr;
return history
? std::make_tuple(
history->chatListBadgesState().unreadCounter,
!history->chatListBadgesState().unreadMuted)
: std::make_tuple(0, false);
});
} else {
return rpl::single(std::make_tuple(0, false));
}
}) | rpl::flatten_latest(
) | rpl::distinct_until_changed(
) | rpl::start_with_next([=](int count, bool active) {
badge->setText(QString::number(count), active);
badge->setVisible(count > 0);
}, badge->lifetime());
rpl::combine(
badge->shownValue(),
badge->widthValue(),
label->widthValue(),
button->widthValue()
) | rpl::start_with_next([=](
bool badgeShown,
int badgeWidth,
int labelWidth,
int width) {
const auto textTop = st::historyComposeButton.textTop;
const auto add = badgeShown
? (textTop + badgeWidth)
: 0;
const auto total = labelWidth + add;
label->moveToLeft((width - total) / 2, textTop, width);
badge->moveToRight((width - total) / 2, textTop, width);
}, button->lifetime());
label->setAttribute(Qt::WA_TransparentForMouseEvents);
badge->setAttribute(Qt::WA_TransparentForMouseEvents);
return result;
}
[[nodiscard]] crl::time CountToastDuration(const TextWithEntities &text) {
return std::clamp(
crl::time(1000) * int(text.text.size()) / 14,
crl::time(1000) * 5,
crl::time(1000) * 8);
}
[[nodiscard]] rpl::producer<PeerData*> ActivePeerValue( [[nodiscard]] rpl::producer<PeerData*> ActivePeerValue(
not_null<Window::SessionController*> controller) { not_null<Window::SessionController*> controller) {
return controller->activeChatValue( return controller->activeChatValue(
@ -256,6 +355,7 @@ HistoryWidget::HistoryWidget(
this, this,
tr::lng_channel_mute(tr::now).toUpper(), tr::lng_channel_mute(tr::now).toUpper(),
st::historyComposeButton) st::historyComposeButton)
, _discuss(SetupDiscussButton(this, controller))
, _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)
@ -334,6 +434,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) {
@ -556,6 +657,7 @@ HistoryWidget::HistoryWidget(
_botStart->hide(); _botStart->hide();
_joinChannel->hide(); _joinChannel->hide();
_muteUnmute->hide(); _muteUnmute->hide();
_discuss->hide();
_reportMessages->hide(); _reportMessages->hide();
initVoiceRecordBar(); initVoiceRecordBar();
@ -3059,12 +3161,30 @@ 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);
if (hasDiscussionGroup()) {
if (_discuss->isHidden()) {
_discuss->clearState();
_discuss->show();
}
} else {
_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();
@ -3116,6 +3236,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();
@ -3227,6 +3348,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) {
@ -4392,6 +4514,22 @@ 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 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;
@ -5374,7 +5512,7 @@ void HistoryWidget::moveFieldControls() {
// (_botMenu.button) (_attachToggle|_replaceMedia) (_sendAs) ---- _inlineResults ------------------------------ _tabbedPanel ------ _fieldBarCancel // (_botMenu.button) (_attachToggle|_replaceMedia) (_sendAs) ---- _inlineResults ------------------------------ _tabbedPanel ------ _fieldBarCancel
// (_attachDocument|_attachPhoto) _field (_ttlInfo) (_scheduled) (_silent|_cmdStart|_kbShow) (_kbHide|_tabbedSelectorToggle) _send // (_attachDocument|_attachPhoto) _field (_ttlInfo) (_scheduled) (_silent|_cmdStart|_kbShow) (_kbHide|_tabbedSelectorToggle) _send
// (_botStart|_unblock|_joinChannel|_muteUnmute|_reportMessages) // (_botStart|_unblock|_joinChannel|{_muteUnmute&_discuss}|_reportMessages)
auto buttonsBottom = bottom - _attachToggle->height(); auto buttonsBottom = bottom - _attachToggle->height();
auto left = st::historySendRight; auto left = st::historySendRight;
@ -5437,12 +5575,36 @@ void HistoryWidget::moveFieldControls() {
_botStart->height()); _botStart->height());
_botStart->setGeometry(fullWidthButtonRect); _botStart->setGeometry(fullWidthButtonRect);
_unblock->setGeometry(fullWidthButtonRect); _unblock->setGeometry(fullWidthButtonRect);
if (hasDiscussionGroup()) {
_joinChannel->setGeometry(myrtlrect(
0,
fullWidthButtonRect.y(),
width() / 2,
fullWidthButtonRect.height()));
_reportMessages->setGeometry(myrtlrect(
0,
fullWidthButtonRect.y(),
width() / 2,
fullWidthButtonRect.height()));
_muteUnmute->setGeometry(myrtlrect(
0,
fullWidthButtonRect.y(),
width() / 2,
fullWidthButtonRect.height()));
_discuss->setGeometry(myrtlrect(
width() / 2,
fullWidthButtonRect.y(),
width() - (width() / 2),
fullWidthButtonRect.height()));
} else {
_joinChannel->setGeometry(fullWidthButtonRect); _joinChannel->setGeometry(fullWidthButtonRect);
_muteUnmute->setGeometry(fullWidthButtonRect); _muteUnmute->setGeometry(fullWidthButtonRect);
_reportMessages->setGeometry(fullWidthButtonRect); _reportMessages->setGeometry(fullWidthButtonRect);
if (_sendRestriction) { if (_sendRestriction) {
_sendRestriction->setGeometry(fullWidthButtonRect); _sendRestriction->setGeometry(fullWidthButtonRect);
} }
}
} }
void HistoryWidget::updateFieldSize() { void HistoryWidget::updateFieldSize() {
@ -5887,6 +6049,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 || joinChannel) && hasDiscussionGroup();
const auto reportMessages = isReportMessages(); const auto reportMessages = isReportMessages();
const auto update = false const auto update = false
|| (_reportMessages->isHidden() == reportMessages) || (_reportMessages->isHidden() == reportMessages)
@ -5897,7 +6060,8 @@ void HistoryWidget::handleHistoryChange(not_null<const History*> history) {
|| (!reportMessages || (!reportMessages
&& !unblock && !unblock
&& !botStart && !botStart
&& _joinChannel->isHidden() == joinChannel) && (_joinChannel->isHidden() == joinChannel
|| _discuss->isHidden() == discuss))
|| (!reportMessages || (!reportMessages
&& !unblock && !unblock
&& !botStart && !botStart
@ -8175,7 +8339,10 @@ void HistoryWidget::handlePeerUpdate() {
} }
if (!_showAnimation) { if (!_showAnimation) {
if (_unblock->isHidden() == isBlocked() if (_unblock->isHidden() == isBlocked()
|| (!isBlocked() && _joinChannel->isHidden() == isJoinChannel())) { || (!isBlocked()
&& _joinChannel->isHidden() == isJoinChannel()
&& _discuss->isHidden() == hasDiscussionGroup())
|| (isMuteUnmute() && _discuss->isHidden() == hasDiscussionGroup())) {
resize = true; resize = true;
} }
if (updateCanSendMessage()) { if (updateCanSendMessage()) {

View file

@ -428,6 +428,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);
@ -759,6 +762,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 };