mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Replaced PinMessageBox with generic box.
This commit is contained in:
parent
2b8eefccca
commit
2d28d795cf
3 changed files with 82 additions and 118 deletions
|
@ -12,8 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "ui/boxes/confirm_box.h"
|
||||||
#include "ui/widgets/checkbox.h"
|
#include "ui/widgets/checkbox.h"
|
||||||
#include "ui/widgets/labels.h"
|
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
|
|
||||||
|
@ -36,94 +36,84 @@ namespace {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
PinMessageBox::PinMessageBox(
|
void PinMessageBox(
|
||||||
QWidget*,
|
not_null<Ui::GenericBox*> box,
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
MsgId msgId)
|
MsgId msgId) {
|
||||||
: _peer(peer)
|
struct State {
|
||||||
, _api(&peer->session().mtp())
|
QPointer<Ui::Checkbox> pinForPeer;
|
||||||
, _msgId(msgId)
|
QPointer<Ui::Checkbox> notify;
|
||||||
, _pinningOld(IsOldForPin(msgId, peer))
|
mtpRequestId requestId = 0;
|
||||||
, _text(
|
};
|
||||||
this,
|
|
||||||
(_pinningOld
|
|
||||||
? tr::lng_pinned_pin_old_sure(tr::now)
|
|
||||||
: (peer->isChat() || peer->isMegagroup())
|
|
||||||
? tr::lng_pinned_pin_sure_group(tr::now)
|
|
||||||
: tr::lng_pinned_pin_sure(tr::now)),
|
|
||||||
st::boxLabel) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void PinMessageBox::prepare() {
|
const auto pinningOld = IsOldForPin(msgId, peer);
|
||||||
addButton(tr::lng_pinned_pin(), [this] { pinMessage(); });
|
const auto state = box->lifetime().make_state<State>();
|
||||||
addButton(tr::lng_cancel(), [this] { closeBox(); });
|
const auto api = box->lifetime().make_state<MTP::Sender>(
|
||||||
|
&peer->session().mtp());
|
||||||
|
|
||||||
if (_peer->isUser() && !_peer->isSelf()) {
|
auto checkbox = [&]() -> object_ptr<Ui::Checkbox> {
|
||||||
_pinForPeer.create(
|
if (peer->isUser() && !peer->isSelf()) {
|
||||||
this,
|
auto object = object_ptr<Ui::Checkbox>(
|
||||||
tr::lng_pinned_also_for_other(
|
box,
|
||||||
tr::now,
|
tr::lng_pinned_also_for_other(
|
||||||
lt_user,
|
tr::now,
|
||||||
_peer->shortName()),
|
lt_user,
|
||||||
false,
|
peer->shortName()),
|
||||||
st::defaultBoxCheckbox);
|
false,
|
||||||
_checkbox = _pinForPeer;
|
st::urlAuthCheckbox);
|
||||||
} else if (!_pinningOld && (_peer->isChat() || _peer->isMegagroup())) {
|
object->setAllowTextLines();
|
||||||
_notify.create(
|
state->pinForPeer = Ui::MakeWeak(object.data());
|
||||||
this,
|
return object;
|
||||||
tr::lng_pinned_notify(tr::now),
|
} else if (!pinningOld && (peer->isChat() || peer->isMegagroup())) {
|
||||||
true,
|
auto object = object_ptr<Ui::Checkbox>(
|
||||||
st::defaultBoxCheckbox);
|
box,
|
||||||
_checkbox = _notify;
|
tr::lng_pinned_notify(tr::now),
|
||||||
}
|
true,
|
||||||
|
st::urlAuthCheckbox);
|
||||||
|
object->setAllowTextLines();
|
||||||
|
state->notify = Ui::MakeWeak(object.data());
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
return { nullptr };
|
||||||
|
}();
|
||||||
|
|
||||||
auto height = st::boxPadding.top()
|
auto pinMessage = [=] {
|
||||||
+ _text->height()
|
if (state->requestId) {
|
||||||
+ st::boxPadding.bottom();
|
return;
|
||||||
if (_checkbox) {
|
}
|
||||||
height += st::boxMediumSkip + _checkbox->heightNoMargins();
|
|
||||||
}
|
|
||||||
setDimensions(st::boxWidth, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PinMessageBox::resizeEvent(QResizeEvent *e) {
|
auto flags = MTPmessages_UpdatePinnedMessage::Flags(0);
|
||||||
BoxContent::resizeEvent(e);
|
if (state->notify && !state->notify->checked()) {
|
||||||
_text->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
|
flags |= MTPmessages_UpdatePinnedMessage::Flag::f_silent;
|
||||||
if (_checkbox) {
|
}
|
||||||
_checkbox->moveToLeft(
|
if (state->pinForPeer && !state->pinForPeer->checked()) {
|
||||||
st::boxPadding.left(),
|
flags |= MTPmessages_UpdatePinnedMessage::Flag::f_pm_oneside;
|
||||||
_text->y() + _text->height() + st::boxMediumSkip);
|
}
|
||||||
|
state->requestId = api->request(MTPmessages_UpdatePinnedMessage(
|
||||||
|
MTP_flags(flags),
|
||||||
|
peer->input,
|
||||||
|
MTP_int(msgId)
|
||||||
|
)).done([=](const MTPUpdates &result) {
|
||||||
|
peer->session().api().applyUpdates(result);
|
||||||
|
box->closeBox();
|
||||||
|
}).fail([=] {
|
||||||
|
box->closeBox();
|
||||||
|
}).send();
|
||||||
|
};
|
||||||
|
|
||||||
|
Ui::ConfirmBox(box, {
|
||||||
|
.text = (pinningOld
|
||||||
|
? tr::lng_pinned_pin_old_sure()
|
||||||
|
: (peer->isChat() || peer->isMegagroup())
|
||||||
|
? tr::lng_pinned_pin_sure_group()
|
||||||
|
: tr::lng_pinned_pin_sure()),
|
||||||
|
.confirmed = std::move(pinMessage),
|
||||||
|
.confirmText = tr::lng_pinned_pin(),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkbox) {
|
||||||
|
auto padding = st::boxPadding;
|
||||||
|
padding.setTop(padding.bottom());
|
||||||
|
box->addRow(std::move(checkbox), std::move(padding));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PinMessageBox::keyPressEvent(QKeyEvent *e) {
|
|
||||||
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
|
||||||
pinMessage();
|
|
||||||
} else {
|
|
||||||
BoxContent::keyPressEvent(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PinMessageBox::pinMessage() {
|
|
||||||
if (_requestId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto flags = MTPmessages_UpdatePinnedMessage::Flags(0);
|
|
||||||
if (_notify && !_notify->checked()) {
|
|
||||||
flags |= MTPmessages_UpdatePinnedMessage::Flag::f_silent;
|
|
||||||
}
|
|
||||||
if (_pinForPeer && !_pinForPeer->checked()) {
|
|
||||||
flags |= MTPmessages_UpdatePinnedMessage::Flag::f_pm_oneside;
|
|
||||||
}
|
|
||||||
_requestId = _api.request(MTPmessages_UpdatePinnedMessage(
|
|
||||||
MTP_flags(flags),
|
|
||||||
_peer->input,
|
|
||||||
MTP_int(_msgId)
|
|
||||||
)).done([=](const MTPUpdates &result) {
|
|
||||||
_peer->session().api().applyUpdates(result);
|
|
||||||
closeBox();
|
|
||||||
}).fail([=] {
|
|
||||||
closeBox();
|
|
||||||
}).send();
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,37 +7,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "boxes/abstract_box.h"
|
|
||||||
#include "mtproto/sender.h"
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class Checkbox;
|
class GenericBox;
|
||||||
class FlatLabel;
|
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
||||||
class PinMessageBox final : public Ui::BoxContent {
|
void PinMessageBox(
|
||||||
public:
|
not_null<Ui::GenericBox*> box,
|
||||||
PinMessageBox(QWidget*, not_null<PeerData*> peer, MsgId msgId);
|
not_null<PeerData*> peer,
|
||||||
|
MsgId msgId);
|
||||||
protected:
|
|
||||||
void prepare() override;
|
|
||||||
|
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
|
||||||
void keyPressEvent(QKeyEvent *e) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void pinMessage();
|
|
||||||
|
|
||||||
const not_null<PeerData*> _peer;
|
|
||||||
MTP::Sender _api;
|
|
||||||
MsgId _msgId = 0;
|
|
||||||
bool _pinningOld = false;
|
|
||||||
|
|
||||||
object_ptr<Ui::FlatLabel> _text;
|
|
||||||
object_ptr<Ui::Checkbox> _notify = { nullptr };
|
|
||||||
object_ptr<Ui::Checkbox> _pinForPeer = { nullptr };
|
|
||||||
QPointer<Ui::Checkbox> _checkbox;
|
|
||||||
|
|
||||||
mtpRequestId _requestId = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
|
@ -1273,7 +1273,7 @@ void ToggleMessagePinned(
|
||||||
}
|
}
|
||||||
if (pin) {
|
if (pin) {
|
||||||
navigation->parentController()->show(
|
navigation->parentController()->show(
|
||||||
Box<PinMessageBox>(item->history()->peer, item->id),
|
Box(PinMessageBox, item->history()->peer, item->id),
|
||||||
Ui::LayerOption::CloseOther);
|
Ui::LayerOption::CloseOther);
|
||||||
} else {
|
} else {
|
||||||
const auto peer = item->history()->peer;
|
const auto peer = item->history()->peer;
|
||||||
|
|
Loading…
Add table
Reference in a new issue