Skip to content

Commit b3c7ce0

Browse files
committed
Added ability to send recording voice with submit key.
1 parent feea881 commit b3c7ce0

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ For license and copyright information please follow this link:
4040
#include "ui/text/text_utilities.h"
4141
#include "ui/dynamic_image.h"
4242
#include "ui/painter.h"
43+
#include "ui/widgets/fields/input_field.h" // ShouldSubmit.
4344
#include "ui/widgets/tooltip.h"
4445
#include "ui/rect.h"
4546
#include "ui/ui_utility.h"
@@ -1943,6 +1944,40 @@ void VoiceRecordBar::startRecording() {
19431944
stop(_inField.current());
19441945
}
19451946
}, _recordingLifetime);
1947+
1948+
_listenChanges.events_starting_with(
1949+
rpl::empty_value()
1950+
) | rpl::filter([=] {
1951+
return _listen == nullptr;
1952+
}) | rpl::start_with_next([=] {
1953+
auto keyFilterCallback = [=](not_null<QEvent*> e) {
1954+
using Result = base::EventFilterResult;
1955+
if (_send->type() != Ui::SendButton::Type::Record
1956+
&& _send->type() != Ui::SendButton::Type::Round) {
1957+
return Result::Continue;
1958+
}
1959+
switch(e->type()) {
1960+
case QEvent::KeyPress: {
1961+
if (!_warningShown
1962+
&& isRecordingLocked()
1963+
&& Ui::ShouldSubmit(
1964+
static_cast<QKeyEvent*>(e.get()),
1965+
Core::App().settings().sendSubmitWay())) {
1966+
stop(true);
1967+
return Result::Cancel;
1968+
}
1969+
return Result::Continue;
1970+
}
1971+
default: return Result::Continue;
1972+
}
1973+
};
1974+
1975+
_keyFilterInRecordingState = base::unique_qptr{
1976+
base::install_event_filter(
1977+
QCoreApplication::instance(),
1978+
std::move(keyFilterCallback)).get()
1979+
};
1980+
}, lifetime());
19461981
}
19471982

19481983
void VoiceRecordBar::checkTipRequired() {
@@ -2016,6 +2051,7 @@ void VoiceRecordBar::hideFast() {
20162051
_lock->hide();
20172052
_level->hide();
20182053
[[maybe_unused]] const auto s = takeTTLState();
2054+
_keyFilterInRecordingState = nullptr;
20192055
}
20202056

20212057
void VoiceRecordBar::stopRecording(StopType type, bool ttlBeforeHide) {
@@ -2353,6 +2389,7 @@ void VoiceRecordBar::orderControls() {
23532389
}
23542390

23552391
void VoiceRecordBar::installListenStateFilter() {
2392+
_keyFilterInRecordingState = nullptr;
23562393
auto keyFilterCallback = [=](not_null<QEvent*> e) {
23572394
using Result = base::EventFilterResult;
23582395
if (!(_send->type() == Ui::SendButton::Type::Send

Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ class VoiceRecordBar final : public Ui::RpWidget {
194194
FilterCallback _startRecordingFilter;
195195
FilterCallback _hasTTLFilter;
196196

197+
base::unique_qptr<QObject> _keyFilterInRecordingState;
198+
197199
bool _warningShown = false;
198200
bool _pauseInsteadSend = false;
199201

0 commit comments

Comments
 (0)