| 237 | } |
| 238 | |
| 239 | void Transcribes::summarize(not_null<HistoryItem*> item) { |
| 240 | if (!item->isHistoryEntry() || item->isLocal()) { |
| 241 | return; |
| 242 | } |
| 243 | |
| 244 | const auto id = item->fullId(); |
| 245 | const auto translatedTo = item->history()->translatedTo(); |
| 246 | const auto langCode = translatedTo |
| 247 | ? translatedTo.twoLetterCode() |
| 248 | : QString(); |
| 249 | const auto requestId = _api.request(MTPmessages_SummarizeText( |
| 250 | langCode.isEmpty() |
| 251 | ? MTP_flags(0) |
| 252 | : MTP_flags(MTPmessages_summarizeText::Flag::f_to_lang), |
| 253 | item->history()->peer->input(), |
| 254 | MTP_int(item->id), |
| 255 | langCode.isEmpty() ? MTPstring() : MTP_string(langCode), |
| 256 | MTPstring() // tone |
| 257 | )).done([=](const MTPTextWithEntities &result) { |
| 258 | const auto &data = result.data(); |
| 259 | auto &entry = _summaries[id]; |
| 260 | entry.requestId = 0; |
| 261 | entry.loading = false; |
| 262 | entry.premiumRequired = false; |
| 263 | entry.languageId = translatedTo; |
| 264 | entry.result = TextWithEntities( |
| 265 | qs(data.vtext()), |
| 266 | Api::EntitiesFromMTP(_session, data.ventities().v)); |
| 267 | if (const auto item = _session->data().message(id)) { |
| 268 | _session->data().requestItemTextRefresh(item); |
| 269 | _session->data().requestItemShowHighlight(item); |
| 270 | } |
| 271 | }).fail([=](const MTP::Error &error) { |
| 272 | auto &entry = _summaries[id]; |
| 273 | if (error.type() == u"SUMMARY_FLOOD_PREMIUM"_q) { |
| 274 | entry.premiumRequired = true; |
| 275 | } |
| 276 | entry.requestId = 0; |
| 277 | entry.shown = false; |
| 278 | entry.loading = false; |
| 279 | if (const auto item = _session->data().message(id)) { |
| 280 | _session->data().requestItemTextRefresh(item); |
| 281 | } |
| 282 | }).send(); |
| 283 | |
| 284 | auto &entry = _summaries.emplace(id).first->second; |
| 285 | entry.requestId = requestId; |
| 286 | entry.shown = true; |
| 287 | entry.loading = true; |
| 288 | |
| 289 | item->setHasSummaryEntry(); |
| 290 | _session->data().requestItemResize(item); |
| 291 | } |
| 292 | |
| 293 | void Transcribes::checkSummaryToTranslate(FullMsgId id) { |
| 294 | const auto i = _summaries.find(id); |
nothing calls this directly
no test coverage detected