diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 376327c8e..3438e8cb2 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -915,7 +915,6 @@ void HistoryInner::paintEvent(QPaintEvent *e) { const auto historyDisplayedEmpty = _history->isDisplayedEmpty() && (!_migrated || _migrated->isDisplayedEmpty()); - const auto translatedTo = _history->translatedTo(); if (_botAbout && !_botAbout->info->text.isEmpty() && _botAbout->height > 0) { const auto st = context.st; const auto stm = &st->messageStyle(false, false); @@ -969,7 +968,7 @@ void HistoryInner::paintEvent(QPaintEvent *e) { auto readContents = base::flat_set>(); const auto guard = gsl::finally([&] { if (_pinnedItem) { - _translateTracker->add(_pinnedItem, translatedTo); + _translateTracker->add(_pinnedItem); } _translateTracker->finishBunch(); if (readTill && _widget->markingMessagesRead()) { @@ -985,7 +984,7 @@ void HistoryInner::paintEvent(QPaintEvent *e) { not_null view, int top, int height) { - _translateTracker->add(view, translatedTo); + _translateTracker->add(view); const auto item = view->data(); const auto isSponsored = item->isSponsored(); const auto isUnread = !item->out() diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp index 4771a9cc4..fb6687eac 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp @@ -480,6 +480,7 @@ SlidingBar::SlidingBar( , _shadow(parent) { setup(parent); _wrapped.hide(anim::type::instant); + _shadow.hide(); } void SlidingBar::setup(not_null parent) { @@ -497,10 +498,13 @@ void SlidingBar::setup(not_null parent) { st::lineWidth); }, _shadow.lifetime()); - _wrapped.shownValue( - ) | rpl::start_with_next([=](bool shown) { - _shadow.setVisible(shown); - }, _shadow.lifetime()); + _shadow.showOn(rpl::combine( + _wrapped.shownValue(), + _wrapped.heightValue(), + rpl::mappers::_1 && rpl::mappers::_2 > 0 + ) | rpl::filter([=](bool shown) { + return (shown == _shadow.isHidden()); + })); } void SlidingBar::toggleContent(bool visible) { @@ -516,14 +520,13 @@ void SlidingBar::raise() { } void SlidingBar::setVisible(bool visible) { - if (_shown == visible) { - return; - } _shown = visible; if (!_shown) { _wrapped.hide(anim::type::instant); } else if (_contentShown) { _wrapped.show(anim::type::instant); + } else if (!_wrapped.isHidden() && !_wrapped.animating()) { + _wrapped.hide(anim::type::instant); } } diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 4d1cd7597..2145504db 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_message.h" #include "history/view/history_view_service_message.h" #include "history/view/history_view_cursor_state.h" +#include "history/view/history_view_translate_tracker.h" #include "history/view/history_view_quick_action.h" #include "chat_helpers/message_field.h" #include "mainwindow.h" @@ -83,6 +84,11 @@ constexpr auto kPreloadedScreensCountFull = kPreloadedScreensCount + 1 + kPreloadedScreensCount; constexpr auto kClearUserpicsAfter = 50; +[[nodiscard]] std::unique_ptr MaybeTranslateTracker( + History *history) { + return history ? std::make_unique(history) : nullptr; +} + } // namespace ListWidget::MouseState::MouseState() : pointState(PointState::Outside) { @@ -297,6 +303,7 @@ ListWidget::ListWidget( this, [=](QRect updated) { update(updated); }, controller->cachedReactionIconFactory().createMethod())) +, _translateTracker(MaybeTranslateTracker(_delegate->listTranslateHistory())) , _scrollDateCheck([this] { scrollDateCheck(); }) , _applyUpdatedScrollState([this] { applyUpdatedScrollState(); }) , _selectEnabled(_delegate->listAllowsMultiSelect()) @@ -359,6 +366,15 @@ ListWidget::ListWidget( maybeMarkReactionsRead(update.item); }, lifetime()); + if (const auto history = _delegate->listTranslateHistory()) { + session().changes().historyUpdates( + history, + Data::HistoryUpdate::Flag::TranslatedTo + ) | rpl::start_with_next([=] { + update(); + }, lifetime()); + } + session().data().itemVisibilityQueries( ) | rpl::start_with_next([=]( const Data::Session::ItemVisibilityQuery &query) { @@ -2025,9 +2041,16 @@ void ListWidget::paintEvent(QPaintEvent *e) { return; } + if (_translateTracker) { + _translateTracker->startBunch(); + } auto readTill = (HistoryItem*)nullptr; auto readContents = base::flat_set>(); const auto guard = gsl::finally([&] { + if (_translateTracker) { + _delegate->listAddTranslatedItems(_translateTracker.get()); + _translateTracker->finishBunch(); + } if (readTill && markingMessagesRead()) { _delegate->listMarkReadTill(readTill); } @@ -2076,6 +2099,9 @@ void ListWidget::paintEvent(QPaintEvent *e) { context.selection = itemRenderSelection(view); view->draw(p, context); } + if (_translateTracker) { + _translateTracker->add(view); + } const auto isSponsored = item->isSponsored(); const auto isUnread = _delegate->listElementShownUnread(view) && item->isRegular(); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index eec023c11..77c51f750 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -53,6 +53,7 @@ namespace HistoryView { struct TextState; struct StateRequest; class EmojiInteractions; +class TranslateTracker; enum class CursorState : char; enum class PointState : char; enum class Context : char; @@ -142,6 +143,9 @@ public: Painter &p, const Ui::ChatPaintContext &context) = 0; virtual QString listElementAuthorRank(not_null view) = 0; + virtual History *listTranslateHistory() = 0; + virtual void listAddTranslatedItems( + not_null tracker) = 0; }; struct SelectionData { @@ -644,6 +648,8 @@ private: rpl::variable _reactionsItem; bool _useCornerReaction = false; + std::unique_ptr _translateTracker; + int _minHeight = 0; int _visibleTop = 0; int _visibleBottom = 0; diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp index b3d1c20db..22ca0af7a 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_pinned_section.h" #include "history/view/history_view_top_bar_widget.h" +#include "history/view/history_view_translate_bar.h" #include "history/view/history_view_list_widget.h" #include "history/history.h" #include "history/history_item_components.h" @@ -100,6 +101,7 @@ PinnedWidget::PinnedWidget( : nullptr) , _topBar(this, controller) , _topBarShadow(this) +, _translateBar(std::make_unique(this, controller, _history)) , _scroll(std::make_unique( this, controller->chatStyle()->value(lifetime(), st::historyScroll), @@ -150,6 +152,7 @@ PinnedWidget::PinnedWidget( clearSelected(); }, _topBar->lifetime()); + _translateBar->raise(); _topBarShadow->raise(); controller->adaptive().value( ) | rpl::start_with_next([=] { @@ -168,6 +171,7 @@ PinnedWidget::PinnedWidget( }, lifetime()); setupClearButton(); + setupTranslateBar(); } PinnedWidget::~PinnedWidget() = default; @@ -195,6 +199,29 @@ void PinnedWidget::setupClearButton() { }); } +void PinnedWidget::setupTranslateBar() { + controller()->adaptive().oneColumnValue( + ) | rpl::start_with_next([=, raw = _translateBar.get()](bool one) { + raw->setShadowGeometryPostprocess([=](QRect geometry) { + if (!one) { + geometry.setLeft(geometry.left() + st::lineWidth); + } + return geometry; + }); + }, _translateBar->lifetime()); + + _translateBarHeight = 0; + _translateBar->heightValue( + ) | rpl::start_with_next([=](int height) { + if (const auto delta = height - _translateBarHeight) { + _translateBarHeight = height; + setGeometryWithTopMoved(geometry(), delta); + } + }, _translateBar->lifetime()); + + _translateBar->finishAnimating(); +} + void PinnedWidget::cornerButtonsShowAtPosition( Data::MessagePosition position) { showAtPosition(position); @@ -261,6 +288,7 @@ QPixmap PinnedWidget::grabForShowAnimation(const Window::SectionSlideParams &par if (params.withTopBarShadow) _topBarShadow->hide(); auto result = Ui::GrabWidget(this); if (params.withTopBarShadow) _topBarShadow->show(); + _translateBar->hide(); return result; } @@ -370,8 +398,11 @@ void PinnedWidget::updateControlsGeometry() { _clearButton->resizeToWidth(width()); _clearButton->move(0, bottom); const auto controlsHeight = 0; - const auto scrollY = _topBar->height(); - const auto scrollHeight = bottom - scrollY - controlsHeight; + auto top = _topBar->height(); + _translateBar->move(0, top); + _translateBar->resizeToWidth(contentWidth); + top += _translateBarHeight; + const auto scrollHeight = bottom - top - controlsHeight; const auto scrollSize = QSize(contentWidth, scrollHeight); if (_scroll->size() != scrollSize) { _skipScrollEvent = true; @@ -379,7 +410,7 @@ void PinnedWidget::updateControlsGeometry() { _inner->resizeToWidth(scrollSize.width(), _scroll->height()); _skipScrollEvent = false; } - _scroll->move(0, scrollY); + _scroll->move(0, top); if (!_scroll->isHidden()) { if (newScrollTop) { _scroll->scrollToY(*newScrollTop); @@ -429,6 +460,7 @@ void PinnedWidget::showAnimatedHook( void PinnedWidget::showFinishedHook() { _topBar->setAnimatingMode(false); _inner->showFinished(); + _translateBar->show(); } bool PinnedWidget::floatPlayerHandleWheelEvent(QEvent *e) { @@ -630,6 +662,14 @@ QString PinnedWidget::listElementAuthorRank(not_null view) { return {}; } +History *PinnedWidget::listTranslateHistory() { + return _history; +} + +void PinnedWidget::listAddTranslatedItems( + not_null tracker) { +} + void PinnedWidget::confirmDeleteSelected() { ConfirmDeleteSelectedItems(_inner); } diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.h b/Telegram/SourceFiles/history/view/history_view_pinned_section.h index 067e78f03..1ee0a9b7d 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.h +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.h @@ -32,6 +32,7 @@ namespace HistoryView { class Element; class TopBarWidget; class PinnedMemento; +class TranslateBar; class PinnedWidget final : public Window::SectionWidget @@ -126,6 +127,9 @@ public: Painter &p, const Ui::ChatPaintContext &context) override; QString listElementAuthorRank(not_null view) override; + History *listTranslateHistory() override; + void listAddTranslatedItems( + not_null tracker) override; // CornerButtonsDelegate delegate. void cornerButtonsShowAtPosition( @@ -158,6 +162,7 @@ private: FullMsgId originId = {}); void setupClearButton(); + void setupTranslateBar(); void confirmDeleteSelected(); void confirmForwardSelected(); @@ -175,6 +180,9 @@ private: object_ptr _topBar; object_ptr _topBarShadow; + std::unique_ptr _translateBar; + int _translateBarHeight = 0; + bool _skipScrollEvent = false; std::unique_ptr _scroll; std::unique_ptr _clearButton; diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index d2dd7519a..ac40c1e6c 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -18,6 +18,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_service_message.h" #include "history/view/history_view_pinned_tracker.h" #include "history/view/history_view_pinned_section.h" +#include "history/view/history_view_translate_bar.h" +#include "history/view/history_view_translate_tracker.h" #include "history/history.h" #include "history/history_drag_area.h" #include "history/history_item_components.h" @@ -241,14 +243,15 @@ RepliesWidget::RepliesWidget( [=](not_null emoji) { listShowPremiumToast(emoji); }, ComposeControls::Mode::Normal, SendMenu::Type::SilentOnly)) +, _translateBar(std::make_unique(this, controller, history)) , _scroll(std::make_unique( this, controller->chatStyle()->value(lifetime(), st::historyScroll), false)) , _cornerButtons( - _scroll.get(), - controller->chatStyle(), - static_cast(this)) { + _scroll.get(), + controller->chatStyle(), + static_cast(this)) { controller->chatStyle()->paletteChanged( ) | rpl::start_with_next([=] { _scroll->updateBars(); @@ -265,6 +268,7 @@ RepliesWidget::RepliesWidget( setupRoot(); setupRootView(); setupShortcuts(); + setupTranslateBar(); _history->peer->updateFull(); @@ -406,8 +410,9 @@ RepliesWidget::~RepliesWidget() { } void RepliesWidget::orderWidgets() { - if (_topBar) { - _topBar->raise(); + _translateBar->raise(); + if (_topicReopenBar) { + _topicReopenBar->bar().raise(); } if (_rootView) { _rootView->raise(); @@ -415,8 +420,8 @@ void RepliesWidget::orderWidgets() { if (_pinnedBar) { _pinnedBar->raise(); } - if (_topicReopenBar) { - _topicReopenBar->bar().raise(); + if (_topBar) { + _topBar->raise(); } _topBarShadow->raise(); _composeControls->raisePanels(); @@ -453,8 +458,12 @@ void RepliesWidget::setupRootView() { _rootId, [bar = _rootView.get()] { bar->customEmojiRepaint(); }), _rootVisible.value() - ) | rpl::map([=](Ui::MessageBarContent &&content, bool shown) { - return shown ? std::move(content) : Ui::MessageBarContent(); + ) | rpl::map([=](Ui::MessageBarContent &&content, bool show) { + const auto shown = !content.title.isEmpty() && !content.text.empty(); + _shownPinnedItem = shown + ? _history->owner().message(_history->peer->id, _rootId) + : nullptr; + return show ? std::move(content) : Ui::MessageBarContent(); })); controller()->adaptive().oneColumnValue( @@ -585,6 +594,7 @@ void RepliesWidget::setTopic(Data::ForumTopic *topic) { refreshTopBarActiveChat(); if (_topic) { if (_rootView) { + _shownPinnedItem = nullptr; _rootView = nullptr; _rootViewHeight = 0; } @@ -1510,6 +1520,29 @@ void RepliesWidget::checkLastPinnedClickedIdReset( } } +void RepliesWidget::setupTranslateBar() { + controller()->adaptive().oneColumnValue( + ) | rpl::start_with_next([=, raw = _translateBar.get()](bool one) { + raw->setShadowGeometryPostprocess([=](QRect geometry) { + if (!one) { + geometry.setLeft(geometry.left() + st::lineWidth); + } + return geometry; + }); + }, _translateBar->lifetime()); + + _translateBarHeight = 0; + _translateBar->heightValue( + ) | rpl::start_with_next([=](int height) { + if (const auto delta = height - _translateBarHeight) { + _translateBarHeight = height; + setGeometryWithTopMoved(geometry(), delta); + } + }, _translateBar->lifetime()); + + _translateBar->finishAnimating(); +} + void RepliesWidget::setupPinnedTracker() { Expects(_topic != nullptr); @@ -1563,6 +1596,7 @@ void RepliesWidget::checkPinnedBarState() { if (_pinnedBar) { _pinnedBar->setContent(rpl::single(Ui::MessageBarContent())); _pinnedTracker->reset(); + _shownPinnedItem = nullptr; _hidingPinnedBar = base::take(_pinnedBar); const auto raw = _hidingPinnedBar.get(); base::call_delayed(st::defaultMessageBar.duration, this, [=] { @@ -1614,7 +1648,12 @@ void RepliesWidget::checkPinnedBarState() { std::move(pinnedRefreshed), std::move(markupRefreshed), _rootVisible.value() - ) | rpl::map([](Ui::MessageBarContent &&content, auto, auto, bool show) { + ) | rpl::map([=](Ui::MessageBarContent &&content, auto, auto, bool show) { + const auto shown = !content.title.isEmpty() && !content.text.empty(); + _shownPinnedItem = shown + ? _history->owner().message( + _pinnedTracker->currentMessageId().message) + : nullptr; return (show || content.count > 1) ? std::move(content) : Ui::MessageBarContent(); @@ -1896,6 +1935,7 @@ QPixmap RepliesWidget::grabForShowAnimation(const Window::SectionSlideParams &pa if (_pinnedBar) { _pinnedBar->hide(); } + _translateBar->hide(); return result; } @@ -2125,22 +2165,24 @@ void RepliesWidget::updateControlsGeometry() { if (_rootView) { _rootView->resizeToWidth(contentWidth); } + auto top = _topBar->height() + _rootViewHeight; if (_pinnedBar) { - _pinnedBar->move(0, _topBar->height()); + _pinnedBar->move(0, top); _pinnedBar->resizeToWidth(contentWidth); + top += _pinnedBarHeight; } + if (_topicReopenBar) { + _topicReopenBar->bar().move(0, top); + top += _topicReopenBar->bar().height(); + } + _translateBar->move(0, top); + _translateBar->resizeToWidth(contentWidth); + top += _translateBarHeight; const auto bottom = height(); const auto controlsHeight = _joinGroup ? _joinGroup->height() : _composeControls->heightCurrent(); - auto top = _topBar->height() - + _rootViewHeight - + _pinnedBarHeight; - if (_topicReopenBar) { - _topicReopenBar->bar().move(0, top); - top += _topicReopenBar->bar().height(); - } const auto scrollHeight = bottom - top - controlsHeight; const auto scrollSize = QSize(contentWidth, scrollHeight); if (_scroll->size() != scrollSize) { @@ -2250,11 +2292,6 @@ void RepliesWidget::setPinnedVisibility(bool shown) { } } } - if (shown) { - _rootView->show(); - } else { - _rootView->hide(); - } _rootVisible = shown; if (!_rootViewInited) { _rootView->finishAnimating(); @@ -2293,6 +2330,10 @@ void RepliesWidget::showFinishedHook() { if (_pinnedBar) { _pinnedBar->show(); } + _translateBar->show(); + if (_topicReopenBar) { + _topicReopenBar->bar().show(); + } // We should setup the drag area only after // the section animation is finished, @@ -2536,6 +2577,17 @@ QString RepliesWidget::listElementAuthorRank(not_null view) { : QString(); } +History *RepliesWidget::listTranslateHistory() { + return _history; +} + +void RepliesWidget::listAddTranslatedItems( + not_null tracker) { + if (_shownPinnedItem) { + tracker->add(_shownPinnedItem); + } +} + void RepliesWidget::setupEmptyPainter() { Expects(_topic != nullptr); diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index cc7e71372..a8645a5c5 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -67,6 +67,7 @@ class StickerToast; class TopicReopenBar; class EmptyPainter; class PinnedTracker; +class TranslateBar; class RepliesWidget final : public Window::SectionWidget @@ -170,6 +171,9 @@ public: Painter &p, const Ui::ChatPaintContext &context) override; QString listElementAuthorRank(not_null view) override; + History *listTranslateHistory() override; + void listAddTranslatedItems( + not_null tracker) override; // CornerButtonsDelegate delegate. void cornerButtonsShowAtPosition( @@ -217,9 +221,9 @@ private: void setTopic(Data::ForumTopic *topic); void setupDragArea(); void setupShortcuts(); + void setupTranslateBar(); void searchInTopic(); - void scrollDownAnimationFinish(); void updatePinnedVisibility(); void confirmDeleteSelected(); @@ -332,12 +336,16 @@ private: bool _skipScrollEvent = false; bool _synteticScrollEvent = false; + std::unique_ptr _translateBar; + int _translateBarHeight = 0; + std::unique_ptr _pinnedTracker; std::unique_ptr _pinnedBar; std::unique_ptr _hidingPinnedBar; int _pinnedBarHeight = 0; FullMsgId _pinnedClickedId; std::optional _minPinnedId; + HistoryItem *_shownPinnedItem = nullptr; std::unique_ptr _rootView; int _rootViewHeight = 0; diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index ffe62daea..a5a7e93d4 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -1325,6 +1325,14 @@ QString ScheduledWidget::listElementAuthorRank( return {}; } +History *ScheduledWidget::listTranslateHistory() { + return nullptr; +} + +void ScheduledWidget::listAddTranslatedItems( + not_null tracker) { +} + void ScheduledWidget::confirmSendNowSelected() { ConfirmSendNowSelectedItems(_inner); } diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h index 426cdf5fa..acbec32d8 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h @@ -150,6 +150,9 @@ public: Painter &p, const Ui::ChatPaintContext &context) override; QString listElementAuthorRank(not_null view) override; + History *listTranslateHistory() override; + void listAddTranslatedItems( + not_null tracker) override; // CornerButtonsDelegate delegate. void cornerButtonsShowAtPosition( diff --git a/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp b/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp index 103e801b3..d1a303724 100644 --- a/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp +++ b/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp @@ -237,18 +237,19 @@ TranslateBar::TranslateBar( _wrap.hide(anim::type::instant); _shadow->hide(); + _shadow->showOn(rpl::combine( + _wrap.shownValue(), + _wrap.heightValue(), + rpl::mappers::_1 && rpl::mappers::_2 > 0 + ) | rpl::filter([=](bool shown) { + return (shown == _shadow->isHidden()); + })); + setup(history); } TranslateBar::~TranslateBar() = default; -void TranslateBar::updateControlsGeometry(QRect wrapGeometry) { - const auto hidden = _wrap.isHidden() || !wrapGeometry.height(); - if (_shadow->isHidden() != hidden) { - _shadow->setVisible(!hidden); - } -} - void TranslateBar::setShadowGeometryPostprocess( Fn postprocess) { _shadowGeometryPostprocess = std::move(postprocess); @@ -270,7 +271,6 @@ void TranslateBar::setup(not_null history) { _wrap.geometryValue( ) | rpl::start_with_next([=](QRect rect) { updateShadowGeometry(rect); - updateControlsGeometry(rect); }, _wrap.lifetime()); const auto translateTo = [=](LanguageId id) { @@ -563,7 +563,8 @@ void TranslateBar::show() { _forceHidden = false; if (_shouldBeShown) { _wrap.show(anim::type::instant); - _shadow->show(); + } else if (!_wrap.isHidden() && !_wrap.animating()) { + _wrap.hide(anim::type::instant); } } @@ -573,7 +574,6 @@ void TranslateBar::hide() { } _forceHidden = true; _wrap.hide(anim::type::instant); - _shadow->hide(); } void TranslateBar::raise() { diff --git a/Telegram/SourceFiles/history/view/history_view_translate_bar.h b/Telegram/SourceFiles/history/view/history_view_translate_bar.h index 7d5b08690..62846100a 100644 --- a/Telegram/SourceFiles/history/view/history_view_translate_bar.h +++ b/Telegram/SourceFiles/history/view/history_view_translate_bar.h @@ -51,7 +51,6 @@ public: private: void setup(not_null history); void updateShadowGeometry(QRect wrapGeometry); - void updateControlsGeometry(QRect wrapGeometry); [[nodiscard]] base::unique_qptr createMenu( not_null button); void showMenu(base::unique_qptr menu); diff --git a/Telegram/SourceFiles/history/view/history_view_translate_tracker.cpp b/Telegram/SourceFiles/history/view/history_view_translate_tracker.cpp index 7017ffe46..dad17969b 100644 --- a/Telegram/SourceFiles/history/view/history_view_translate_tracker.cpp +++ b/Telegram/SourceFiles/history/view/history_view_translate_tracker.cpp @@ -19,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item_components.h" #include "history/view/history_view_element.h" #include "main/main_session.h" -#include "spellcheck/spellcheck_types.h" #include "spellcheck/platform/platform_language.h" namespace HistoryView { @@ -32,11 +31,6 @@ constexpr auto kRequestCountLimit = 20; } // namespace -struct TranslateTracker::ItemForRecognize { - uint64 generation = 0; - MaybeLanguageId id; -}; - TranslateTracker::TranslateTracker(not_null history) : _history(history) , _limit(kEnoughForRecognition) { @@ -85,29 +79,25 @@ bool TranslateTracker::enoughForRecognition() const { void TranslateTracker::startBunch() { _addedInBunch = 0; + _bunchTranslatedTo = _history->translatedTo(); ++_generation; } -void TranslateTracker::add( - not_null view, - LanguageId translatedTo) { +void TranslateTracker::add(not_null view) { const auto item = view->data(); const auto only = view->isOnlyEmojiAndSpaces(); if (only != OnlyEmojiAndSpaces::Unknown) { item->cacheOnlyEmojiAndSpaces(only == OnlyEmojiAndSpaces::Yes); } - add(item, translatedTo, false); + add(item, false); +} + +void TranslateTracker::add(not_null item) { + add(item, false); } void TranslateTracker::add( not_null item, - LanguageId translatedTo) { - add(item, translatedTo, false); -} - -void TranslateTracker::add( - not_null item, - LanguageId translatedTo, bool skipDependencies) { Expects(_addedInBunch >= 0); @@ -117,15 +107,26 @@ void TranslateTracker::add( || item->isOnlyEmojiAndSpaces()) { return; } - if (item->translationShowRequiresCheck(translatedTo)) { - _switchTranslations[item] = translatedTo; + if (item->translationShowRequiresCheck(_bunchTranslatedTo)) { + _switchTranslations[item] = _bunchTranslatedTo; } if (!skipDependencies) { if (const auto reply = item->Get()) { if (const auto to = reply->replyToMsg.get()) { - add(to, translatedTo, true); + add(to, true); } } +#if 0 // I hope this is not needed, although I'm not sure. + if (item->groupId()) { + if (const auto group = _history->owner().groups().find(item)) { + for (const auto &other : group->items) { + if (other != item) { + add(other, true); + } + } + } + } +#endif } const auto id = item->fullId(); const auto i = _itemsForRecognize.find(id); @@ -162,7 +163,6 @@ void TranslateTracker::finishBunch() { checkRecognized(); } } - requestSome(); if (!_switchTranslations.empty()) { auto switching = base::take(_switchTranslations); for (const auto &[item, id] : switching) { @@ -171,6 +171,7 @@ void TranslateTracker::finishBunch() { _switchTranslations = std::move(switching); _switchTranslations.clear(); } + requestSome(); } void TranslateTracker::cancelToRequest() { diff --git a/Telegram/SourceFiles/history/view/history_view_translate_tracker.h b/Telegram/SourceFiles/history/view/history_view_translate_tracker.h index 8294bf5a8..77f9c4e32 100644 --- a/Telegram/SourceFiles/history/view/history_view_translate_tracker.h +++ b/Telegram/SourceFiles/history/view/history_view_translate_tracker.h @@ -7,9 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "spellcheck/spellcheck_types.h" + class History; class HistoryItem; -struct LanguageId; namespace HistoryView { @@ -22,24 +23,24 @@ public: [[nodiscard]] bool enoughForRecognition() const; void startBunch(); - void add(not_null view, LanguageId translatedTo); - void add(not_null item, LanguageId translatedTo); + void add(not_null view); + void add(not_null item); void finishBunch(); [[nodiscard]] rpl::producer trackingLanguage() const; private: using MaybeLanguageId = std::variant; - struct ItemForRecognize; + struct ItemForRecognize { + uint64 generation = 0; + MaybeLanguageId id; + }; struct ItemToRequest { int length = 0; }; void setup(); - void add( - not_null item, - LanguageId translatedTo, - bool skipDependencies); + void add(not_null item, bool skipDependencies); void recognizeCollected(); void trackSkipLanguages(); void checkRecognized(); @@ -58,6 +59,7 @@ private: rpl::variable _trackingLanguage = false; base::flat_map _itemsForRecognize; uint64 _generation = 0; + LanguageId _bunchTranslatedTo; int _limit = 0; int _addedInBunch = -1; bool _allLoaded = false; diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp index d9212bd54..308dd8d94 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp @@ -759,7 +759,10 @@ void GroupedMedia::unloadHeavyPart() { } void GroupedMedia::parentTextUpdated() { - history()->owner().requestViewResize(_parent); + if (_parent->media() == this) { + refreshCaption(); + history()->owner().requestViewResize(_parent); + } } bool GroupedMedia::needsBubble() const { diff --git a/Telegram/SourceFiles/ui/chat/pinned_bar.cpp b/Telegram/SourceFiles/ui/chat/pinned_bar.cpp index ebb832a86..fddd61fe4 100644 --- a/Telegram/SourceFiles/ui/chat/pinned_bar.cpp +++ b/Telegram/SourceFiles/ui/chat/pinned_bar.cpp @@ -28,6 +28,14 @@ PinnedBar::PinnedBar( _wrap.hide(anim::type::instant); _shadow->hide(); + _shadow->showOn(rpl::combine( + _wrap.shownValue(), + _wrap.heightValue(), + rpl::mappers::_1 && rpl::mappers::_2 > 0 + ) | rpl::filter([=](bool shown) { + return (shown == _shadow->isHidden()); + })); + _wrap.entity()->paintRequest( ) | rpl::start_with_next([=](QRect clip) { QPainter(_wrap.entity()).fillRect(clip, st::historyPinnedBg); @@ -121,10 +129,6 @@ void PinnedBar::setRightButton(object_ptr button) { void PinnedBar::updateControlsGeometry(QRect wrapGeometry) { _bar->widget()->resizeToWidth(wrapGeometry.width()); - const auto hidden = _wrap.isHidden() || !wrapGeometry.height(); - if (_shadow->isHidden() != hidden) { - _shadow->setVisible(!hidden); - } if (_right.button) { _right.button->moveToRight(0, 0); } @@ -208,7 +212,8 @@ void PinnedBar::show() { _forceHidden = false; if (_shouldBeShown) { _wrap.show(anim::type::instant); - _shadow->show(); + } else if (!_wrap.isHidden() && !_wrap.animating()) { + _wrap.hide(anim::type::instant); } } @@ -218,7 +223,6 @@ void PinnedBar::hide() { } _forceHidden = true; _wrap.hide(anim::type::instant); - _shadow->hide(); } void PinnedBar::raise() {