diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 4a3378556..779311b55 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2481,4 +2481,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ktg_settings_messages" = "Messages"; +"ktg_hide_pinned_message" = "Hide"; + // Keys finished diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json index 25a3ef5af..ce595c01b 100644 --- a/Telegram/Resources/langs/rewrites/ru.json +++ b/Telegram/Resources/langs/rewrites/ru.json @@ -108,5 +108,6 @@ "ktg_settings_filters_hide_folder_names": "Компактные папки", "ktg_settings_top_bar_mute": "Уведомления вверху профиля", "ktg_settings_messages": "Сообщения", - "ktg_settings_filters_hide_all": "Скрыть папку «Все чаты»" + "ktg_settings_filters_hide_all": "Скрыть папку «Все чаты»", + "ktg_hide_pinned_message": "Скрыть" } diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 4839c5269..20829d1cb 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "history/history.h" #include "history/history_item.h" +#include "history/history_widget.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" @@ -493,6 +494,73 @@ 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 d3c53edda..f8635e798 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.h +++ b/Telegram/SourceFiles/boxes/confirm_box.h @@ -149,6 +149,30 @@ 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 a31f11012..8c003184a 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -6187,21 +6187,7 @@ void HistoryWidget::unpinMessage(FullMsgId itemId) { return; } - Ui::show(Box(tr::lng_pinned_unpin_sure(tr::now), tr::lng_pinned_unpin(tr::now), crl::guard(this, [=] { - peer->clearPinnedMessage(); - - Ui::hideLayer(); - MTP::send( - MTPmessages_UpdatePinnedMessage( - MTP_flags(0), - peer->input, - MTP_int(0)), - rpcDone(&HistoryWidget::unpinDone)); - }))); -} - -void HistoryWidget::unpinDone(const MTPUpdates &updates) { - session().api().applyUpdates(updates); + Ui::show(Box(peer)); } void HistoryWidget::hidePinnedMessage(bool force) { diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index d98e41109..2cfb46ab9 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -540,7 +540,6 @@ private: void updatePinnedBar(bool force = false); bool pinnedMsgVisibilityUpdated(); void destroyPinnedBar(); - void unpinDone(const MTPUpdates &updates); void sendInlineResult( not_null result,