Add checkbox 'Pin also for {user}'.

This commit is contained in:
John Preston 2020-10-23 10:04:28 +03:00
parent 77894d1445
commit c2753a9caf
4 changed files with 31 additions and 5 deletions

View file

@ -166,10 +166,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_pinned_quiz" = "Pinned quiz"; "lng_pinned_quiz" = "Pinned quiz";
"lng_pinned_unpin_sure" = "Would you like to unpin this message?"; "lng_pinned_unpin_sure" = "Would you like to unpin this message?";
"lng_pinned_pin_sure" = "Would you like to pin this message?"; "lng_pinned_pin_sure" = "Would you like to pin this message?";
"lng_pinned_pin_sure_group" = "Do you want to pin this message for all members in the group?";
"lng_pinned_pin_old_sure" = "Do you want to pin an older message while leaving a more recent one pinned?"; "lng_pinned_pin_old_sure" = "Do you want to pin an older message while leaving a more recent one pinned?";
"lng_pinned_pin" = "Pin"; "lng_pinned_pin" = "Pin";
"lng_pinned_unpin" = "Unpin"; "lng_pinned_unpin" = "Unpin";
"lng_pinned_notify" = "Notify all members"; "lng_pinned_notify" = "Notify all members";
"lng_pinned_also_for_other" = "Also pin for {user}";
"lng_pinned_messages_title#one" = "{count} pinned message"; "lng_pinned_messages_title#one" = "{count} pinned message";
"lng_pinned_messages_title#other" = "{count} pinned messages"; "lng_pinned_messages_title#other" = "{count} pinned messages";
"lng_pinned_hide_all" = "Don't show pinned messages"; "lng_pinned_hide_all" = "Don't show pinned messages";

View file

@ -464,6 +464,8 @@ PinMessageBox::PinMessageBox(
this, this,
(_pinningOld (_pinningOld
? tr::lng_pinned_pin_old_sure(tr::now) ? 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)), : tr::lng_pinned_pin_sure(tr::now)),
st::boxLabel) { st::boxLabel) {
} }
@ -473,12 +475,27 @@ void PinMessageBox::prepare() {
addButton(tr::lng_cancel(), [this] { closeBox(); }); addButton(tr::lng_cancel(), [this] { closeBox(); });
if (!_pinningOld && (_peer->isChat() || _peer->isMegagroup())) { if (!_pinningOld && (_peer->isChat() || _peer->isMegagroup())) {
_notify.create(this, tr::lng_pinned_notify(tr::now), true, st::defaultBoxCheckbox); _notify.create(
this,
tr::lng_pinned_notify(tr::now),
true,
st::defaultBoxCheckbox);
_checkbox = _notify;
} else if (_peer->isUser() && !_peer->isSelf()) {
_pinForPeer.create(
this,
tr::lng_pinned_also_for_other(
tr::now,
lt_user,
_peer->shortName()),
true,
st::defaultBoxCheckbox);
_checkbox = _pinForPeer;
} }
auto height = st::boxPadding.top() + _text->height() + st::boxPadding.bottom(); auto height = st::boxPadding.top() + _text->height() + st::boxPadding.bottom();
if (_notify) { if (_checkbox) {
height += st::boxMediumSkip + _notify->heightNoMargins(); height += st::boxMediumSkip + _checkbox->heightNoMargins();
} }
setDimensions(st::boxWidth, height); setDimensions(st::boxWidth, height);
} }
@ -486,8 +503,8 @@ void PinMessageBox::prepare() {
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) { if (_checkbox) {
_notify->moveToLeft(st::boxPadding.left(), _text->y() + _text->height() + st::boxMediumSkip); _checkbox->moveToLeft(st::boxPadding.left(), _text->y() + _text->height() + st::boxMediumSkip);
} }
} }
@ -506,6 +523,9 @@ void PinMessageBox::pinMessage() {
if (_notify && !_notify->checked()) { if (_notify && !_notify->checked()) {
flags |= MTPmessages_UpdatePinnedMessage::Flag::f_silent; flags |= MTPmessages_UpdatePinnedMessage::Flag::f_silent;
} }
if (_pinForPeer && !_pinForPeer->checked()) {
flags |= MTPmessages_UpdatePinnedMessage::Flag::f_pm_oneside;
}
_requestId = _api.request(MTPmessages_UpdatePinnedMessage( _requestId = _api.request(MTPmessages_UpdatePinnedMessage(
MTP_flags(flags), MTP_flags(flags),
_peer->input, _peer->input,

View file

@ -188,6 +188,8 @@ private:
object_ptr<Ui::FlatLabel> _text; object_ptr<Ui::FlatLabel> _text;
object_ptr<Ui::Checkbox> _notify = { nullptr }; object_ptr<Ui::Checkbox> _notify = { nullptr };
object_ptr<Ui::Checkbox> _pinForPeer = { nullptr };
QPointer<Ui::Checkbox> _checkbox;
mtpRequestId _requestId = 0; mtpRequestId _requestId = 0;

View file

@ -537,6 +537,8 @@ void HistoryItem::setRealId(MsgId newId) {
bool HistoryItem::canPin() const { bool HistoryItem::canPin() const {
if (id < 0 || !toHistoryMessage()) { if (id < 0 || !toHistoryMessage()) {
return false; return false;
} else if (const auto m = media(); m && m->call()) {
return false;
} }
return _history->peer->canPinMessages(); return _history->peer->canPinMessages();
} }