diff --git a/Telegram/SourceFiles/data/data_messages.cpp b/Telegram/SourceFiles/data/data_messages.cpp index 65ef717c97..6e312cbd93 100644 --- a/Telegram/SourceFiles/data/data_messages.cpp +++ b/Telegram/SourceFiles/data/data_messages.cpp @@ -135,6 +135,7 @@ void MessagesList::addSlice( } void MessagesList::removeOne(MessagePosition messageId) { + auto update = MessagesSliceUpdate(); auto slice = ranges::lower_bound( _slices, messageId, @@ -144,10 +145,16 @@ void MessagesList::removeOne(MessagePosition messageId) { _slices.modify(slice, [&](Slice &slice) { return slice.messages.remove(messageId); }); + update.messages = &slice->messages; + update.range = slice->range; } if (_count) { --*_count; } + update.count = _count; + if (update.messages) { + _sliceUpdated.fire(std::move(update)); + } } void MessagesList::removeAll(ChannelId channelId) { @@ -188,6 +195,8 @@ void MessagesList::removeLessThan(MessagePosition messageId) { } }); break; + } else { + break; } } if (removed && _count) { diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 705ff00fdd..a92dd5ab7c 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -4973,9 +4973,6 @@ void HistoryWidget::mousePressEvent(QMouseEvent *e) { } else { Ui::showPeerHistory(_peer, _editMsgId ? _editMsgId : replyToId()); } - //} else if (_inPinnedMsg) { // #TODO pinned - // Assert(_pinnedBar != nullptr); - // Ui::showPeerHistory(_peer, _pinnedBar->msgId); } } @@ -5266,6 +5263,14 @@ void HistoryWidget::checkPinnedBarState() { hidePinnedMessage(); }, _pinnedBar->lifetime()); + _pinnedBar->barClicks( + ) | rpl::start_with_next([=] { + const auto id = _pinnedTracker->currentMessageId(); + if (id.message) { + Ui::showPeerHistory(_peer, id.message); + } + }, _pinnedBar->lifetime()); + _pinnedBarHeight = 0; _pinnedBar->heightValue( ) | rpl::start_with_next([=](int height) { @@ -6369,10 +6374,6 @@ void HistoryWidget::drawRecording(Painter &p, float64 recordActive) { // // } // // left += st::msgReplyBarSize.height() + st::msgReplyBarSkip - st::msgReplyBarSize.width() - st::msgReplyBarPos.x(); // // } -// //} else { -// // p.setFont(st::msgDateFont); -// // p.setPen(st::historyComposeAreaFgService); -// // p.drawText(left, top + (st::msgReplyBarSize.height() - st::msgDateFont->height) / 2 + st::msgDateFont->ascent, st::msgDateFont->elided(tr::lng_profile_loading(tr::now), width() - left - _pinnedBar->cancel->width() - st::msgReplyPadding.right())); // //} //} diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp index c8af04b240..824705a775 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp @@ -35,7 +35,7 @@ namespace { return Ui::MessageBarContent{ .id = item->id, .title = ((type == PinnedIdType::First) - ? "First message" + ? tr::lng_pinned_previous(tr::now) // #TODO pinned first? : (type == PinnedIdType::Middle) ? tr::lng_pinned_previous(tr::now) : !poll @@ -148,6 +148,24 @@ void PinnedBar::createControls() { _close->raise(); } + // Clicks. + _bar->widget()->setCursor(style::cur_pointer); + _bar->widget()->events( + ) | rpl::filter([=](not_null event) { + return (event->type() == QEvent::MouseButtonPress); + }) | rpl::map([=] { + return _bar->widget()->events( + ) | rpl::filter([=](not_null event) { + return (event->type() == QEvent::MouseButtonRelease); + }) | rpl::take(1) | rpl::filter([=](not_null event) { + return _bar->widget()->rect().contains( + static_cast(event.get())->pos()); + }); + }) | rpl::flatten_latest( + ) | rpl::map([] { + return rpl::empty_value(); + }) | rpl::start_to_stream(_barClicks, _bar->widget()->lifetime()); + _bar->widget()->move(0, 0); _bar->widget()->show(); _wrap.entity()->resize(_wrap.entity()->width(), _bar->widget()->height()); @@ -233,4 +251,8 @@ rpl::producer<> PinnedBar::closeClicks() const { : (_close->clicks() | rpl::map([] { return rpl::empty_value(); })); } -} // namespace HistoryView \ No newline at end of file +rpl::producer<> PinnedBar::barClicks() const { + return _barClicks.events(); +} + +} // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_bar.h b/Telegram/SourceFiles/history/view/history_view_pinned_bar.h index 397cbc92f8..469e6f2a16 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_bar.h +++ b/Telegram/SourceFiles/history/view/history_view_pinned_bar.h @@ -51,6 +51,7 @@ public: [[nodiscard]] int height() const; [[nodiscard]] rpl::producer heightValue() const; [[nodiscard]] rpl::producer<> closeClicks() const; + [[nodiscard]] rpl::producer<> barClicks() const; [[nodiscard]] rpl::lifetime &lifetime() { return _wrap.lifetime(); @@ -64,6 +65,7 @@ private: std::unique_ptr _close; std::unique_ptr _shadow; rpl::event_stream _content; + rpl::event_stream<> _barClicks; bool _shouldBeShown = false; bool _forceHidden = false; diff --git a/Telegram/SourceFiles/ui/chat/message_bar.cpp b/Telegram/SourceFiles/ui/chat/message_bar.cpp index 05a02f16cf..1cb11a7ae7 100644 --- a/Telegram/SourceFiles/ui/chat/message_bar.cpp +++ b/Telegram/SourceFiles/ui/chat/message_bar.cpp @@ -49,12 +49,13 @@ MessageBar::BodyAnimation MessageBar::DetectBodyAnimationType( const auto now = currentAnimation ? currentAnimation->bodyAnimation : BodyAnimation::None; + const auto somethingChanged = (currentContent.text != nextContent.text) + || (currentContent.id != nextContent.id); return (now == BodyAnimation::Full - || currentContent.title != nextContent.title) + || currentContent.title != nextContent.title + || (currentContent.title.isEmpty() && somethingChanged)) ? BodyAnimation::Full - : (now == BodyAnimation::Text - || currentContent.text != nextContent.text - || currentContent.id != nextContent.id) + : (now == BodyAnimation::Text || somethingChanged) ? BodyAnimation::Text : BodyAnimation::None; } @@ -275,9 +276,20 @@ void MessageBar::paint(Painter &p) { } } if (!_animation || _animation->bodyAnimation == BodyAnimation::None) { - p.setPen(_st.textFg); - p.setTextPalette(_st.textPalette); - _text.drawLeftElided(p, body.x(), text.y(), body.width(), width); + if (_title.isEmpty()) { + // "Loading..." state. + p.setPen(st::historyComposeAreaFgService); + _text.drawLeftElided( + p, + body.x(), + body.y() + (body.height() - st::normalFont->height) / 2, + body.width(), + width); + } else { + p.setPen(_st.textFg); + p.setTextPalette(_st.textPalette); + _text.drawLeftElided(p, body.x(), text.y(), body.width(), width); + } } else if (_animation->bodyAnimation == BodyAnimation::Text) { p.setOpacity(1. - progress); p.drawPixmap(