Add better discard confirmations.

This commit is contained in:
John Preston 2024-10-22 19:54:58 +04:00
parent 6cfa053328
commit 6287d306c2
6 changed files with 27 additions and 10 deletions

View file

@ -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.";

View file

@ -964,6 +964,7 @@ void ComposeControls::setHistory(SetHistoryArgs &&args) {
initWebpageProcess();
initWriteRestriction();
initForwardProcess();
updateRecordMediaState();
updateBotCommandShown();
updateLikeShown();
updateMessagesTTLShown();

View file

@ -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,

View file

@ -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*> data) {

View file

@ -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);

View file

@ -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);
}