mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Extracted PinMessageBox to separated file.
This commit is contained in:
parent
fa6725c54a
commit
d4fe5f7a83
6 changed files with 175 additions and 128 deletions
|
@ -227,6 +227,8 @@ PRIVATE
|
|||
boxes/passcode_box.h
|
||||
boxes/phone_banned_box.cpp
|
||||
boxes/phone_banned_box.h
|
||||
boxes/pin_messages_box.cpp
|
||||
boxes/pin_messages_box.h
|
||||
boxes/rate_call_box.cpp
|
||||
boxes/rate_call_box.h
|
||||
boxes/self_destruction_box.cpp
|
||||
|
|
|
@ -71,21 +71,6 @@ TextParseOptions kMarkedTextBoxOptions = {
|
|||
Qt::LayoutDirectionAuto, // dir
|
||||
};
|
||||
|
||||
[[nodiscard]] bool IsOldForPin(MsgId id, not_null<PeerData*> peer) {
|
||||
const auto normal = peer->migrateToOrMe();
|
||||
const auto migrated = normal->migrateFrom();
|
||||
const auto top = Data::ResolveTopPinnedId(normal, migrated);
|
||||
if (!top) {
|
||||
return false;
|
||||
} else if (peer == migrated) {
|
||||
return top.channel || (id < top.msg);
|
||||
} else if (migrated) {
|
||||
return top.channel && (id < top.msg);
|
||||
} else {
|
||||
return (id < top.msg);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
ConfirmBox::ConfirmBox(
|
||||
|
@ -456,92 +441,6 @@ void MaxInviteBox::resizeEvent(QResizeEvent *e) {
|
|||
_invitationLink = myrtlrect(st::boxPadding.left(), st::boxPadding.top() + _textHeight + st::boxTextFont->height, width() - st::boxPadding.left() - st::boxPadding.right(), 2 * st::boxTextFont->height);
|
||||
}
|
||||
|
||||
PinMessageBox::PinMessageBox(
|
||||
QWidget*,
|
||||
not_null<PeerData*> peer,
|
||||
MsgId msgId)
|
||||
: _peer(peer)
|
||||
, _api(&peer->session().mtp())
|
||||
, _msgId(msgId)
|
||||
, _pinningOld(IsOldForPin(msgId, peer))
|
||||
, _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() {
|
||||
addButton(tr::lng_pinned_pin(), [this] { pinMessage(); });
|
||||
addButton(tr::lng_cancel(), [this] { closeBox(); });
|
||||
|
||||
if (_peer->isUser() && !_peer->isSelf()) {
|
||||
_pinForPeer.create(
|
||||
this,
|
||||
tr::lng_pinned_also_for_other(
|
||||
tr::now,
|
||||
lt_user,
|
||||
_peer->shortName()),
|
||||
false,
|
||||
st::defaultBoxCheckbox);
|
||||
_checkbox = _pinForPeer;
|
||||
} else if (!_pinningOld && (_peer->isChat() || _peer->isMegagroup())) {
|
||||
_notify.create(
|
||||
this,
|
||||
tr::lng_pinned_notify(tr::now),
|
||||
true,
|
||||
st::defaultBoxCheckbox);
|
||||
_checkbox = _notify;
|
||||
}
|
||||
|
||||
auto height = st::boxPadding.top() + _text->height() + st::boxPadding.bottom();
|
||||
if (_checkbox) {
|
||||
height += st::boxMediumSkip + _checkbox->heightNoMargins();
|
||||
}
|
||||
setDimensions(st::boxWidth, height);
|
||||
}
|
||||
|
||||
void PinMessageBox::resizeEvent(QResizeEvent *e) {
|
||||
BoxContent::resizeEvent(e);
|
||||
_text->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
|
||||
if (_checkbox) {
|
||||
_checkbox->moveToLeft(st::boxPadding.left(), _text->y() + _text->height() + st::boxMediumSkip);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
Ui::hideLayer();
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
Ui::hideLayer();
|
||||
}).send();
|
||||
}
|
||||
|
||||
DeleteMessagesBox::DeleteMessagesBox(
|
||||
QWidget*,
|
||||
not_null<HistoryItem*> item,
|
||||
|
|
|
@ -169,33 +169,6 @@ private:
|
|||
|
||||
};
|
||||
|
||||
class PinMessageBox final : public Ui::BoxContent {
|
||||
public:
|
||||
PinMessageBox(QWidget*, 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;
|
||||
|
||||
};
|
||||
|
||||
class DeleteMessagesBox final : public Ui::BoxContent {
|
||||
public:
|
||||
DeleteMessagesBox(
|
||||
|
|
129
Telegram/SourceFiles/boxes/pin_messages_box.cpp
Normal file
129
Telegram/SourceFiles/boxes/pin_messages_box.cpp
Normal file
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "boxes/pin_messages_box.h"
|
||||
|
||||
#include "apiwrap.h"
|
||||
#include "data/data_chat.h"
|
||||
#include "data/data_user.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_session.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] bool IsOldForPin(MsgId id, not_null<PeerData*> peer) {
|
||||
const auto normal = peer->migrateToOrMe();
|
||||
const auto migrated = normal->migrateFrom();
|
||||
const auto top = Data::ResolveTopPinnedId(normal, migrated);
|
||||
if (!top) {
|
||||
return false;
|
||||
} else if (peer == migrated) {
|
||||
return top.channel || (id < top.msg);
|
||||
} else if (migrated) {
|
||||
return top.channel && (id < top.msg);
|
||||
} else {
|
||||
return (id < top.msg);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
PinMessageBox::PinMessageBox(
|
||||
QWidget*,
|
||||
not_null<PeerData*> peer,
|
||||
MsgId msgId)
|
||||
: _peer(peer)
|
||||
, _api(&peer->session().mtp())
|
||||
, _msgId(msgId)
|
||||
, _pinningOld(IsOldForPin(msgId, peer))
|
||||
, _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() {
|
||||
addButton(tr::lng_pinned_pin(), [this] { pinMessage(); });
|
||||
addButton(tr::lng_cancel(), [this] { closeBox(); });
|
||||
|
||||
if (_peer->isUser() && !_peer->isSelf()) {
|
||||
_pinForPeer.create(
|
||||
this,
|
||||
tr::lng_pinned_also_for_other(
|
||||
tr::now,
|
||||
lt_user,
|
||||
_peer->shortName()),
|
||||
false,
|
||||
st::defaultBoxCheckbox);
|
||||
_checkbox = _pinForPeer;
|
||||
} else if (!_pinningOld && (_peer->isChat() || _peer->isMegagroup())) {
|
||||
_notify.create(
|
||||
this,
|
||||
tr::lng_pinned_notify(tr::now),
|
||||
true,
|
||||
st::defaultBoxCheckbox);
|
||||
_checkbox = _notify;
|
||||
}
|
||||
|
||||
auto height = st::boxPadding.top()
|
||||
+ _text->height()
|
||||
+ st::boxPadding.bottom();
|
||||
if (_checkbox) {
|
||||
height += st::boxMediumSkip + _checkbox->heightNoMargins();
|
||||
}
|
||||
setDimensions(st::boxWidth, height);
|
||||
}
|
||||
|
||||
void PinMessageBox::resizeEvent(QResizeEvent *e) {
|
||||
BoxContent::resizeEvent(e);
|
||||
_text->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
|
||||
if (_checkbox) {
|
||||
_checkbox->moveToLeft(
|
||||
st::boxPadding.left(),
|
||||
_text->y() + _text->height() + st::boxMediumSkip);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
Ui::hideLayer();
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
Ui::hideLayer();
|
||||
}).send();
|
||||
}
|
43
Telegram/SourceFiles/boxes/pin_messages_box.h
Normal file
43
Telegram/SourceFiles/boxes/pin_messages_box.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "boxes/abstract_box.h"
|
||||
#include "mtproto/sender.h"
|
||||
|
||||
namespace Ui {
|
||||
class Checkbox;
|
||||
class FlatLabel;
|
||||
} // namespace Ui
|
||||
|
||||
class PinMessageBox final : public Ui::BoxContent {
|
||||
public:
|
||||
PinMessageBox(QWidget*, 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;
|
||||
|
||||
};
|
|
@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "boxes/mute_settings_box.h"
|
||||
#include "boxes/add_contact_box.h"
|
||||
#include "boxes/create_poll_box.h"
|
||||
#include "boxes/pin_messages_box.h"
|
||||
#include "boxes/peers/add_participants_box.h"
|
||||
#include "boxes/peers/edit_contact_box.h"
|
||||
#include "ui/boxes/report_box.h"
|
||||
|
|
Loading…
Add table
Reference in a new issue