mirror of https://github.com/procxx/kepka.git
				
				
				
			PinMessageBox: show notify checkbox only for group
Prepare for pinning messages in Channels, in which we are could not
disable the pin notification.
Based on upstream commit
75d8d01b17
Related to #8, #114.
			
			
This commit is contained in:
		
							parent
							
								
									265cd836ef
								
							
						
					
					
						commit
						dd003ffb7d
					
				| 
						 | 
					@ -387,22 +387,31 @@ void ConvertToSupergroupBox::paintEvent(QPaintEvent *e) {
 | 
				
			||||||
PinMessageBox::PinMessageBox(QWidget *, ChannelData *channel, MsgId msgId)
 | 
					PinMessageBox::PinMessageBox(QWidget *, ChannelData *channel, MsgId msgId)
 | 
				
			||||||
    : _channel(channel)
 | 
					    : _channel(channel)
 | 
				
			||||||
    , _msgId(msgId)
 | 
					    , _msgId(msgId)
 | 
				
			||||||
    , _text(this, lang(lng_pinned_pin_sure), Ui::FlatLabel::InitType::Simple, st::boxLabel)
 | 
					    , _text(this, lang(lng_pinned_pin_sure), Ui::FlatLabel::InitType::Simple, st::boxLabel) {}
 | 
				
			||||||
    , _notify(this, lang(lng_pinned_notify), true, st::defaultBoxCheckbox) {}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PinMessageBox::prepare() {
 | 
					void PinMessageBox::prepare() {
 | 
				
			||||||
 | 
						if (_channel->isMegagroup()) {
 | 
				
			||||||
 | 
							_notify.create(this, lang(lng_pinned_notify), true, st::defaultBoxCheckbox);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						auto height = st::boxPadding.top() + _text->height() + st::boxPadding.bottom();
 | 
				
			||||||
 | 
						if (_notify) {
 | 
				
			||||||
 | 
							height += st::boxMediumSkip + _notify->heightNoMargins();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	addButton(langFactory(lng_pinned_pin), [this] { pinMessage(); });
 | 
						addButton(langFactory(lng_pinned_pin), [this] { pinMessage(); });
 | 
				
			||||||
	addButton(langFactory(lng_cancel), [this] { closeBox(); });
 | 
						addButton(langFactory(lng_cancel), [this] { closeBox(); });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	setDimensions(st::boxWidth, st::boxPadding.top() + _text->height() + st::boxMediumSkip +
 | 
						setDimensions(st::boxWidth, height);
 | 
				
			||||||
	                                _notify->heightNoMargins() + st::boxPadding.bottom());
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PinMessageBox::resizeEvent(QResizeEvent *e) {
 | 
					void PinMessageBox::resizeEvent(QResizeEvent *e) {
 | 
				
			||||||
	BoxContent::resizeEvent(e);
 | 
						BoxContent::resizeEvent(e);
 | 
				
			||||||
	_text->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
 | 
						_text->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
 | 
				
			||||||
 | 
						if (_notify) {
 | 
				
			||||||
		_notify->moveToLeft(st::boxPadding.left(), _text->y() + _text->height() + st::boxMediumSkip);
 | 
							_notify->moveToLeft(st::boxPadding.left(), _text->y() + _text->height() + st::boxMediumSkip);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PinMessageBox::keyPressEvent(QKeyEvent *e) {
 | 
					void PinMessageBox::keyPressEvent(QKeyEvent *e) {
 | 
				
			||||||
	if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
 | 
						if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
 | 
				
			||||||
| 
						 | 
					@ -416,7 +425,7 @@ void PinMessageBox::pinMessage() {
 | 
				
			||||||
	if (_requestId) return;
 | 
						if (_requestId) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto flags = MTPchannels_UpdatePinnedMessage::Flags(0);
 | 
						auto flags = MTPchannels_UpdatePinnedMessage::Flags(0);
 | 
				
			||||||
	if (!_notify->checked()) {
 | 
						if (_notify && !_notify->checked()) {
 | 
				
			||||||
		flags |= MTPchannels_UpdatePinnedMessage::Flag::f_silent;
 | 
							flags |= MTPchannels_UpdatePinnedMessage::Flag::f_silent;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	_requestId = MTP::send(MTPchannels_UpdatePinnedMessage(MTP_flags(flags), _channel->inputChannel, MTP_int(_msgId)),
 | 
						_requestId = MTP::send(MTPchannels_UpdatePinnedMessage(MTP_flags(flags), _channel->inputChannel, MTP_int(_msgId)),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -166,7 +166,7 @@ private:
 | 
				
			||||||
	MsgId _msgId;
 | 
						MsgId _msgId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	object_ptr<Ui::FlatLabel> _text;
 | 
						object_ptr<Ui::FlatLabel> _text;
 | 
				
			||||||
	object_ptr<Ui::Checkbox> _notify;
 | 
						object_ptr<Ui::Checkbox> _notify = {nullptr};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mtpRequestId _requestId = 0;
 | 
						mtpRequestId _requestId = 0;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue