diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 9c8a54e78..6048332be 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -617,6 +617,8 @@ PRIVATE kotato/boxes/fonts_box.h kotato/boxes/net_boost_box.cpp kotato/boxes/net_boost_box.h + kotato/boxes/unpin_box.cpp + kotato/boxes/unpin_box.h kotato/json_settings.cpp kotato/json_settings.h kotato/settings_menu.cpp diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 20829d1cb..99d89ae7e 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -494,73 +494,6 @@ bool PinMessageBox::pinFail(const RPCError &error) { return true; } -UnpinMessageBox::UnpinMessageBox( - QWidget*, - not_null peer) -: _peer(peer) -, _text(this, tr::lng_pinned_unpin_sure(tr::now), st::boxLabel) { -} - -void UnpinMessageBox::prepare() { - addLeftButton(tr::ktg_hide_pinned_message(), [this] { hideMessage(); }); - - addButton(tr::lng_pinned_unpin(), [this] { unpinMessage(); }); - addButton(tr::lng_cancel(), [this] { closeBox(); }); - - auto height = st::boxPadding.top() + _text->height() + st::boxPadding.bottom(); - setDimensions(st::boxWidth, height); -} - -void UnpinMessageBox::resizeEvent(QResizeEvent *e) { - BoxContent::resizeEvent(e); - _text->moveToLeft(st::boxPadding.left(), st::boxPadding.top()); -} - -void UnpinMessageBox::keyPressEvent(QKeyEvent *e) { - if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { - unpinMessage(); - } else if (e->key() == Qt::Key_Backspace) { - hideMessage(); - } else { - BoxContent::keyPressEvent(e); - } -} - -void UnpinMessageBox::unpinMessage() { - if (_requestId) return; - - _requestId = MTP::send( - MTPmessages_UpdatePinnedMessage( - MTP_flags(0), - _peer->input, - MTP_int(0)), - rpcDone(&UnpinMessageBox::unpinDone), - rpcFail(&UnpinMessageBox::unpinFail)); -} - -void UnpinMessageBox::hideMessage() { - if (_requestId) return; - - auto hidden = HistoryWidget::switchPinnedHidden(_peer, true); - if (hidden) { - Notify::peerUpdatedDelayed( - _peer, - Notify::PeerUpdate::Flag::PinnedMessageChanged); - } - Ui::hideLayer(); -} - -void UnpinMessageBox::unpinDone(const MTPUpdates &updates) { - _peer->session().api().applyUpdates(updates); - Ui::hideLayer(); -} - -bool UnpinMessageBox::unpinFail(const RPCError &error) { - if (MTP::isDefaultHandledError(error)) return false; - Ui::hideLayer(); - return true; -} - DeleteMessagesBox::DeleteMessagesBox( QWidget*, not_null item, diff --git a/Telegram/SourceFiles/boxes/confirm_box.h b/Telegram/SourceFiles/boxes/confirm_box.h index f8635e798..d3c53edda 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.h +++ b/Telegram/SourceFiles/boxes/confirm_box.h @@ -149,30 +149,6 @@ private: }; -class UnpinMessageBox : public Ui::BoxContent, public RPCSender { -public: - UnpinMessageBox(QWidget*, not_null peer); - -protected: - void prepare() override; - - void resizeEvent(QResizeEvent *e) override; - void keyPressEvent(QKeyEvent *e) override; - -private: - void unpinMessage(); - void hideMessage(); - void unpinDone(const MTPUpdates &updates); - bool unpinFail(const RPCError &error); - - not_null _peer; - - object_ptr _text; - - mtpRequestId _requestId = 0; - -}; - class DeleteMessagesBox : public Ui::BoxContent, public RPCSender { public: DeleteMessagesBox( diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 8c003184a..2030e966e 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/send_files_box.h" #include "boxes/share_box.h" #include "boxes/edit_caption_box.h" +#include "kotato/boxes/unpin_box.h" #include "core/file_utilities.h" #include "ui/toast/toast.h" #include "ui/special_buttons.h" diff --git a/Telegram/SourceFiles/kotato/boxes/unpin_box.cpp b/Telegram/SourceFiles/kotato/boxes/unpin_box.cpp new file mode 100644 index 000000000..fc877c2e3 --- /dev/null +++ b/Telegram/SourceFiles/kotato/boxes/unpin_box.cpp @@ -0,0 +1,88 @@ +/* +This file is part of Kotatogram Desktop, +the unofficial app based on Telegram Desktop. + +For license and copyright information please follow this link: +https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL +*/ +#include "kotato/boxes/unpin_box.h" + +#include "lang/lang_keys.h" +#include "apiwrap.h" +#include "history/history_widget.h" +#include "ui/widgets/labels.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" +#include "main/main_session.h" +#include "observer_peer.h" +#include "styles/style_layers.h" +#include "styles/style_boxes.h" + +UnpinMessageBox::UnpinMessageBox( + QWidget*, + not_null peer) +: _peer(peer) +, _text(this, tr::lng_pinned_unpin_sure(tr::now), st::boxLabel) { +} + +void UnpinMessageBox::prepare() { + addLeftButton(tr::ktg_hide_pinned_message(), [this] { hideMessage(); }); + + addButton(tr::lng_pinned_unpin(), [this] { unpinMessage(); }); + addButton(tr::lng_cancel(), [this] { closeBox(); }); + + auto height = st::boxPadding.top() + _text->height() + st::boxPadding.bottom(); + setDimensions(st::boxWidth, height); +} + +void UnpinMessageBox::resizeEvent(QResizeEvent *e) { + BoxContent::resizeEvent(e); + _text->moveToLeft(st::boxPadding.left(), st::boxPadding.top()); +} + +void UnpinMessageBox::keyPressEvent(QKeyEvent *e) { + if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { + unpinMessage(); + } else if (e->key() == Qt::Key_Backspace) { + hideMessage(); + } else { + BoxContent::keyPressEvent(e); + } +} + +void UnpinMessageBox::unpinMessage() { + if (_requestId) return; + + _requestId = MTP::send( + MTPmessages_UpdatePinnedMessage( + MTP_flags(0), + _peer->input, + MTP_int(0)), + rpcDone(&UnpinMessageBox::unpinDone), + rpcFail(&UnpinMessageBox::unpinFail)); +} + +void UnpinMessageBox::hideMessage() { + if (_requestId) return; + + auto hidden = HistoryWidget::switchPinnedHidden(_peer, true); + if (hidden) { + Notify::peerUpdatedDelayed( + _peer, + Notify::PeerUpdate::Flag::PinnedMessageChanged); + } + Ui::hideLayer(); +} + +void UnpinMessageBox::unpinDone(const MTPUpdates &updates) { + _peer->session().api().applyUpdates(updates); + Ui::hideLayer(); +} + +bool UnpinMessageBox::unpinFail(const RPCError &error) { + if (MTP::isDefaultHandledError(error)) return false; + Ui::hideLayer(); + return true; +} + diff --git a/Telegram/SourceFiles/kotato/boxes/unpin_box.h b/Telegram/SourceFiles/kotato/boxes/unpin_box.h new file mode 100644 index 000000000..3b0d0ae22 --- /dev/null +++ b/Telegram/SourceFiles/kotato/boxes/unpin_box.h @@ -0,0 +1,39 @@ +/* +This file is part of Kotatogram Desktop, +the unofficial app based on Telegram Desktop. + +For license and copyright information please follow this link: +https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL +*/ +#pragma once + +#include "boxes/abstract_box.h" +#include "mtproto/mtproto_rpc_sender.h" + +namespace Ui { +class FlatLabel; +} // namespace Ui + +class UnpinMessageBox : public Ui::BoxContent, public RPCSender { +public: + UnpinMessageBox(QWidget*, not_null peer); + +protected: + void prepare() override; + + void resizeEvent(QResizeEvent *e) override; + void keyPressEvent(QKeyEvent *e) override; + +private: + void unpinMessage(); + void hideMessage(); + void unpinDone(const MTPUpdates &updates); + bool unpinFail(const RPCError &error); + + not_null _peer; + + object_ptr _text; + + mtpRequestId _requestId = 0; + +};