mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-08-02 02:07:54 +00:00
Added new api support to text summarizing.
This commit is contained in:
@@ -235,27 +235,25 @@ void Transcribes::summarize(not_null<HistoryItem*> item) {
|
||||
}
|
||||
|
||||
const auto id = item->fullId();
|
||||
const auto requestId = _api.request(MTPmessages_TranslateText(
|
||||
MTP_flags(MTPmessages_TranslateText::Flag::f_peer
|
||||
| MTPmessages_TranslateText::Flag::f_id),
|
||||
const auto langSummary = summaryFromLang(id);
|
||||
const auto requestId = _api.request(MTPmessages_SummarizeText(
|
||||
langSummary.isEmpty()
|
||||
? MTP_flags(0)
|
||||
: MTP_flags(MTPmessages_summarizeText::Flag::f_to_lang),
|
||||
item->history()->peer->input(),
|
||||
MTP_vector<MTPint>(1, MTP_int(item->id)),
|
||||
MTPVector<MTPTextWithEntities>(),
|
||||
MTP_string("sum")
|
||||
)).done([=](const MTPmessages_TranslatedText &result) {
|
||||
const auto &list = result.data().vresult().v;
|
||||
if (!list.isEmpty()) {
|
||||
const auto &tl = list.front().data();
|
||||
auto &entry = _summaries[id];
|
||||
entry.requestId = 0;
|
||||
entry.loading = false;
|
||||
entry.result = TextWithEntities(
|
||||
qs(tl.vtext()),
|
||||
Api::EntitiesFromMTP(_session, tl.ventities().v));
|
||||
if (const auto item = _session->data().message(id)) {
|
||||
_session->data().requestItemResize(item);
|
||||
_session->data().requestItemShowHighlight(item);
|
||||
}
|
||||
MTP_int(item->id),
|
||||
langSummary.isEmpty() ? MTPstring() : MTP_string(langSummary)
|
||||
)).done([=](const MTPTextWithEntities &result) {
|
||||
const auto &data = result.data();
|
||||
auto &entry = _summaries[id];
|
||||
entry.requestId = 0;
|
||||
entry.loading = false;
|
||||
entry.result = TextWithEntities(
|
||||
qs(data.vtext()),
|
||||
Api::EntitiesFromMTP(_session, data.ventities().v));
|
||||
if (const auto item = _session->data().message(id)) {
|
||||
_session->data().requestItemResize(item);
|
||||
_session->data().requestItemShowHighlight(item);
|
||||
}
|
||||
}).fail([=] {
|
||||
auto &entry = _summaries[id];
|
||||
@@ -275,4 +273,13 @@ void Transcribes::summarize(not_null<HistoryItem*> item) {
|
||||
_session->data().requestItemResize(item);
|
||||
}
|
||||
|
||||
void Transcribes::setSummaryFromLang(FullMsgId id, QString &&text) {
|
||||
_summariesFromLang[id] = std::move(text);
|
||||
}
|
||||
|
||||
QString Transcribes::summaryFromLang(FullMsgId id) const {
|
||||
const auto i = _summariesFromLang.find(id);
|
||||
return (i != _summariesFromLang.end()) ? i->second : QString();
|
||||
}
|
||||
|
||||
} // namespace Api
|
||||
|
||||
@@ -44,6 +44,8 @@ public:
|
||||
void toggleSummary(not_null<HistoryItem*> item);
|
||||
[[nodiscard]] const SummaryEntry &summary(
|
||||
not_null<const HistoryItem*> item) const;
|
||||
void setSummaryFromLang(FullMsgId, QString &&summaryFromLang);
|
||||
[[nodiscard]] QString summaryFromLang(FullMsgId) const;
|
||||
|
||||
void apply(const MTPDupdateTranscribedAudio &update);
|
||||
|
||||
@@ -71,6 +73,7 @@ private:
|
||||
base::flat_map<uint64, FullMsgId> _ids;
|
||||
|
||||
base::flat_map<FullMsgId, SummaryEntry> _summaries;
|
||||
base::flat_map<FullMsgId, QString> _summariesFromLang;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -362,6 +362,7 @@ enum class MessageFlag : uint64 {
|
||||
|
||||
HasHiddenLinks = (1ULL << 56),
|
||||
HasSummaryEntry = (1ULL << 57),
|
||||
CanBeSummarized = (1ULL << 58),
|
||||
};
|
||||
inline constexpr bool is_flag_type(MessageFlag) { return true; }
|
||||
using MessageFlags = base::flags<MessageFlag>;
|
||||
|
||||
@@ -483,6 +483,12 @@ HistoryItem::HistoryItem(
|
||||
history->owner().histories().reportDelivery(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (const auto summaryFromLang = data.vsummary_from_language()) {
|
||||
history->session().api().transcribes().setSummaryFromLang(
|
||||
fullId(),
|
||||
qs(*summaryFromLang));
|
||||
}
|
||||
}
|
||||
|
||||
HistoryItem::HistoryItem(
|
||||
|
||||
@@ -336,6 +336,9 @@ public:
|
||||
[[nodiscard]] bool showSimilarChannels() const {
|
||||
return _flags & MessageFlag::ShowSimilarChannels;
|
||||
}
|
||||
[[nodiscard]] bool canBeSummarized() const {
|
||||
return _flags & MessageFlag::CanBeSummarized;
|
||||
}
|
||||
[[nodiscard]] bool hasRealFromId() const;
|
||||
[[nodiscard]] bool isPostHidingAuthor() const;
|
||||
[[nodiscard]] bool isPostShowingAuthor() const;
|
||||
|
||||
@@ -846,6 +846,9 @@ MessageFlags FlagsFromMTP(
|
||||
? Flag::TonPaidSuggested
|
||||
: (flags & MTP::f_paid_suggested_post_stars)
|
||||
? Flag::StarsPaidSuggested
|
||||
: Flag())
|
||||
| ((flags & MTP::f_summary_from_language)
|
||||
? Flag::CanBeSummarized
|
||||
: Flag());
|
||||
}
|
||||
|
||||
|
||||
@@ -1222,7 +1222,9 @@ void Message::draw(Painter &p, const PaintContext &context) const {
|
||||
st::historyFastShareBottom)
|
||||
: st::historyFastShareBottom;
|
||||
const auto fastShareLeft = hasRightLayout()
|
||||
? (g.left() - rightActionWidth - st::historyFastShareLeft)
|
||||
? (g.left()
|
||||
- (_summarize ? 0 : rightActionWidth)
|
||||
- st::historyFastShareLeft)
|
||||
: (g.left() + g.width() + st::historyFastShareLeft);
|
||||
const auto fastShareTop = g.top() + (data()->isSponsored()
|
||||
? fastShareSkip
|
||||
@@ -4574,13 +4576,11 @@ const HistoryMessageEdited *Message::displayedEditBadge() const {
|
||||
}
|
||||
|
||||
void Message::ensureSummarizeButton() const {
|
||||
const auto item = data();
|
||||
if (item->isPost()
|
||||
&& item->originalText().text.size() >= kSummarizeThreshold
|
||||
/* && item->history()->session().premium()*/) {
|
||||
if (data()->canBeSummarized()
|
||||
/*&& item->originalText().text.size() >= kSummarizeThreshold*/) {
|
||||
if (!_summarize) {
|
||||
_summarize
|
||||
= std::make_unique<TranscribeButton>(item, false, true);
|
||||
= std::make_unique<TranscribeButton>(data(), false, true);
|
||||
}
|
||||
} else {
|
||||
_summarize = nullptr;
|
||||
|
||||
@@ -206,7 +206,7 @@ void AddCocoonBoxCover(not_null<Ui::VerticalLayout*> container) {
|
||||
auto metrics = QFontMetrics(font);
|
||||
|
||||
const auto text = tr::lng_translate_cocoon_title(tr::now);
|
||||
const auto textw = metrics.width(text);
|
||||
const auto textw = metrics.horizontalAdvance(text);
|
||||
const auto left = (width - textw) / 2;
|
||||
|
||||
auto q = QPainter(&state->gradient);
|
||||
|
||||
Reference in New Issue
Block a user