From 9f3048c1dc9df75245cc0e17d2a82c431d553ba5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 30 Jan 2018 16:17:50 +0300 Subject: [PATCH] Hide service messages from feed. --- .../history/view/history_view_element.cpp | 8 ++++-- .../history/view/history_view_element.h | 1 + .../history/view/history_view_list_widget.cpp | 10 +++---- .../history/view/history_view_message.cpp | 24 +++++++++------- .../view/history_view_service_message.cpp | 28 +++++++++++++++---- .../view/history_view_service_message.h | 1 + 6 files changed, 50 insertions(+), 22 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index c4e2c9f81..f877e9bae 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -169,7 +169,7 @@ void Element::setY(int y) { int Element::marginTop() const { const auto item = data(); auto result = 0; - if (!isHiddenByGroup()) { + if (!isHidden()) { if (isAttachedToPrevious()) { result += st::msgMarginTopAttached; } else { @@ -185,7 +185,7 @@ int Element::marginTop() const { int Element::marginBottom() const { const auto item = data(); - return isHiddenByGroup() ? 0 : st::msgMargin.bottom(); + return isHidden() ? 0 : st::msgMargin.bottom(); } bool Element::isUnderCursor() const { @@ -231,6 +231,10 @@ bool Element::isHiddenByGroup() const { return _flags & Flag::HiddenByGroup; } +bool Element::isHidden() const { + return isHiddenByGroup(); +} + void Element::refreshMedia() { _flags &= ~Flag::HiddenByGroup; diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 947cbb9de..519a00a0c 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -136,6 +136,7 @@ public: virtual int infoWidth() const; bool isHiddenByGroup() const; + virtual bool isHidden() const; // For blocks context this should be called only from recountAttachToPreviousInBlocks(). void setAttachToPrevious(bool attachToNext); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index b057e098a..e192b40a3 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -925,7 +925,7 @@ void ListWidget::updateItemsGeometry() { const auto first = [&] { for (auto i = 0; i != count; ++i) { const auto view = _items[i].get(); - if (view->isHiddenByGroup()) { + if (view->isHidden()) { view->setDisplayDate(false); } else { view->setDisplayDate(true); @@ -1552,7 +1552,7 @@ void ListWidget::updateDragSelection( } }; const auto changeView = [&](not_null view, bool add) { - if (!view->isHiddenByGroup()) { + if (!view->isHidden()) { changeGroup(view->data(), add); } }; @@ -2065,7 +2065,7 @@ void ListWidget::refreshAttachmentsAtIndex(int index) { const auto from = [&] { if (index > 0) { for (auto i = index - 1; i != 0; --i) { - if (!_items[i]->isHiddenByGroup()) { + if (!_items[i]->isHidden()) { return i; } } @@ -2075,7 +2075,7 @@ void ListWidget::refreshAttachmentsAtIndex(int index) { const auto till = [&] { const auto count = int(_items.size()); for (auto i = index + 1; i != count; ++i) { - if (!_items[i]->isHiddenByGroup()) { + if (!_items[i]->isHidden()) { return i + 1; } } @@ -2093,7 +2093,7 @@ void ListWidget::refreshAttachmentsFromTill(int from, int till) { auto view = _items[from].get(); for (auto i = from + 1; i != till; ++i) { const auto next = _items[i].get(); - if (next->isHiddenByGroup()) { + if (next->isHidden()) { next->setDisplayDate(false); } else { const auto viewDate = view->data()->date; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 7d5e9d677..9d57cce10 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -347,6 +347,11 @@ void Message::draw( QRect clip, TextSelection selection, TimeMs ms) const { + auto g = countGeometry(); + if (g.width() < 1) { + return; + } + const auto item = message(); const auto media = this->media(); @@ -354,11 +359,6 @@ void Message::draw( const auto bubble = drawBubble(); const auto selected = (selection == FullSelection); - auto g = countGeometry(); - if (g.width() < 1) { - return; - } - auto dateh = 0; if (const auto date = Get()) { dateh = date->height(); @@ -372,6 +372,10 @@ void Message::draw( } } + if (isHidden()) { + return; + } + auto fullAnimMs = App::main() ? App::main()->highlightStartTime(item) : 0LL; if (fullAnimMs > 0 && fullAnimMs <= ms) { auto animms = ms - fullAnimMs; @@ -609,7 +613,7 @@ void Message::paintText(Painter &p, QRect &trect, TextSelection selection) const PointState Message::pointState(QPoint point) const { const auto g = countGeometry(); - if (g.width() < 1) { + if (g.width() < 1 || isHidden()) { return PointState::Outside; } @@ -664,7 +668,7 @@ bool Message::displayFromPhoto() const { } bool Message::hasFromPhoto() const { - if (isHiddenByGroup()) { + if (isHidden()) { return false; } switch (context()) { @@ -695,7 +699,7 @@ TextState Message::textState( auto result = TextState(item); auto g = countGeometry(); - if (g.width() < 1) { + if (g.width() < 1 || isHidden()) { return result; } @@ -1289,7 +1293,7 @@ bool Message::hasOutLayout() const { bool Message::drawBubble() const { const auto item = message(); - if (isHiddenByGroup()) { + if (isHidden()) { return false; } else if (logEntryOriginal()) { return true; @@ -1532,7 +1536,7 @@ QRect Message::countGeometry() const { } int Message::resizeContentGetHeight(int newWidth) { - if (isHiddenByGroup()) { + if (isHidden()) { return marginTop() + marginBottom(); } else if (newWidth < st::msgMinWidth) { return height(); diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.cpp b/Telegram/SourceFiles/history/view/history_view_service_message.cpp index 3a0dd9813..aa1f02f59 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_service_message.cpp @@ -311,14 +311,18 @@ QRect Service::countGeometry() const { } QSize Service::performCountCurrentSize(int newWidth) { - const auto item = message(); - const auto media = this->media(); - auto newHeight = displayedDateHeight(); if (const auto bar = Get()) { newHeight += bar->height(); } + if (isHidden()) { + return { newWidth, newHeight }; + } + + const auto item = message(); + const auto media = this->media(); + if (item->_text.isEmpty()) { item->_textHeight = 0; } else { @@ -362,6 +366,13 @@ QSize Service::performCountOptimalSize() { return { maxWidth, minHeight }; } +bool Service::isHidden() const { + if (context() == Context::Feed) { + return true; + } + return Element::isHidden(); +} + void Service::draw( Painter &p, QRect clip, @@ -392,6 +403,13 @@ void Service::draw( height -= unreadbarh; } + if (isHidden()) { + if (auto skiph = dateh + unreadbarh) { + p.translate(0, -skiph); + } + return; + } + auto fullAnimMs = App::main() ? App::main()->highlightStartTime(item) : 0LL; if (fullAnimMs > 0 && fullAnimMs <= ms) { auto animms = ms - fullAnimMs; @@ -441,7 +459,7 @@ PointState Service::pointState(QPoint point) const { const auto media = this->media(); auto g = countGeometry(); - if (g.width() < 1) { + if (g.width() < 1 || isHidden()) { return PointState::Outside; } @@ -464,7 +482,7 @@ TextState Service::textState(QPoint point, StateRequest request) const { auto result = TextState(item); auto g = countGeometry(); - if (g.width() < 1) { + if (g.width() < 1 || isHidden()) { return result; } diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.h b/Telegram/SourceFiles/history/view/history_view_service_message.h index 87c66f96a..ea673310c 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.h +++ b/Telegram/SourceFiles/history/view/history_view_service_message.h @@ -19,6 +19,7 @@ public: not_null delegate, not_null data); + bool isHidden() const override; void draw( Painter &p, QRect clip,