| 171 | } |
| 172 | |
| 173 | void Transcribes::load(not_null<HistoryItem*> item) { |
| 174 | if (!item->isHistoryEntry() || item->isLocal()) { |
| 175 | return; |
| 176 | } |
| 177 | const auto toggleRound = [](not_null<HistoryItem*> item, Entry &entry) { |
| 178 | if (const auto media = item->media()) { |
| 179 | if (const auto document = media->document()) { |
| 180 | if (document->isVideoMessage()) { |
| 181 | entry.roundview = true; |
| 182 | document->owner().requestItemViewRefresh(item); |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | }; |
| 187 | const auto id = item->fullId(); |
| 188 | const auto requestId = _api.request(MTPmessages_TranscribeAudio( |
| 189 | item->history()->peer->input(), |
| 190 | MTP_int(item->id) |
| 191 | )).done([=](const MTPmessages_TranscribedAudio &result) { |
| 192 | const auto &data = result.data(); |
| 193 | |
| 194 | { |
| 195 | const auto trialsCountChanged = data.vtrial_remains_num() |
| 196 | && (_trialsCount != data.vtrial_remains_num()->v); |
| 197 | if (trialsCountChanged) { |
| 198 | _trialsCount = data.vtrial_remains_num()->v; |
| 199 | } |
| 200 | const auto refreshAtChanged = data.vtrial_remains_until_date() |
| 201 | && (_trialsRefreshAt != data.vtrial_remains_until_date()->v); |
| 202 | if (refreshAtChanged) { |
| 203 | _trialsRefreshAt = data.vtrial_remains_until_date()->v; |
| 204 | } |
| 205 | if (trialsCountChanged) { |
| 206 | ShowTrialTranscribesToast(_trialsCount, _trialsRefreshAt); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | auto &entry = _map[id]; |
| 211 | entry.requestId = 0; |
| 212 | entry.pending = data.is_pending(); |
| 213 | entry.result = qs(data.vtext()); |
| 214 | _ids.emplace(data.vtranscription_id().v, id); |
| 215 | if (const auto item = _session->data().message(id)) { |
| 216 | toggleRound(item, entry); |
| 217 | _session->data().requestItemResize(item); |
| 218 | } |
| 219 | }).fail([=](const MTP::Error &error) { |
| 220 | auto &entry = _map[id]; |
| 221 | entry.requestId = 0; |
| 222 | entry.pending = false; |
| 223 | entry.failed = true; |
| 224 | if (error.type() == u"MSG_VOICE_TOO_LONG"_q) { |
| 225 | entry.toolong = true; |
| 226 | } |
| 227 | if (const auto item = _session->data().message(id)) { |
| 228 | toggleRound(item, entry); |
| 229 | _session->data().requestItemResize(item); |
| 230 | } |
no test coverage detected