Support write restrictions in Replies section.
This commit is contained in:
parent
94c2969f8b
commit
cc9eb7f893
|
@ -493,6 +493,7 @@ ComposeControls::ComposeControls(
|
||||||
, _window(window)
|
, _window(window)
|
||||||
, _mode(mode)
|
, _mode(mode)
|
||||||
, _wrap(std::make_unique<Ui::RpWidget>(parent))
|
, _wrap(std::make_unique<Ui::RpWidget>(parent))
|
||||||
|
, _writeRestricted(std::make_unique<Ui::RpWidget>(parent))
|
||||||
, _send(Ui::CreateChild<Ui::SendButton>(_wrap.get()))
|
, _send(Ui::CreateChild<Ui::SendButton>(_wrap.get()))
|
||||||
, _attachToggle(Ui::CreateChild<Ui::IconButton>(
|
, _attachToggle(Ui::CreateChild<Ui::IconButton>(
|
||||||
_wrap.get(),
|
_wrap.get(),
|
||||||
|
@ -534,6 +535,8 @@ void ComposeControls::setHistory(SetHistoryArgs &&args) {
|
||||||
| rpl::then(std::move(args.slowmodeSecondsLeft));
|
| rpl::then(std::move(args.slowmodeSecondsLeft));
|
||||||
_sendDisabledBySlowmode = rpl::single(false)
|
_sendDisabledBySlowmode = rpl::single(false)
|
||||||
| rpl::then(std::move(args.sendDisabledBySlowmode));
|
| rpl::then(std::move(args.sendDisabledBySlowmode));
|
||||||
|
_writeRestriction = rpl::single(std::optional<QString>())
|
||||||
|
| rpl::then(std::move(args.writeRestriction));
|
||||||
const auto history = *args.history;
|
const auto history = *args.history;
|
||||||
if (_history == history) {
|
if (_history == history) {
|
||||||
return;
|
return;
|
||||||
|
@ -546,19 +549,27 @@ void ComposeControls::setHistory(SetHistoryArgs &&args) {
|
||||||
|
|
||||||
void ComposeControls::move(int x, int y) {
|
void ComposeControls::move(int x, int y) {
|
||||||
_wrap->move(x, y);
|
_wrap->move(x, y);
|
||||||
|
_writeRestricted->move(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComposeControls::resizeToWidth(int width) {
|
void ComposeControls::resizeToWidth(int width) {
|
||||||
_wrap->resizeToWidth(width);
|
_wrap->resizeToWidth(width);
|
||||||
|
_writeRestricted->resizeToWidth(width);
|
||||||
updateHeight();
|
updateHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<int> ComposeControls::height() const {
|
rpl::producer<int> ComposeControls::height() const {
|
||||||
return _wrap->heightValue();
|
using namespace rpl::mappers;
|
||||||
|
return rpl::conditional(
|
||||||
|
_writeRestriction.value() | rpl::map(!_1),
|
||||||
|
_wrap->heightValue(),
|
||||||
|
_writeRestricted->heightValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
int ComposeControls::heightCurrent() const {
|
int ComposeControls::heightCurrent() const {
|
||||||
return _wrap->height();
|
return _writeRestriction.current()
|
||||||
|
? _writeRestricted->height()
|
||||||
|
: _wrap->height();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ComposeControls::focus() {
|
bool ComposeControls::focus() {
|
||||||
|
@ -773,6 +784,7 @@ void ComposeControls::init() {
|
||||||
initField();
|
initField();
|
||||||
initTabbedSelector();
|
initTabbedSelector();
|
||||||
initSendButton();
|
initSendButton();
|
||||||
|
initWriteRestriction();
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
::Media::Capture::instance(),
|
::Media::Capture::instance(),
|
||||||
|
@ -957,6 +969,18 @@ void ComposeControls::drawRecording(Painter &p, float64 recordActive) {
|
||||||
p.drawText(left + (right - left - _recordCancelWidth) / 2, _attachToggle->y() + st::historyRecordTextTop + st::historyRecordFont->ascent, tr::lng_record_cancel(tr::now));
|
p.drawText(left + (right - left - _recordCancelWidth) / 2, _attachToggle->y() + st::historyRecordTextTop + st::historyRecordFont->ascent, tr::lng_record_cancel(tr::now));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ComposeControls::drawRestrictedWrite(Painter &p, const QString &error) {
|
||||||
|
p.fillRect(_writeRestricted->rect(), st::historyReplyBg);
|
||||||
|
|
||||||
|
p.setFont(st::normalFont);
|
||||||
|
p.setPen(st::windowSubTextFg);
|
||||||
|
p.drawText(
|
||||||
|
_writeRestricted->rect().marginsRemoved(
|
||||||
|
QMargins(st::historySendPadding, 0, st::historySendPadding, 0)),
|
||||||
|
error,
|
||||||
|
style::al_center);
|
||||||
|
}
|
||||||
|
|
||||||
void ComposeControls::setTextFromEditingMessage(not_null<HistoryItem*> item) {
|
void ComposeControls::setTextFromEditingMessage(not_null<HistoryItem*> item) {
|
||||||
if (!_header->isEditingMessage()) {
|
if (!_header->isEditingMessage()) {
|
||||||
return;
|
return;
|
||||||
|
@ -1050,6 +1074,25 @@ void ComposeControls::initSendButton() {
|
||||||
_send->finishAnimating();
|
_send->finishAnimating();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ComposeControls::initWriteRestriction() {
|
||||||
|
_writeRestricted->resize(
|
||||||
|
_writeRestricted->width(),
|
||||||
|
st::historyUnblock.height);
|
||||||
|
_writeRestricted->paintRequest(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
if (const auto error = _writeRestriction.current()) {
|
||||||
|
auto p = Painter(_writeRestricted.get());
|
||||||
|
drawRestrictedWrite(p, *error);
|
||||||
|
}
|
||||||
|
}, _wrap->lifetime());
|
||||||
|
|
||||||
|
_writeRestriction.value(
|
||||||
|
) | rpl::start_with_next([=](const std::optional<QString> &error) {
|
||||||
|
_writeRestricted->setVisible(error.has_value());
|
||||||
|
_wrap->setVisible(!error.has_value());
|
||||||
|
}, _wrap->lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
void ComposeControls::updateSendButtonType() {
|
void ComposeControls::updateSendButtonType() {
|
||||||
using Type = Ui::SendButton::Type;
|
using Type = Ui::SendButton::Type;
|
||||||
const auto type = [&] {
|
const auto type = [&] {
|
||||||
|
@ -1143,8 +1186,6 @@ void ComposeControls::paintBackground(QRect clip) {
|
||||||
if (!_send->isHidden() && _recording) {
|
if (!_send->isHidden() && _recording) {
|
||||||
drawRecording(p, _send->recordActiveRatio());
|
drawRecording(p, _send->recordActiveRatio());
|
||||||
}
|
}
|
||||||
//} else if (const auto error = writeRestriction()) {
|
|
||||||
// drawRestrictedWrite(p, *error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1414,7 +1455,6 @@ void ComposeControls::initWebpageProcess() {
|
||||||
title->events(),
|
title->events(),
|
||||||
description->events(),
|
description->events(),
|
||||||
pageData->events());
|
pageData->events());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebPageId ComposeControls::webPageId() const {
|
WebPageId ComposeControls::webPageId() const {
|
||||||
|
|
|
@ -94,6 +94,7 @@ public:
|
||||||
Fn<bool()> showSlowmodeError;
|
Fn<bool()> showSlowmodeError;
|
||||||
rpl::producer<int> slowmodeSecondsLeft;
|
rpl::producer<int> slowmodeSecondsLeft;
|
||||||
rpl::producer<bool> sendDisabledBySlowmode;
|
rpl::producer<bool> sendDisabledBySlowmode;
|
||||||
|
rpl::producer<std::optional<QString>> writeRestriction;
|
||||||
};
|
};
|
||||||
void setHistory(SetHistoryArgs &&args);
|
void setHistory(SetHistoryArgs &&args);
|
||||||
void finishAnimating();
|
void finishAnimating();
|
||||||
|
@ -159,6 +160,7 @@ private:
|
||||||
void initTabbedSelector();
|
void initTabbedSelector();
|
||||||
void initSendButton();
|
void initSendButton();
|
||||||
void initWebpageProcess();
|
void initWebpageProcess();
|
||||||
|
void initWriteRestriction();
|
||||||
void updateSendButtonType();
|
void updateSendButtonType();
|
||||||
void updateHeight();
|
void updateHeight();
|
||||||
void updateControlsVisibility();
|
void updateControlsVisibility();
|
||||||
|
@ -187,6 +189,7 @@ private:
|
||||||
|
|
||||||
bool showRecordButton() const;
|
bool showRecordButton() const;
|
||||||
void drawRecording(Painter &p, float64 recordActive);
|
void drawRecording(Painter &p, float64 recordActive);
|
||||||
|
void drawRestrictedWrite(Painter &p, const QString &error);
|
||||||
void updateOverStates(QPoint pos);
|
void updateOverStates(QPoint pos);
|
||||||
|
|
||||||
const not_null<QWidget*> _parent;
|
const not_null<QWidget*> _parent;
|
||||||
|
@ -195,9 +198,11 @@ private:
|
||||||
Fn<bool()> _showSlowmodeError;
|
Fn<bool()> _showSlowmodeError;
|
||||||
rpl::variable<int> _slowmodeSecondsLeft;
|
rpl::variable<int> _slowmodeSecondsLeft;
|
||||||
rpl::variable<bool> _sendDisabledBySlowmode;
|
rpl::variable<bool> _sendDisabledBySlowmode;
|
||||||
|
rpl::variable<std::optional<QString>> _writeRestriction;
|
||||||
Mode _mode = Mode::Normal;
|
Mode _mode = Mode::Normal;
|
||||||
|
|
||||||
const std::unique_ptr<Ui::RpWidget> _wrap;
|
const std::unique_ptr<Ui::RpWidget> _wrap;
|
||||||
|
const std::unique_ptr<Ui::RpWidget> _writeRestricted;
|
||||||
|
|
||||||
const not_null<Ui::SendButton*> _send;
|
const not_null<Ui::SendButton*> _send;
|
||||||
const not_null<Ui::IconButton*> _attachToggle;
|
const not_null<Ui::IconButton*> _attachToggle;
|
||||||
|
|
|
@ -440,11 +440,21 @@ void RepliesWidget::setupComposeControls() {
|
||||||
std::move(hasSendingMessage),
|
std::move(hasSendingMessage),
|
||||||
_1 && _2);
|
_1 && _2);
|
||||||
|
|
||||||
|
auto writeRestriction = session().changes().peerFlagsValue(
|
||||||
|
_history->peer,
|
||||||
|
Data::PeerUpdate::Flag::Rights
|
||||||
|
) | rpl::map([=] {
|
||||||
|
return Data::RestrictionError(
|
||||||
|
_history->peer,
|
||||||
|
ChatRestriction::f_send_messages);
|
||||||
|
});
|
||||||
|
|
||||||
_composeControls->setHistory({
|
_composeControls->setHistory({
|
||||||
.history = _history.get(),
|
.history = _history.get(),
|
||||||
.showSlowmodeError = [=] { return showSlowmodeError(); },
|
.showSlowmodeError = [=] { return showSlowmodeError(); },
|
||||||
.slowmodeSecondsLeft = std::move(slowmodeSecondsLeft),
|
.slowmodeSecondsLeft = std::move(slowmodeSecondsLeft),
|
||||||
.sendDisabledBySlowmode = std::move(sendDisabledBySlowmode),
|
.sendDisabledBySlowmode = std::move(sendDisabledBySlowmode),
|
||||||
|
.writeRestriction = std::move(writeRestriction),
|
||||||
});
|
});
|
||||||
|
|
||||||
_composeControls->height(
|
_composeControls->height(
|
||||||
|
@ -761,6 +771,12 @@ bool RepliesWidget::showSlowmodeError() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<QString> RepliesWidget::writeRestriction() const {
|
||||||
|
return Data::RestrictionError(
|
||||||
|
_history->peer,
|
||||||
|
ChatRestriction::f_send_messages);
|
||||||
|
}
|
||||||
|
|
||||||
void RepliesWidget::uploadFilesAfterConfirmation(
|
void RepliesWidget::uploadFilesAfterConfirmation(
|
||||||
Storage::PreparedList &&list,
|
Storage::PreparedList &&list,
|
||||||
SendMediaType type,
|
SendMediaType type,
|
||||||
|
|
|
@ -235,6 +235,7 @@ private:
|
||||||
Api::SendOptions options);
|
Api::SendOptions options);
|
||||||
|
|
||||||
[[nodiscard]] bool showSlowmodeError();
|
[[nodiscard]] bool showSlowmodeError();
|
||||||
|
[[nodiscard]] std::optional<QString> writeRestriction() const;
|
||||||
|
|
||||||
const not_null<History*> _history;
|
const not_null<History*> _history;
|
||||||
const MsgId _rootId = 0;
|
const MsgId _rootId = 0;
|
||||||
|
|
Loading…
Reference in New Issue