[Improvement] Restore discussion group button
This commit is contained in:
parent
53b835af46
commit
ada490e74e
4 changed files with 184 additions and 8 deletions
|
|
@ -2952,6 +2952,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_restart_button" = "Restart";
|
||||
"lng_channel_mute" = "Mute";
|
||||
"lng_channel_unmute" = "Unmute";
|
||||
"lng_channel_discuss" = "Discuss";
|
||||
"lng_saved_messages" = "Saved Messages";
|
||||
"lng_saved_short" = "Save";
|
||||
"lng_saved_forward_here" = "Forward messages here for quick access";
|
||||
|
|
|
|||
|
|
@ -838,6 +838,10 @@ historyComposeButton: FlatButton {
|
|||
color: historyComposeButtonBgRipple;
|
||||
}
|
||||
}
|
||||
historyComposeButtonLabel: FlatLabel(defaultFlatLabel) {
|
||||
textFg: windowActiveTextFg;
|
||||
style: semiboldTextStyle;
|
||||
}
|
||||
historyUnblock: FlatButton(historyComposeButton) {
|
||||
color: attentionButtonFg;
|
||||
overColor: attentionButtonFgOver;
|
||||
|
|
|
|||
|
|
@ -198,6 +198,105 @@ constexpr auto kCommonModifiers = 0
|
|||
| Qt::ControlModifier;
|
||||
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(
|
||||
not_null<Window::SessionController*> controller) {
|
||||
return controller->activeChatValue(
|
||||
|
|
@ -256,6 +355,7 @@ HistoryWidget::HistoryWidget(
|
|||
this,
|
||||
tr::lng_channel_mute(tr::now).toUpper(),
|
||||
st::historyComposeButton)
|
||||
, _discuss(SetupDiscussButton(this, controller))
|
||||
, _reportMessages(this, QString(), st::historyComposeButton)
|
||||
, _attachToggle(this, st::historyAttach)
|
||||
, _tabbedSelectorToggle(this, st::historyAttachEmoji)
|
||||
|
|
@ -334,6 +434,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) {
|
||||
|
|
@ -556,6 +657,7 @@ HistoryWidget::HistoryWidget(
|
|||
_botStart->hide();
|
||||
_joinChannel->hide();
|
||||
_muteUnmute->hide();
|
||||
_discuss->hide();
|
||||
_reportMessages->hide();
|
||||
|
||||
initVoiceRecordBar();
|
||||
|
|
@ -3059,12 +3161,30 @@ void HistoryWidget::updateControlsVisibility() {
|
|||
toggle(_reportMessages);
|
||||
} else if (isBlocked()) {
|
||||
toggle(_unblock);
|
||||
_discuss->hide();
|
||||
} else if (isJoinChannel()) {
|
||||
toggle(_joinChannel);
|
||||
if (hasDiscussionGroup()) {
|
||||
if (_discuss->isHidden()) {
|
||||
_discuss->clearState();
|
||||
_discuss->show();
|
||||
}
|
||||
} else {
|
||||
_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();
|
||||
|
|
@ -3116,6 +3236,7 @@ void HistoryWidget::updateControlsVisibility() {
|
|||
_botStart->hide();
|
||||
_joinChannel->hide();
|
||||
_muteUnmute->hide();
|
||||
_discuss->hide();
|
||||
_reportMessages->hide();
|
||||
_send->show();
|
||||
updateSendButtonType();
|
||||
|
|
@ -3227,6 +3348,7 @@ void HistoryWidget::updateControlsVisibility() {
|
|||
_botStart->hide();
|
||||
_joinChannel->hide();
|
||||
_muteUnmute->hide();
|
||||
_discuss->hide();
|
||||
_reportMessages->hide();
|
||||
_attachToggle->hide();
|
||||
if (_silent) {
|
||||
|
|
@ -4392,6 +4514,22 @@ 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 channel = _peer ? _peer->asChannel() : nullptr;
|
||||
return channel
|
||||
&& channel->isBroadcast()
|
||||
&& (channel->flags() & ChannelDataFlag::HasLink);
|
||||
}
|
||||
|
||||
void HistoryWidget::reportSelectedMessages() {
|
||||
if (!_list || !_chooseForReport || !_list->getSelectionState().count) {
|
||||
return;
|
||||
|
|
@ -5374,7 +5512,7 @@ void HistoryWidget::moveFieldControls() {
|
|||
|
||||
// (_botMenu.button) (_attachToggle|_replaceMedia) (_sendAs) ---- _inlineResults ------------------------------ _tabbedPanel ------ _fieldBarCancel
|
||||
// (_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 left = st::historySendRight;
|
||||
|
|
@ -5437,6 +5575,29 @@ void HistoryWidget::moveFieldControls() {
|
|||
_botStart->height());
|
||||
_botStart->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);
|
||||
_muteUnmute->setGeometry(fullWidthButtonRect);
|
||||
_reportMessages->setGeometry(fullWidthButtonRect);
|
||||
|
|
@ -5444,6 +5605,7 @@ void HistoryWidget::moveFieldControls() {
|
|||
_sendRestriction->setGeometry(fullWidthButtonRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryWidget::updateFieldSize() {
|
||||
const auto kbShowShown = _history && !_kbShown && _keyboard->hasMarkup();
|
||||
|
|
@ -5887,6 +6049,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 || joinChannel) && hasDiscussionGroup();
|
||||
const auto reportMessages = isReportMessages();
|
||||
const auto update = false
|
||||
|| (_reportMessages->isHidden() == reportMessages)
|
||||
|
|
@ -5897,7 +6060,8 @@ void HistoryWidget::handleHistoryChange(not_null<const History*> history) {
|
|||
|| (!reportMessages
|
||||
&& !unblock
|
||||
&& !botStart
|
||||
&& _joinChannel->isHidden() == joinChannel)
|
||||
&& (_joinChannel->isHidden() == joinChannel
|
||||
|| _discuss->isHidden() == discuss))
|
||||
|| (!reportMessages
|
||||
&& !unblock
|
||||
&& !botStart
|
||||
|
|
@ -8175,7 +8339,10 @@ void HistoryWidget::handlePeerUpdate() {
|
|||
}
|
||||
if (!_showAnimation) {
|
||||
if (_unblock->isHidden() == isBlocked()
|
||||
|| (!isBlocked() && _joinChannel->isHidden() == isJoinChannel())) {
|
||||
|| (!isBlocked()
|
||||
&& _joinChannel->isHidden() == isJoinChannel()
|
||||
&& _discuss->isHidden() == hasDiscussionGroup())
|
||||
|| (isMuteUnmute() && _discuss->isHidden() == hasDiscussionGroup())) {
|
||||
resize = true;
|
||||
}
|
||||
if (updateCanSendMessage()) {
|
||||
|
|
|
|||
|
|
@ -428,6 +428,9 @@ private:
|
|||
void unblockUser();
|
||||
void sendBotStartCommand();
|
||||
void joinChannel();
|
||||
void goToDiscussionGroup();
|
||||
|
||||
[[nodiscard]] bool hasDiscussionGroup() const;
|
||||
|
||||
void supportInitAutocomplete();
|
||||
void supportInsertText(const QString &text);
|
||||
|
|
@ -759,6 +762,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