Save voice message to database when it is recognized.

This commit is contained in:
levlam 2022-09-19 11:15:13 +03:00
parent 8d0cb5b82d
commit 618bface99
4 changed files with 24 additions and 2 deletions

View File

@ -7193,6 +7193,15 @@ void MessagesManager::on_external_update_message_content(FullMessageId full_mess
} }
} }
void MessagesManager::on_update_message_content(FullMessageId full_message_id) {
Dialog *d = get_dialog(full_message_id.get_dialog_id());
CHECK(d != nullptr);
Message *m = get_message(d, full_message_id.get_message_id());
CHECK(m != nullptr);
send_update_message_content(d, m, true, "on_update_message_content");
on_message_changed(d, m, true, "on_update_message_content");
}
bool MessagesManager::update_message_contains_unread_mention(Dialog *d, Message *m, bool contains_unread_mention, bool MessagesManager::update_message_contains_unread_mention(Dialog *d, Message *m, bool contains_unread_mention,
const char *source) { const char *source) {
LOG_CHECK(m != nullptr) << source; LOG_CHECK(m != nullptr) << source;

View File

@ -366,6 +366,8 @@ class MessagesManager final : public Actor {
void on_external_update_message_content(FullMessageId full_message_id); void on_external_update_message_content(FullMessageId full_message_id);
void on_update_message_content(FullMessageId full_message_id);
void on_read_channel_inbox(ChannelId channel_id, MessageId max_message_id, int32 server_unread_count, int32 pts, void on_read_channel_inbox(ChannelId channel_id, MessageId max_message_id, int32 server_unread_count, int32 pts,
const char *source); const char *source);

View File

@ -182,7 +182,7 @@ FileId VoiceNotesManager::on_get_voice_note(unique_ptr<VoiceNote> new_voice_note
v->transcription_id = new_voice_note->transcription_id; v->transcription_id = new_voice_note->transcription_id;
v->text = std::move(new_voice_note->text); v->text = std::move(new_voice_note->text);
v->last_transcription_error = Status::OK(); v->last_transcription_error = Status::OK();
on_voice_note_transcription_updated(file_id); on_voice_note_transcription_completed(file_id);
} }
} }
@ -316,7 +316,7 @@ void VoiceNotesManager::on_voice_note_transcribed(FileId file_id, string &&text,
auto promises = std::move(it->second); auto promises = std::move(it->second);
speech_recognition_queries_.erase(it); speech_recognition_queries_.erase(it);
on_voice_note_transcription_updated(file_id); on_voice_note_transcription_completed(file_id);
set_promises(promises); set_promises(promises);
} else { } else {
if (is_changed) { if (is_changed) {
@ -386,6 +386,15 @@ void VoiceNotesManager::on_voice_note_transcription_updated(FileId file_id) {
} }
} }
void VoiceNotesManager::on_voice_note_transcription_completed(FileId file_id) {
auto it = voice_note_messages_.find(file_id);
if (it != voice_note_messages_.end()) {
for (const auto &full_message_id : it->second) {
td_->messages_manager_->on_update_message_content(full_message_id);
}
}
}
void VoiceNotesManager::rate_speech_recognition(FullMessageId full_message_id, bool is_good, Promise<Unit> &&promise) { void VoiceNotesManager::rate_speech_recognition(FullMessageId full_message_id, bool is_good, Promise<Unit> &&promise) {
if (!td_->messages_manager_->have_message_force(full_message_id, "rate_speech_recognition")) { if (!td_->messages_manager_->have_message_force(full_message_id, "rate_speech_recognition")) {
return promise.set_error(Status::Error(400, "Message not found")); return promise.set_error(Status::Error(400, "Message not found"));

View File

@ -100,6 +100,8 @@ class VoiceNotesManager final : public Actor {
void on_voice_note_transcription_updated(FileId file_id); void on_voice_note_transcription_updated(FileId file_id);
void on_voice_note_transcription_completed(FileId file_id);
void tear_down() final; void tear_down() final;
Td *td_; Td *td_;