Ask for boosts to unlock group restrictions.
This commit is contained in:
@@ -394,13 +394,9 @@ not_null<HistoryItem*> Result::makeMessage(
|
||||
return sendData->makeMessage(this, history, std::move(fields));
|
||||
}
|
||||
|
||||
QString Result::getErrorOnSend(not_null<History*> history) const {
|
||||
const auto specific = sendData->getErrorOnSend(this, history);
|
||||
return !specific.isEmpty()
|
||||
? specific
|
||||
: Data::RestrictionError(
|
||||
history->peer,
|
||||
ChatRestriction::SendInline).value_or(QString());
|
||||
Data::SendError Result::getErrorOnSend(not_null<History*> history) const {
|
||||
return sendData->getErrorOnSend(this, history).value_or(
|
||||
Data::RestrictionError(history->peer, ChatRestriction::SendInline));
|
||||
}
|
||||
|
||||
std::optional<Data::LocationPoint> Result::getLocationPoint() const {
|
||||
|
||||
@@ -20,6 +20,7 @@ struct HistoryItemCommonFields;
|
||||
|
||||
namespace Data {
|
||||
class LocationPoint;
|
||||
struct SendError;
|
||||
} // namespace Data
|
||||
|
||||
namespace InlineBots {
|
||||
@@ -69,7 +70,8 @@ public:
|
||||
[[nodiscard]] not_null<HistoryItem*> makeMessage(
|
||||
not_null<History*> history,
|
||||
HistoryItemCommonFields &&fields) const;
|
||||
QString getErrorOnSend(not_null<History*> history) const;
|
||||
[[nodiscard]] Data::SendError getErrorOnSend(
|
||||
not_null<History*> history) const;
|
||||
|
||||
// interface for Layout:: usage
|
||||
std::optional<Data::LocationPoint> getLocationPoint() const;
|
||||
|
||||
@@ -42,11 +42,11 @@ not_null<HistoryItem*> SendDataCommon::makeMessage(
|
||||
std::move(distinct.media));
|
||||
}
|
||||
|
||||
QString SendDataCommon::getErrorOnSend(
|
||||
Data::SendError SendDataCommon::getErrorOnSend(
|
||||
const Result *owner,
|
||||
not_null<History*> history) const {
|
||||
const auto type = ChatRestriction::SendOther;
|
||||
return Data::RestrictionError(history->peer, type).value_or(QString());
|
||||
return Data::RestrictionError(history->peer, type);
|
||||
}
|
||||
|
||||
SendDataCommon::SentMessageFields SendText::getSentMessageFields() const {
|
||||
@@ -106,11 +106,11 @@ not_null<HistoryItem*> SendPhoto::makeMessage(
|
||||
TextWithEntities{ _message, _entities });
|
||||
}
|
||||
|
||||
QString SendPhoto::getErrorOnSend(
|
||||
Data::SendError SendPhoto::getErrorOnSend(
|
||||
const Result *owner,
|
||||
not_null<History*> history) const {
|
||||
const auto type = ChatRestriction::SendPhotos;
|
||||
return Data::RestrictionError(history->peer, type).value_or(QString());
|
||||
return Data::RestrictionError(history->peer, type);
|
||||
}
|
||||
|
||||
not_null<HistoryItem*> SendFile::makeMessage(
|
||||
@@ -123,11 +123,11 @@ not_null<HistoryItem*> SendFile::makeMessage(
|
||||
TextWithEntities{ _message, _entities });
|
||||
}
|
||||
|
||||
QString SendFile::getErrorOnSend(
|
||||
Data::SendError SendFile::getErrorOnSend(
|
||||
const Result *owner,
|
||||
not_null<History*> history) const {
|
||||
const auto type = _document->requiredSendRight();
|
||||
return Data::RestrictionError(history->peer, type).value_or(QString());
|
||||
return Data::RestrictionError(history->peer, type);
|
||||
}
|
||||
|
||||
not_null<HistoryItem*> SendGame::makeMessage(
|
||||
@@ -137,11 +137,11 @@ not_null<HistoryItem*> SendGame::makeMessage(
|
||||
return history->makeMessage(std::move(fields), _game);
|
||||
}
|
||||
|
||||
QString SendGame::getErrorOnSend(
|
||||
Data::SendError SendGame::getErrorOnSend(
|
||||
const Result *owner,
|
||||
not_null<History*> history) const {
|
||||
const auto type = ChatRestriction::SendGames;
|
||||
return Data::RestrictionError(history->peer, type).value_or(QString());
|
||||
return Data::RestrictionError(history->peer, type);
|
||||
}
|
||||
|
||||
SendDataCommon::SentMessageFields SendInvoice::getSentMessageFields() const {
|
||||
|
||||
@@ -11,6 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
struct HistoryItemCommonFields;
|
||||
|
||||
namespace Data {
|
||||
struct SendError;
|
||||
} // namespace Data
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
@@ -44,7 +48,7 @@ public:
|
||||
const Result *owner,
|
||||
not_null<History*> history,
|
||||
HistoryItemCommonFields &&fields) const = 0;
|
||||
virtual QString getErrorOnSend(
|
||||
virtual Data::SendError getErrorOnSend(
|
||||
const Result *owner,
|
||||
not_null<History*> history) const = 0;
|
||||
|
||||
@@ -80,7 +84,7 @@ public:
|
||||
not_null<History*> history,
|
||||
HistoryItemCommonFields &&fields) const override;
|
||||
|
||||
QString getErrorOnSend(
|
||||
Data::SendError getErrorOnSend(
|
||||
const Result *owner,
|
||||
not_null<History*> history) const override;
|
||||
|
||||
@@ -241,7 +245,7 @@ public:
|
||||
not_null<History*> history,
|
||||
HistoryItemCommonFields &&fields) const override;
|
||||
|
||||
QString getErrorOnSend(
|
||||
Data::SendError getErrorOnSend(
|
||||
const Result *owner,
|
||||
not_null<History*> history) const override;
|
||||
|
||||
@@ -275,7 +279,7 @@ public:
|
||||
not_null<History*> history,
|
||||
HistoryItemCommonFields &&fields) const override;
|
||||
|
||||
QString getErrorOnSend(
|
||||
Data::SendError getErrorOnSend(
|
||||
const Result *owner,
|
||||
not_null<History*> history) const override;
|
||||
|
||||
@@ -303,7 +307,7 @@ public:
|
||||
not_null<History*> history,
|
||||
HistoryItemCommonFields &&fields) const override;
|
||||
|
||||
QString getErrorOnSend(
|
||||
Data::SendError getErrorOnSend(
|
||||
const Result *owner,
|
||||
not_null<History*> history) const override;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "mainwindow.h"
|
||||
#include "main/main_session.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
@@ -113,19 +114,35 @@ void Inner::checkRestrictedPeer() {
|
||||
const auto error = Data::RestrictionError(
|
||||
_inlineQueryPeer,
|
||||
ChatRestriction::SendInline);
|
||||
if (error) {
|
||||
if (!_restrictedLabel) {
|
||||
_restrictedLabel.create(this, *error, st::stickersRestrictedLabel);
|
||||
_restrictedLabel->show();
|
||||
_restrictedLabel->move(st::inlineResultsLeft - st::roundRadiusSmall, st::stickerPanPadding);
|
||||
_restrictedLabel->resizeToNaturalWidth(width() - (st::inlineResultsLeft - st::roundRadiusSmall) * 2);
|
||||
if (_switchPmButton) {
|
||||
_switchPmButton->hide();
|
||||
}
|
||||
repaintItems();
|
||||
}
|
||||
const auto changed = (_restrictedLabelKey != error.text);
|
||||
if (!changed) {
|
||||
return;
|
||||
}
|
||||
_restrictedLabelKey = error.text;
|
||||
if (error) {
|
||||
const auto window = _controller;
|
||||
const auto peer = _inlineQueryPeer;
|
||||
_restrictedLabel.create(
|
||||
this,
|
||||
rpl::single(error.boostsToLift
|
||||
? Ui::Text::Link(error.text)
|
||||
: TextWithEntities{ error.text }),
|
||||
st::stickersRestrictedLabel);
|
||||
const auto lifting = error.boostsToLift;
|
||||
_restrictedLabel->setClickHandlerFilter([=](auto...) {
|
||||
window->resolveBoostState(peer->asChannel(), lifting);
|
||||
return false;
|
||||
});
|
||||
_restrictedLabel->show();
|
||||
updateRestrictedLabelGeometry();
|
||||
if (_switchPmButton) {
|
||||
_switchPmButton->hide();
|
||||
}
|
||||
repaintItems();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
_restrictedLabelKey = QString();
|
||||
}
|
||||
if (_restrictedLabel) {
|
||||
_restrictedLabel.destroy();
|
||||
@@ -136,6 +153,18 @@ void Inner::checkRestrictedPeer() {
|
||||
}
|
||||
}
|
||||
|
||||
void Inner::updateRestrictedLabelGeometry() {
|
||||
if (!_restrictedLabel) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto labelWidth = width() - st::stickerPanPadding * 2;
|
||||
_restrictedLabel->resizeToWidth(labelWidth);
|
||||
_restrictedLabel->moveToLeft(
|
||||
(width() - _restrictedLabel->width()) / 2,
|
||||
st::stickerPanPadding);
|
||||
}
|
||||
|
||||
bool Inner::isRestrictedView() {
|
||||
checkRestrictedPeer();
|
||||
return (_restrictedLabel != nullptr);
|
||||
@@ -178,6 +207,10 @@ rpl::producer<> Inner::inlineRowsCleared() const {
|
||||
|
||||
Inner::~Inner() = default;
|
||||
|
||||
void Inner::resizeEvent(QResizeEvent *e) {
|
||||
updateRestrictedLabelGeometry();
|
||||
}
|
||||
|
||||
void Inner::paintEvent(QPaintEvent *e) {
|
||||
Painter p(this);
|
||||
QRect r = e ? e->rect() : rect();
|
||||
|
||||
@@ -108,6 +108,7 @@ protected:
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void leaveEventHook(QEvent *e) override;
|
||||
void leaveToChildEvent(QEvent *e, QWidget *child) override;
|
||||
@@ -136,6 +137,7 @@ private:
|
||||
void clearInlineRows(bool resultsDeleted);
|
||||
ItemBase *layoutPrepareInlineResult(Result *result);
|
||||
|
||||
void updateRestrictedLabelGeometry();
|
||||
void deleteUnusedInlineLayouts();
|
||||
|
||||
int validateExistingInlineRows(const Results &results);
|
||||
@@ -162,6 +164,7 @@ private:
|
||||
QByteArray _switchPmUrl;
|
||||
|
||||
object_ptr<Ui::FlatLabel> _restrictedLabel = { nullptr };
|
||||
QString _restrictedLabelKey;
|
||||
|
||||
base::unique_qptr<Ui::PopupMenu> _menu;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user