2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Add FileSizeLimitBox and pass "ref" to premium payment.

This commit is contained in:
John Preston
2022-05-23 18:46:15 +04:00
parent 62f42eabb0
commit d1907083ed
20 changed files with 211 additions and 350 deletions

View File

@@ -207,48 +207,6 @@ void ShowAddParticipantsError(
Ui::show(Ui::MakeInformBox(text), Ui::LayerOption::KeepOther);
}
class RevokePublicLinkBox::Inner : public TWidget {
public:
Inner(
QWidget *parent,
not_null<Main::Session*> session,
Fn<void()> revokeCallback);
protected:
void mouseMoveEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void paintEvent(QPaintEvent *e) override;
private:
struct ChatRow {
ChatRow(not_null<PeerData*> peer) : peer(peer) {
}
not_null<PeerData*> peer;
mutable std::shared_ptr<Data::CloudImageView> userpic;
Ui::Text::String name, status;
};
void paintChat(Painter &p, const ChatRow &row, bool selected) const;
void updateSelected();
const not_null<Main::Session*> _session;
MTP::Sender _api;
PeerData *_selected = nullptr;
PeerData *_pressed = nullptr;
std::vector<ChatRow> _rows;
int _rowsTop = 0;
int _rowHeight = 0;
int _revokeWidth = 0;
Fn<void()> _revokeCallback;
mtpRequestId _revokeRequestId = 0;
};
AddContactBox::AddContactBox(
QWidget*,
not_null<Main::Session*> session)
@@ -1243,9 +1201,7 @@ void SetupChannelBox::privacyChanged(Privacy value) {
check();
});
Ui::show(
Box<RevokePublicLinkBox>(
&_channel->session(),
callback),
Box(PublicLinksLimitBox, _navigation, callback),
Ui::LayerOption::KeepOther);
return;
}
@@ -1337,9 +1293,7 @@ void SetupChannelBox::showRevokePublicLinkBoxForEdit() {
};
closeBox();
Ui::show(
Box<RevokePublicLinkBox>(
&channel->session(),
callback),
Box(PublicLinksLimitBox, navigation, callback),
Ui::LayerOption::KeepOther);
}
@@ -1505,252 +1459,3 @@ void EditNameBox::saveSelfFail(const QString &error) {
_first->setFocus();
}
}
RevokePublicLinkBox::Inner::Inner(
QWidget *parent,
not_null<Main::Session*> session,
Fn<void()> revokeCallback)
: TWidget(parent)
, _session(session)
, _api(&_session->mtp())
, _rowHeight(st::contactsPadding.top()
+ st::contactsPhotoSize
+ st::contactsPadding.bottom())
, _revokeWidth(st::normalFont->width(
tr::lng_channels_too_much_public_revoke(tr::now)))
, _revokeCallback(std::move(revokeCallback)) {
setMouseTracking(true);
resize(width(), 5 * _rowHeight);
_api.request(MTPchannels_GetAdminedPublicChannels(
MTP_flags(0)
)).done([=](const MTPmessages_Chats &result) {
const auto &chats = result.match([](const auto &data) {
return data.vchats().v;
});
for (const auto &chat : chats) {
if (const auto peer = _session->data().processChat(chat)) {
if (!peer->isChannel() || peer->userName().isEmpty()) {
continue;
}
auto row = ChatRow(peer);
row.peer = peer;
row.name.setText(
st::contactsNameStyle,
peer->name,
Ui::NameTextOptions());
row.status.setMarkedText(
st::defaultTextStyle,
_session->createInternalLink(
Ui::Text::Link(peer->userName())));
_rows.push_back(std::move(row));
}
}
resize(width(), _rows.size() * _rowHeight);
update();
}).send();
}
RevokePublicLinkBox::RevokePublicLinkBox(
QWidget*,
not_null<Main::Session*> session,
Fn<void()> revokeCallback)
: _session(session)
, _aboutRevoke(
this,
tr::lng_channels_too_much_public_about(tr::now),
st::aboutRevokePublicLabel)
, _revokeCallback(std::move(revokeCallback)) {
}
void RevokePublicLinkBox::prepare() {
_innerTop = st::boxPadding.top()
+ _aboutRevoke->height()
+ st::boxPadding.top();
_inner = setInnerWidget(object_ptr<Inner>(this, _session, [=] {
const auto callback = _revokeCallback;
closeBox();
if (callback) {
callback();
}
}), st::boxScroll, _innerTop);
addButton(tr::lng_cancel(), [=] { closeBox(); });
_session->downloaderTaskFinished(
) | rpl::start_with_next([=] {
update();
}, lifetime());
_inner->resizeToWidth(st::boxWideWidth);
setDimensions(st::boxWideWidth, _innerTop + _inner->height());
}
void RevokePublicLinkBox::Inner::mouseMoveEvent(QMouseEvent *e) {
updateSelected();
}
void RevokePublicLinkBox::Inner::updateSelected() {
const auto point = mapFromGlobal(QCursor::pos());
PeerData *selected = nullptr;
auto top = _rowsTop;
for (const auto &row : _rows) {
const auto revokeLink = style::rtlrect(
width()
- st::contactsPadding.right()
- st::contactsCheckPosition.x()
- _revokeWidth,
top
+ st::contactsPadding.top()
+ (st::contactsPhotoSize - st::normalFont->height) / 2,
_revokeWidth,
st::normalFont->height,
width());
if (revokeLink.contains(point)) {
selected = row.peer;
break;
}
top += _rowHeight;
}
if (selected != _selected) {
_selected = selected;
setCursor((_selected || _pressed)
? style::cur_pointer
: style::cur_default);
update();
}
}
void RevokePublicLinkBox::Inner::mousePressEvent(QMouseEvent *e) {
if (_pressed != _selected) {
_pressed = _selected;
update();
}
}
void RevokePublicLinkBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
const auto pressed = base::take(_pressed);
setCursor((_selected || _pressed)
? style::cur_pointer
: style::cur_default);
if (pressed && pressed == _selected) {
const auto textMethod = pressed->isMegagroup()
? tr::lng_channels_too_much_public_revoke_confirm_group
: tr::lng_channels_too_much_public_revoke_confirm_channel;
const auto text = textMethod(
tr::now,
lt_link,
_session->createInternalLink(pressed->userName()),
lt_group,
pressed->name);
const auto confirmText = tr::lng_channels_too_much_public_revoke(
tr::now);
auto callback = crl::guard(this, [=](Fn<void()> &&close) {
if (_revokeRequestId) {
return;
}
_revokeRequestId = _api.request(MTPchannels_UpdateUsername(
pressed->asChannel()->inputChannel,
MTP_string()
)).done([=, close = std::move(close)] {
close();
if (const auto callback = _revokeCallback) {
callback();
}
}).send();
});
Ui::show(
Ui::MakeConfirmBox({
.text = text,
.confirmed = std::move(callback),
.confirmText = confirmText,
}),
Ui::LayerOption::KeepOther);
}
}
void RevokePublicLinkBox::Inner::paintEvent(QPaintEvent *e) {
Painter p(this);
p.translate(0, _rowsTop);
for (const auto &row : _rows) {
paintChat(p, row, (row.peer == _selected));
p.translate(0, _rowHeight);
}
}
void RevokePublicLinkBox::resizeEvent(QResizeEvent *e) {
BoxContent::resizeEvent(e);
_aboutRevoke->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
}
void RevokePublicLinkBox::Inner::paintChat(
Painter &p,
const ChatRow &row,
bool selected) const {
const auto peer = row.peer;
peer->paintUserpicLeft(
p,
row.userpic,
st::contactsPadding.left(),
st::contactsPadding.top(),
width(),
st::contactsPhotoSize);
p.setPen(st::contactsNameFg);
const auto namex = st::contactsPadding.left()
+ st::contactsPhotoSize
+ st::contactsPadding.left();
auto namew = width()
- namex
- st::contactsPadding.right()
- (_revokeWidth + st::contactsCheckPosition.x() * 2);
const auto badgeStyle = Ui::PeerBadgeStyle{
&st::dialogsVerifiedIcon,
nullptr, // premium
&st::attentionButtonFg
};
namew -= Ui::DrawPeerBadgeGetWidth(
peer,
p,
QRect(
namex,
st::contactsPadding.top() + st::contactsNameTop,
row.name.maxWidth(),
st::contactsNameStyle.font->height),
namew,
width(),
badgeStyle);
row.name.drawLeftElided(
p,
namex,
st::contactsPadding.top() + st::contactsNameTop,
namew,
width());
p.setFont(selected ? st::linkOverFont : st::linkFont);
p.setPen(selected
? st::defaultLinkButton.overColor
: st::defaultLinkButton.color);
p.drawTextRight(
st::contactsPadding.right() + st::contactsCheckPosition.x(),
st::contactsPadding.top()
+ (st::contactsPhotoSize - st::normalFont->height) / 2,
width(),
tr::lng_channels_too_much_public_revoke(tr::now),
_revokeWidth);
p.setPen(st::contactsStatusFg);
p.setTextPalette(st::revokePublicLinkStatusPalette);
row.status.drawLeftElided(
p,
namex,
st::contactsPadding.top() + st::contactsStatusTop,
namew,
width());
p.restoreTextPalette();
}