From 6287d306c24fc89ac2b28a14bf7bea087e2b2fa0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 22 Oct 2024 19:54:58 +0400 Subject: [PATCH] Add better discard confirmations. --- Telegram/Resources/langs/lang.strings | 3 +++ .../history_view_compose_controls.cpp | 1 + .../history_view_voice_record_bar.cpp | 24 ++++++++++++------- .../media/player/media_player_instance.cpp | 5 +++- .../media/player/media_player_instance.h | 2 +- .../media/player/media_player_widget.cpp | 2 ++ 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index e42eaaf6a..6ffd7dd8f 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2152,6 +2152,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_media_cancel" = "Cancel"; "lng_media_video" = "Video"; "lng_media_audio" = "Voice message"; +"lng_media_round" = "Video message"; "lng_media_auto_settings" = "Automatic media download"; "lng_media_auto_in_private" = "In private chats"; @@ -3244,7 +3245,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_record_cancel" = "Release outside this field to cancel"; "lng_record_cancel_stories" = "Release outside to cancel"; "lng_record_lock_cancel_sure" = "Do you want to stop recording and discard your voice message?"; +"lng_record_lock_cancel_sure_round" = "Do you want to stop recording and discard your video message?"; "lng_record_listen_cancel_sure" = "Do you want to discard your recorded voice message?"; +"lng_record_listen_cancel_sure_round" = "Do you want to discard your recorded video message?"; "lng_record_lock_discard" = "Discard"; "lng_record_voice_tip" = "Hold to record audio. Click to switch to video."; "lng_record_video_tip" = "Hold to record video. Click to switch to audio."; diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index aab9559ca..4314f738c 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -964,6 +964,7 @@ void ComposeControls::setHistory(SetHistoryArgs &&args) { initWebpageProcess(); initWriteRestriction(); initForwardProcess(); + updateRecordMediaState(); updateBotCommandShown(); updateLikeShown(); updateMessagesTTLShown(); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp index 754f1ab21..7c582784a 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp @@ -790,6 +790,13 @@ void ListenWrap::initPlayButton() { ) | rpl::start_with_next([=] { *showPause = false; }, _lifetime); + + _lifetime.add([=] { + const auto current = instance()->current(AudioMsgId::Type::Voice); + if (current.audio() == _document) { + instance()->stop(AudioMsgId::Type::Voice, true); + } + }); } void ListenWrap::initPlayProgress() { @@ -1369,7 +1376,7 @@ VoiceRecordBar::VoiceRecordBar( } VoiceRecordBar::~VoiceRecordBar() { - if (isRecording()) { + if (isActive()) { stopRecording(StopType::Cancel); } } @@ -1598,7 +1605,6 @@ void VoiceRecordBar::init() { if (!paused) { return; } - // _lockShowing = false; const auto to = 1.; auto callback = [=](float64 value) { @@ -1819,7 +1825,8 @@ void VoiceRecordBar::startRecording() { ) | rpl::start_with_next_error([=](const Update &update) { recordUpdated(update.level, update.samples); if (update.finished) { - stop(update.samples >= kMinSamples); + stopRecording(StopType::Listen); + _lockShowing = false; } }, [=](Error error) { stop(false); @@ -1895,7 +1902,6 @@ void VoiceRecordBar::stop(bool send) { const auto type = send ? StopType::Send : StopType::Cancel; stopRecording(type, ttlBeforeHide); }; - // _lockShowing = false; visibilityAnimate(false, std::move(disappearanceCallback)); } @@ -1985,8 +1991,6 @@ void VoiceRecordBar::stopRecording(StopType type, bool ttlBeforeHide) { &_data, _cancelFont); _listenChanges.fire({}); - - // _lockShowing = false; })); } } else if (type == StopType::Send) { @@ -2313,8 +2317,12 @@ void VoiceRecordBar::showDiscardBox( }; _show->showBox(Ui::MakeConfirmBox({ .text = (isListenState() - ? tr::lng_record_listen_cancel_sure - : tr::lng_record_lock_cancel_sure)(), + ? (_recordingVideo + ? tr::lng_record_listen_cancel_sure_round + : tr::lng_record_listen_cancel_sure) + : (_recordingVideo + ? tr::lng_record_lock_cancel_sure_round + : tr::lng_record_lock_cancel_sure))(), .confirmed = std::move(sure), .confirmText = tr::lng_record_lock_discard(), .confirmStyle = &st::attentionBoxButton, diff --git a/Telegram/SourceFiles/media/player/media_player_instance.cpp b/Telegram/SourceFiles/media/player/media_player_instance.cpp index 2859aa068..127009d25 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.cpp +++ b/Telegram/SourceFiles/media/player/media_player_instance.cpp @@ -869,7 +869,7 @@ void Instance::pause(AudioMsgId::Type type) { } } -void Instance::stop(AudioMsgId::Type type) { +void Instance::stop(AudioMsgId::Type type, bool asFinished) { if (const auto data = getData(type)) { if (data->streamed) { clearStreamed(data); @@ -877,6 +877,9 @@ void Instance::stop(AudioMsgId::Type type) { data->resumeOnCallEnd = false; _playerStopped.fire_copy({type}); } + if (asFinished) { + _tracksFinished.fire_copy(type); + } } void Instance::stopAndClear(not_null data) { diff --git a/Telegram/SourceFiles/media/player/media_player_instance.h b/Telegram/SourceFiles/media/player/media_player_instance.h index 13771ce4c..ebe7d3d4c 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.h +++ b/Telegram/SourceFiles/media/player/media_player_instance.h @@ -72,7 +72,7 @@ public: void play(AudioMsgId::Type type); void pause(AudioMsgId::Type type); - void stop(AudioMsgId::Type type); + void stop(AudioMsgId::Type type, bool asFinished = false); void playPause(AudioMsgId::Type type); bool next(AudioMsgId::Type type); bool previous(AudioMsgId::Type type); diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index f45bda81a..a74be5945 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -717,6 +717,8 @@ void Widget::handleSongChange() { 0, name.size(), QString())); + } else if (document->isVideoMessage()) { + textWithEntities.text = tr::lng_media_round(tr::now); } else { textWithEntities.text = tr::lng_media_audio(tr::now); }