Moved unpin box
This commit is contained in:
		
							parent
							
								
									1141adfb30
								
							
						
					
					
						commit
						7ba072b0dd
					
				
					 6 changed files with 130 additions and 91 deletions
				
			
		|  | @ -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 | ||||
|  |  | |||
|  | @ -494,73 +494,6 @@ bool PinMessageBox::pinFail(const RPCError &error) { | |||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| UnpinMessageBox::UnpinMessageBox( | ||||
| 	QWidget*, | ||||
| 	not_null<PeerData*> 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<HistoryItem*> item, | ||||
|  |  | |||
|  | @ -149,30 +149,6 @@ private: | |||
| 
 | ||||
| }; | ||||
| 
 | ||||
| class UnpinMessageBox : public Ui::BoxContent, public RPCSender { | ||||
| public: | ||||
| 	UnpinMessageBox(QWidget*, not_null<PeerData*> 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<PeerData*> _peer; | ||||
| 
 | ||||
| 	object_ptr<Ui::FlatLabel> _text; | ||||
| 
 | ||||
| 	mtpRequestId _requestId = 0; | ||||
| 
 | ||||
| }; | ||||
| 
 | ||||
| class DeleteMessagesBox : public Ui::BoxContent, public RPCSender { | ||||
| public: | ||||
| 	DeleteMessagesBox( | ||||
|  |  | |||
|  | @ -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" | ||||
|  |  | |||
							
								
								
									
										88
									
								
								Telegram/SourceFiles/kotato/boxes/unpin_box.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								Telegram/SourceFiles/kotato/boxes/unpin_box.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -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<PeerData*> 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; | ||||
| } | ||||
| 
 | ||||
							
								
								
									
										39
									
								
								Telegram/SourceFiles/kotato/boxes/unpin_box.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								Telegram/SourceFiles/kotato/boxes/unpin_box.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -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<PeerData*> 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<PeerData*> _peer; | ||||
| 
 | ||||
| 	object_ptr<Ui::FlatLabel> _text; | ||||
| 
 | ||||
| 	mtpRequestId _requestId = 0; | ||||
| 
 | ||||
| }; | ||||
		Loading…
	
	Add table
		
		Reference in a new issue