Pause voice in pay-to-send chats.

This commit is contained in:
John Preston 2025-03-03 13:36:14 +04:00
parent d1e6150874
commit 4ab4eb8ef2
4 changed files with 22 additions and 4 deletions

View file

@ -5169,12 +5169,13 @@ void HistoryWidget::updateSendButtonType() {
: 0;
}();
const auto perMessage = _peer ? _peer->starsPerMessageChecked() : 0;
const auto stars = perMessage
? perMessage * ComputeSendingMessagesCount(_history, {
const auto messages = _voiceRecordBar->isListenState()
? 1
: ComputeSendingMessagesCount(_history, {
.forward = &_forwardPanel->items(),
.text = &_field->getTextWithTags(),
})
: 0;
});
const auto stars = perMessage ? (perMessage * messages) : 0;
_send->setState({
.type = (delay > 0) ? Type::Slowmode : type,
.slowmodeDelay = delay,
@ -5775,6 +5776,9 @@ void HistoryWidget::fieldFocused() {
}
void HistoryWidget::updateFieldPlaceholder() {
_voiceRecordBar->setPauseInsteadSend(_history
&& _history->peer->starsPerMessageChecked() > 0);
if (!_editMsgId && _inlineBot && !_inlineLookingUpBot) {
_field->setPlaceholder(
rpl::single(_inlineBot->botInfo->inlinePlaceholder.mid(1)),

View file

@ -1714,6 +1714,9 @@ void ComposeControls::initFieldAutocomplete() {
}
void ComposeControls::updateFieldPlaceholder() {
_voiceRecordBar->setPauseInsteadSend(_history
&& _history->peer->starsPerMessageChecked() > 0);
if (!isEditingMessage() && _isInlineBot) {
_field->setPlaceholder(
rpl::single(_inlineBot->botInfo->inlinePlaceholder.mid(1)),

View file

@ -1768,6 +1768,10 @@ void VoiceRecordBar::setTTLFilter(FilterCallback &&callback) {
_hasTTLFilter = std::move(callback);
}
void VoiceRecordBar::setPauseInsteadSend(bool pauseInsteadSend) {
_pauseInsteadSend = pauseInsteadSend;
}
void VoiceRecordBar::initLockGeometry() {
const auto parent = static_cast<Ui::RpWidget*>(parentWidget());
rpl::merge(
@ -1918,6 +1922,11 @@ void VoiceRecordBar::recordUpdated(quint16 level, int samples) {
void VoiceRecordBar::stop(bool send) {
if (isHidden() && !send) {
return;
} else if (send && _pauseInsteadSend) {
_fullRecord = true;
stopRecording(StopType::Listen);
_lockShowing = false;
return;
}
const auto ttlBeforeHide = peekTTLState();
auto disappearanceCallback = [=] {

View file

@ -100,6 +100,7 @@ public:
void setStartRecordingFilter(FilterCallback &&callback);
void setTTLFilter(FilterCallback &&callback);
void setPauseInsteadSend(bool pauseInsteadSend);
[[nodiscard]] bool isRecording() const;
[[nodiscard]] bool isRecordingLocked() const;
@ -193,6 +194,7 @@ private:
FilterCallback _hasTTLFilter;
bool _warningShown = false;
bool _pauseInsteadSend = false;
rpl::variable<bool> _recording = false;
rpl::variable<bool> _inField = false;