mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 21:27:07 +02:00
Feed initial messages slice to translation tracker.
This commit is contained in:
parent
64f4e0dd52
commit
4a37846605
7 changed files with 66 additions and 16 deletions
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "history/view/history_view_element.h"
|
||||
#include "history/view/history_view_item_preview.h"
|
||||
#include "history/view/history_view_translate_tracker.h"
|
||||
#include "dialogs/dialogs_indexed_list.h"
|
||||
#include "history/history_inner_widget.h"
|
||||
#include "history/history_item.h"
|
||||
|
|
|
@ -555,6 +555,9 @@ void HistoryInner::messagesReceived(
|
|||
const QVector<MTPMessage> &messages) {
|
||||
if (_history->peer == peer) {
|
||||
_history->addOlderSlice(messages);
|
||||
if (!messages.isEmpty()) {
|
||||
_translateTracker->addBunchFromBlocks();
|
||||
}
|
||||
} else if (_migrated && _migrated->peer == peer) {
|
||||
const auto newLoaded = _migrated
|
||||
&& _migrated->isEmpty()
|
||||
|
|
|
@ -523,6 +523,9 @@ void ListWidget::refreshRows(const Data::MessagesSlice &old) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (_translateTracker) {
|
||||
_translateTracker->addBunchFrom(_items);
|
||||
}
|
||||
for (auto e = end(_items), i = e - addedToEndCount; i != e; ++i) {
|
||||
_itemRevealPending.emplace(*i);
|
||||
}
|
||||
|
|
|
@ -279,7 +279,7 @@ void TranslateBar::setup(not_null<History*> history) {
|
|||
}
|
||||
};
|
||||
const auto button = static_cast<Ui::AbstractButton*>(_wrap.entity());
|
||||
button->resize(0, st::historyComposeButton.height);
|
||||
button->resize(0, st::historyTranslateBarHeight);
|
||||
button->setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
|
||||
button->paintRequest(
|
||||
|
@ -619,7 +619,7 @@ int TranslateBar::height() const {
|
|||
return !_forceHidden
|
||||
? _wrap.height()
|
||||
: _shouldBeShown
|
||||
? st::historyComposeButton.height
|
||||
? st::historyTranslateBarHeight
|
||||
: 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace {
|
|||
|
||||
constexpr auto kEnoughForRecognition = 10;
|
||||
constexpr auto kEnoughForTranslation = 6;
|
||||
constexpr auto kMaxCheckInBunch = 100;
|
||||
constexpr auto kRequestLengthLimit = 24 * 1024;
|
||||
constexpr auto kRequestCountLimit = 20;
|
||||
|
||||
|
@ -82,20 +83,20 @@ void TranslateTracker::startBunch() {
|
|||
++_generation;
|
||||
}
|
||||
|
||||
void TranslateTracker::add(not_null<Element*> view) {
|
||||
bool TranslateTracker::add(not_null<Element*> view) {
|
||||
const auto item = view->data();
|
||||
const auto only = view->isOnlyEmojiAndSpaces();
|
||||
if (only != OnlyEmojiAndSpaces::Unknown) {
|
||||
item->cacheOnlyEmojiAndSpaces(only == OnlyEmojiAndSpaces::Yes);
|
||||
}
|
||||
add(item, false);
|
||||
return add(item, false);
|
||||
}
|
||||
|
||||
void TranslateTracker::add(not_null<HistoryItem*> item) {
|
||||
add(item, false);
|
||||
bool TranslateTracker::add(not_null<HistoryItem*> item) {
|
||||
return add(item, false);
|
||||
}
|
||||
|
||||
void TranslateTracker::add(
|
||||
bool TranslateTracker::add(
|
||||
not_null<HistoryItem*> item,
|
||||
bool skipDependencies) {
|
||||
Expects(_addedInBunch >= 0);
|
||||
|
@ -104,7 +105,7 @@ void TranslateTracker::add(
|
|||
|| item->isService()
|
||||
|| !item->isRegular()
|
||||
|| item->isOnlyEmojiAndSpaces()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (item->translationShowRequiresCheck(_bunchTranslatedTo)) {
|
||||
_switchTranslations[item] = _bunchTranslatedTo;
|
||||
|
@ -131,7 +132,7 @@ void TranslateTracker::add(
|
|||
const auto i = _itemsForRecognize.find(id);
|
||||
if (i != end(_itemsForRecognize)) {
|
||||
i->second.generation = _generation;
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
const auto &text = item->originalText().text;
|
||||
_itemsForRecognize.emplace(id, ItemForRecognize{
|
||||
|
@ -141,6 +142,7 @@ void TranslateTracker::add(
|
|||
: MaybeLanguageId{ text }),
|
||||
});
|
||||
++_addedInBunch;
|
||||
return true;
|
||||
}
|
||||
|
||||
void TranslateTracker::switchTranslation(
|
||||
|
@ -173,6 +175,43 @@ void TranslateTracker::finishBunch() {
|
|||
requestSome();
|
||||
}
|
||||
|
||||
void TranslateTracker::addBunchFromBlocks() {
|
||||
if (enoughForRecognition()) {
|
||||
return;
|
||||
}
|
||||
startBunch();
|
||||
const auto guard = gsl::finally([&] {
|
||||
finishBunch();
|
||||
});
|
||||
|
||||
auto check = kMaxCheckInBunch;
|
||||
for (const auto &block : _history->blocks) {
|
||||
for (const auto &view : block->messages) {
|
||||
if (!check-- || (add(view.get()) && enoughForRecognition())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TranslateTracker::addBunchFrom(
|
||||
const std::vector<not_null<Element*>> &views) {
|
||||
if (enoughForRecognition()) {
|
||||
return;
|
||||
}
|
||||
startBunch();
|
||||
const auto guard = gsl::finally([&] {
|
||||
finishBunch();
|
||||
});
|
||||
|
||||
auto check = kMaxCheckInBunch;
|
||||
for (const auto &view : views) {
|
||||
if (!check-- || (add(view.get()) && enoughForRecognition())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TranslateTracker::cancelToRequest() {
|
||||
if (!_itemsToRequest.empty()) {
|
||||
const auto owner = &_history->owner();
|
||||
|
|
|
@ -23,10 +23,13 @@ public:
|
|||
|
||||
[[nodiscard]] bool enoughForRecognition() const;
|
||||
void startBunch();
|
||||
void add(not_null<Element*> view);
|
||||
void add(not_null<HistoryItem*> item);
|
||||
bool add(not_null<Element*> view);
|
||||
bool add(not_null<HistoryItem*> item);
|
||||
void finishBunch();
|
||||
|
||||
void addBunchFromBlocks();
|
||||
void addBunchFrom(const std::vector<not_null<Element*>> &views);
|
||||
|
||||
[[nodiscard]] rpl::producer<bool> trackingLanguage() const;
|
||||
|
||||
private:
|
||||
|
@ -40,7 +43,7 @@ private:
|
|||
};
|
||||
|
||||
void setup();
|
||||
void add(not_null<HistoryItem*> item, bool skipDependencies);
|
||||
bool add(not_null<HistoryItem*> item, bool skipDependencies);
|
||||
void recognizeCollected();
|
||||
void trackSkipLanguages();
|
||||
void checkRecognized();
|
||||
|
|
|
@ -1237,18 +1237,19 @@ historyTranslateLabel: FlatLabel(defaultFlatLabel) {
|
|||
minWidth: 80px;
|
||||
}
|
||||
historyTranslateIcon: icon{{ "menu/translate", windowActiveTextFg }};
|
||||
historyTranslateBarHeight: 36px;
|
||||
historyTranslateSettings: IconButton(defaultIconButton) {
|
||||
width: 46px;
|
||||
height: 46px;
|
||||
height: 36px;
|
||||
icon: icon{{ "menu/customize", windowActiveTextFg }};
|
||||
iconOver: icon{{ "menu/customize", windowActiveTextFg }};
|
||||
rippleAreaPosition: point(4px, 4px);
|
||||
rippleAreaSize: 38px;
|
||||
rippleAreaPosition: point(6px, 2px);
|
||||
rippleAreaSize: 32px;
|
||||
ripple: RippleAnimation(defaultRippleAnimation) {
|
||||
color: lightButtonBgOver;
|
||||
}
|
||||
}
|
||||
historyTranslateMenuPosition: point(-6px, 40px);
|
||||
historyTranslateMenuPosition: point(-6px, 30px);
|
||||
|
||||
historySendDisabled: FlatLabel(defaultFlatLabel) {
|
||||
minWidth: 10px;
|
||||
|
|
Loading…
Add table
Reference in a new issue