Skip to content

Commit

Permalink
Allow admins just hide pinned messages (O#1790)
Browse files Browse the repository at this point in the history
Signed-off-by: Soltan Tekeev <[email protected]>
  • Loading branch information
Soltan Tekeev committed Apr 12, 2016
1 parent 463ff69 commit a23581a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
28 changes: 23 additions & 5 deletions Telegram/SourceFiles/historywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3982,6 +3982,7 @@ void HistoryWidget::updateControlsVisibility() {
if (_pinnedBar) {
_pinnedBar->cancel.hide();
_pinnedBar->shadow.hide();
_pinnedBar->hide.hide();
}
return;
}
Expand All @@ -3990,6 +3991,9 @@ void HistoryWidget::updateControlsVisibility() {
if (_pinnedBar) {
_pinnedBar->cancel.show();
_pinnedBar->shadow.show();
if (_peer->asChannel()->amCreator() || _peer->asChannel()->amEditor()) {
_pinnedBar->hide.show();
}
}
if (_firstLoadRequest && !_scroll.isHidden()) {
_scroll.hide();
Expand Down Expand Up @@ -5014,6 +5018,7 @@ void HistoryWidget::animShow(const QPixmap &bgAnimCache, const QPixmap &bgAnimTo
if (_pinnedBar) {
_pinnedBar->shadow.hide();
_pinnedBar->cancel.hide();
_pinnedBar->hide.hide();
}

a_coordUnder = back ? anim::ivalue(-qFloor(st::slideShift * width()), 0) : anim::ivalue(0, -qFloor(st::slideShift * width()));
Expand Down Expand Up @@ -6430,6 +6435,7 @@ void HistoryWidget::resizeEvent(QResizeEvent *e) {
_attachMention.setBoundings(_scroll.geometry());
}
_pinnedBar->cancel.move(width() - _pinnedBar->cancel.width(), 0);
_pinnedBar->hide.move(_pinnedBar->cancel.x() - _pinnedBar->hide.width(), 0);
_pinnedBar->shadow.setGeometry(0, st::replyHeight, width(), st::lineWidth);
} else if (_scroll.y() != 0) {
_scroll.move(0, 0);
Expand Down Expand Up @@ -7000,6 +7006,7 @@ void HistoryWidget::onInlineResultSend(InlineBots::Result *result, UserData *bot
HistoryWidget::PinnedBar::PinnedBar(MsgId msgId, HistoryWidget *parent)
: msgId(msgId)
, msg(0)
, hide(parent, lang(lng_report_spam_hide), st::reportSpamHide)
, cancel(parent, st::replyCancel)
, shadow(parent, st::shadowColor) {
}
Expand Down Expand Up @@ -7034,7 +7041,7 @@ void HistoryWidget::updatePinnedBar(bool force) {
bool HistoryWidget::pinnedMsgVisibilityUpdated() {
bool result = false;
MsgId pinnedMsgId = (_peer && _peer->isMegagroup()) ? _peer->asChannel()->mgInfo->pinnedMsgId : 0;
if (pinnedMsgId && !_peer->asChannel()->amCreator() && !_peer->asChannel()->amEditor()) {
if (pinnedMsgId /*&& !_peer->asChannel()->amCreator() && !_peer->asChannel()->amEditor()*/) {
Global::HiddenPinnedMessagesMap::const_iterator it = Global::HiddenPinnedMessages().constFind(_peer->id);
if (it != Global::HiddenPinnedMessages().cend()) {
if (it.value() == pinnedMsgId) {
Expand All @@ -7051,11 +7058,18 @@ bool HistoryWidget::pinnedMsgVisibilityUpdated() {
if (_a_show.animating()) {
_pinnedBar->cancel.hide();
_pinnedBar->shadow.hide();
_pinnedBar->hide.hide();
} else {
_pinnedBar->cancel.show();
_pinnedBar->shadow.show();
if (_peer->asChannel()->amCreator() || _peer->asChannel()->amEditor()) {
_pinnedBar->hide.show();
} else {
_pinnedBar->hide.hide();
}
}
connect(&_pinnedBar->cancel, SIGNAL(clicked()), this, SLOT(onPinnedHide()));
connect(&_pinnedBar->hide, SIGNAL(clicked()), this, SLOT(onPinnedHideForce()));
_reportSpamPanel.raise();
_sideShadow.raise();
_topShadow.raise();
Expand Down Expand Up @@ -7357,7 +7371,7 @@ void HistoryWidget::unpinDone(const MTPUpdates &updates) {
}
}

void HistoryWidget::onPinnedHide() {
void HistoryWidget::onPinnedHide(bool ignoreAdmin) {
if (!_peer || !_peer->isMegagroup()) return;
if (!_peer->asChannel()->mgInfo->pinnedMsgId) {
if (pinnedMsgVisibilityUpdated()) {
Expand All @@ -7367,7 +7381,7 @@ void HistoryWidget::onPinnedHide() {
return;
}

if (_peer->asChannel()->amCreator() || _peer->asChannel()->amEditor()) {
if (!ignoreAdmin && (_peer->asChannel()->amCreator() || _peer->asChannel()->amEditor())) {
onUnpinMessage();
} else {
Global::RefHiddenPinnedMessages().insert(_peer->id, _peer->asChannel()->mgInfo->pinnedMsgId);
Expand All @@ -7379,6 +7393,10 @@ void HistoryWidget::onPinnedHide() {
}
}

void HistoryWidget::onPinnedHideForce() {
onPinnedHide(true);
}

void HistoryWidget::onCopyPostLink() {
HistoryItem *to = App::contextItem();
if (!to || !to->hasDirectLink()) return;
Expand Down Expand Up @@ -8049,11 +8067,11 @@ void HistoryWidget::drawPinnedBar(Painter &p) {
p.drawText(left, st::msgReplyPadding.top() + st::msgServiceNameFont->ascent, lang(lng_pinned_message));

p.setPen((((_pinnedBar->msg->toHistoryMessage() && _pinnedBar->msg->toHistoryMessage()->emptyText()) || _pinnedBar->msg->serviceMsg()) ? st::msgInDateFg : st::msgColor)->p);
_pinnedBar->text.drawElided(p, left, st::msgReplyPadding.top() + st::msgServiceNameFont->height, width() - left -_fieldBarCancel.width() - st::msgReplyPadding.right());
_pinnedBar->text.drawElided(p, left, st::msgReplyPadding.top() + st::msgServiceNameFont->height, width() - left - (!_pinnedBar->hide.isHidden() ? _pinnedBar->hide.width() : 0) - _pinnedBar->cancel.width() - st::msgReplyPadding.right());
} else {
p.setFont(st::msgDateFont);
p.setPen(st::msgInDateFg);
p.drawText(left, st::msgReplyPadding.top() + (st::msgReplyBarSize.height() - st::msgDateFont->height) / 2 + st::msgDateFont->ascent, st::msgDateFont->elided(lang(lng_profile_loading), width() - left - _pinnedBar->cancel.width() - st::msgReplyPadding.right()));
p.drawText(left, st::msgReplyPadding.top() + (st::msgReplyBarSize.height() - st::msgDateFont->height) / 2 + st::msgDateFont->ascent, st::msgDateFont->elided(lang(lng_profile_loading), width() - left - (!_pinnedBar->hide.isHidden() ? _pinnedBar->hide.width() : 0) - _pinnedBar->cancel.width() - st::msgReplyPadding.right()));
}
}

Expand Down
4 changes: 3 additions & 1 deletion Telegram/SourceFiles/historywidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ public slots:
void onPinMessage();
void onUnpinMessage();
void onUnpinMessageSure();
void onPinnedHide();
void onPinnedHide(bool ignoreAdmin = false);
void onPinnedHideForce();
void onCopyPostLink();
void onFieldBarCancel();

Expand Down Expand Up @@ -844,6 +845,7 @@ private slots:
MsgId msgId = 0;
HistoryItem *msg = nullptr;
Text text;
FlatButton hide;
IconedButton cancel;
PlainShadow shadow;
};
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/profilewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,7 @@ void ProfileInner::updateInvitationLink() {
}

void ProfileInner::updatePinnedMessageVisibility() {
if (_peerChannel && _peerChannel->isMegagroup() && _peerChannel->mgInfo->pinnedMsgId && !_amCreator && !_peerChannel->amEditor()) {
if (_peerChannel && _peerChannel->isMegagroup() && _peerChannel->mgInfo->pinnedMsgId /*&& !_amCreator && !_peerChannel->amEditor()*/) {
_pinnedMessage.show();
} else {
_pinnedMessage.hide();
Expand Down

0 comments on commit a23581a

Please sign in to comment.