Hide service messages from feed.

This commit is contained in:
John Preston 2018-01-30 16:17:50 +03:00
parent 2586268b81
commit 9f3048c1dc
6 changed files with 50 additions and 22 deletions

View File

@ -169,7 +169,7 @@ void Element::setY(int y) {
int Element::marginTop() const { int Element::marginTop() const {
const auto item = data(); const auto item = data();
auto result = 0; auto result = 0;
if (!isHiddenByGroup()) { if (!isHidden()) {
if (isAttachedToPrevious()) { if (isAttachedToPrevious()) {
result += st::msgMarginTopAttached; result += st::msgMarginTopAttached;
} else { } else {
@ -185,7 +185,7 @@ int Element::marginTop() const {
int Element::marginBottom() const { int Element::marginBottom() const {
const auto item = data(); const auto item = data();
return isHiddenByGroup() ? 0 : st::msgMargin.bottom(); return isHidden() ? 0 : st::msgMargin.bottom();
} }
bool Element::isUnderCursor() const { bool Element::isUnderCursor() const {
@ -231,6 +231,10 @@ bool Element::isHiddenByGroup() const {
return _flags & Flag::HiddenByGroup; return _flags & Flag::HiddenByGroup;
} }
bool Element::isHidden() const {
return isHiddenByGroup();
}
void Element::refreshMedia() { void Element::refreshMedia() {
_flags &= ~Flag::HiddenByGroup; _flags &= ~Flag::HiddenByGroup;

View File

@ -136,6 +136,7 @@ public:
virtual int infoWidth() const; virtual int infoWidth() const;
bool isHiddenByGroup() const; bool isHiddenByGroup() const;
virtual bool isHidden() const;
// For blocks context this should be called only from recountAttachToPreviousInBlocks(). // For blocks context this should be called only from recountAttachToPreviousInBlocks().
void setAttachToPrevious(bool attachToNext); void setAttachToPrevious(bool attachToNext);

View File

@ -925,7 +925,7 @@ void ListWidget::updateItemsGeometry() {
const auto first = [&] { const auto first = [&] {
for (auto i = 0; i != count; ++i) { for (auto i = 0; i != count; ++i) {
const auto view = _items[i].get(); const auto view = _items[i].get();
if (view->isHiddenByGroup()) { if (view->isHidden()) {
view->setDisplayDate(false); view->setDisplayDate(false);
} else { } else {
view->setDisplayDate(true); view->setDisplayDate(true);
@ -1552,7 +1552,7 @@ void ListWidget::updateDragSelection(
} }
}; };
const auto changeView = [&](not_null<Element*> view, bool add) { const auto changeView = [&](not_null<Element*> view, bool add) {
if (!view->isHiddenByGroup()) { if (!view->isHidden()) {
changeGroup(view->data(), add); changeGroup(view->data(), add);
} }
}; };
@ -2065,7 +2065,7 @@ void ListWidget::refreshAttachmentsAtIndex(int index) {
const auto from = [&] { const auto from = [&] {
if (index > 0) { if (index > 0) {
for (auto i = index - 1; i != 0; --i) { for (auto i = index - 1; i != 0; --i) {
if (!_items[i]->isHiddenByGroup()) { if (!_items[i]->isHidden()) {
return i; return i;
} }
} }
@ -2075,7 +2075,7 @@ void ListWidget::refreshAttachmentsAtIndex(int index) {
const auto till = [&] { const auto till = [&] {
const auto count = int(_items.size()); const auto count = int(_items.size());
for (auto i = index + 1; i != count; ++i) { for (auto i = index + 1; i != count; ++i) {
if (!_items[i]->isHiddenByGroup()) { if (!_items[i]->isHidden()) {
return i + 1; return i + 1;
} }
} }
@ -2093,7 +2093,7 @@ void ListWidget::refreshAttachmentsFromTill(int from, int till) {
auto view = _items[from].get(); auto view = _items[from].get();
for (auto i = from + 1; i != till; ++i) { for (auto i = from + 1; i != till; ++i) {
const auto next = _items[i].get(); const auto next = _items[i].get();
if (next->isHiddenByGroup()) { if (next->isHidden()) {
next->setDisplayDate(false); next->setDisplayDate(false);
} else { } else {
const auto viewDate = view->data()->date; const auto viewDate = view->data()->date;

View File

@ -347,6 +347,11 @@ void Message::draw(
QRect clip, QRect clip,
TextSelection selection, TextSelection selection,
TimeMs ms) const { TimeMs ms) const {
auto g = countGeometry();
if (g.width() < 1) {
return;
}
const auto item = message(); const auto item = message();
const auto media = this->media(); const auto media = this->media();
@ -354,11 +359,6 @@ void Message::draw(
const auto bubble = drawBubble(); const auto bubble = drawBubble();
const auto selected = (selection == FullSelection); const auto selected = (selection == FullSelection);
auto g = countGeometry();
if (g.width() < 1) {
return;
}
auto dateh = 0; auto dateh = 0;
if (const auto date = Get<DateBadge>()) { if (const auto date = Get<DateBadge>()) {
dateh = date->height(); dateh = date->height();
@ -372,6 +372,10 @@ void Message::draw(
} }
} }
if (isHidden()) {
return;
}
auto fullAnimMs = App::main() ? App::main()->highlightStartTime(item) : 0LL; auto fullAnimMs = App::main() ? App::main()->highlightStartTime(item) : 0LL;
if (fullAnimMs > 0 && fullAnimMs <= ms) { if (fullAnimMs > 0 && fullAnimMs <= ms) {
auto animms = ms - fullAnimMs; auto animms = ms - fullAnimMs;
@ -609,7 +613,7 @@ void Message::paintText(Painter &p, QRect &trect, TextSelection selection) const
PointState Message::pointState(QPoint point) const { PointState Message::pointState(QPoint point) const {
const auto g = countGeometry(); const auto g = countGeometry();
if (g.width() < 1) { if (g.width() < 1 || isHidden()) {
return PointState::Outside; return PointState::Outside;
} }
@ -664,7 +668,7 @@ bool Message::displayFromPhoto() const {
} }
bool Message::hasFromPhoto() const { bool Message::hasFromPhoto() const {
if (isHiddenByGroup()) { if (isHidden()) {
return false; return false;
} }
switch (context()) { switch (context()) {
@ -695,7 +699,7 @@ TextState Message::textState(
auto result = TextState(item); auto result = TextState(item);
auto g = countGeometry(); auto g = countGeometry();
if (g.width() < 1) { if (g.width() < 1 || isHidden()) {
return result; return result;
} }
@ -1289,7 +1293,7 @@ bool Message::hasOutLayout() const {
bool Message::drawBubble() const { bool Message::drawBubble() const {
const auto item = message(); const auto item = message();
if (isHiddenByGroup()) { if (isHidden()) {
return false; return false;
} else if (logEntryOriginal()) { } else if (logEntryOriginal()) {
return true; return true;
@ -1532,7 +1536,7 @@ QRect Message::countGeometry() const {
} }
int Message::resizeContentGetHeight(int newWidth) { int Message::resizeContentGetHeight(int newWidth) {
if (isHiddenByGroup()) { if (isHidden()) {
return marginTop() + marginBottom(); return marginTop() + marginBottom();
} else if (newWidth < st::msgMinWidth) { } else if (newWidth < st::msgMinWidth) {
return height(); return height();

View File

@ -311,14 +311,18 @@ QRect Service::countGeometry() const {
} }
QSize Service::performCountCurrentSize(int newWidth) { QSize Service::performCountCurrentSize(int newWidth) {
const auto item = message();
const auto media = this->media();
auto newHeight = displayedDateHeight(); auto newHeight = displayedDateHeight();
if (const auto bar = Get<UnreadBar>()) { if (const auto bar = Get<UnreadBar>()) {
newHeight += bar->height(); newHeight += bar->height();
} }
if (isHidden()) {
return { newWidth, newHeight };
}
const auto item = message();
const auto media = this->media();
if (item->_text.isEmpty()) { if (item->_text.isEmpty()) {
item->_textHeight = 0; item->_textHeight = 0;
} else { } else {
@ -362,6 +366,13 @@ QSize Service::performCountOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
bool Service::isHidden() const {
if (context() == Context::Feed) {
return true;
}
return Element::isHidden();
}
void Service::draw( void Service::draw(
Painter &p, Painter &p,
QRect clip, QRect clip,
@ -392,6 +403,13 @@ void Service::draw(
height -= unreadbarh; height -= unreadbarh;
} }
if (isHidden()) {
if (auto skiph = dateh + unreadbarh) {
p.translate(0, -skiph);
}
return;
}
auto fullAnimMs = App::main() ? App::main()->highlightStartTime(item) : 0LL; auto fullAnimMs = App::main() ? App::main()->highlightStartTime(item) : 0LL;
if (fullAnimMs > 0 && fullAnimMs <= ms) { if (fullAnimMs > 0 && fullAnimMs <= ms) {
auto animms = ms - fullAnimMs; auto animms = ms - fullAnimMs;
@ -441,7 +459,7 @@ PointState Service::pointState(QPoint point) const {
const auto media = this->media(); const auto media = this->media();
auto g = countGeometry(); auto g = countGeometry();
if (g.width() < 1) { if (g.width() < 1 || isHidden()) {
return PointState::Outside; return PointState::Outside;
} }
@ -464,7 +482,7 @@ TextState Service::textState(QPoint point, StateRequest request) const {
auto result = TextState(item); auto result = TextState(item);
auto g = countGeometry(); auto g = countGeometry();
if (g.width() < 1) { if (g.width() < 1 || isHidden()) {
return result; return result;
} }

View File

@ -19,6 +19,7 @@ public:
not_null<ElementDelegate*> delegate, not_null<ElementDelegate*> delegate,
not_null<HistoryService*> data); not_null<HistoryService*> data);
bool isHidden() const override;
void draw( void draw(
Painter &p, Painter &p,
QRect clip, QRect clip,