feat: send GIF|voice confirmation by settings toggles

This commit is contained in:
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 2023-06-28 00:00:03 +03:00
parent 0c0dc3fde8
commit 243245d680
9 changed files with 248 additions and 32 deletions

View file

@ -102,6 +102,8 @@ PRIVATE
ayu/ayu_settings.h ayu/ayu_settings.h
ayu/ayu_lang.cpp ayu/ayu_lang.cpp
ayu/ayu_lang.h ayu/ayu_lang.h
ayu/boxes/voice_confirmation_box.cpp
ayu/boxes/voice_confirmation_box.h
ayu/boxes/confirmation_box.cpp ayu/boxes/confirmation_box.cpp
ayu/boxes/confirmation_box.h ayu/boxes/confirmation_box.h
ayu/boxes/edit_deleted_mark.cpp ayu/boxes/edit_deleted_mark.cpp

View file

@ -153,6 +153,10 @@ namespace AyuSettings {
GIFConfirmation = val; GIFConfirmation = val;
} }
void AyuGramSettings::set_voiceConfirmation(bool val) {
voiceConfirmation = val;
}
bool AyuGramSettings::getGhostModeValue() { bool AyuGramSettings::getGhostModeValue() {
return (!sendReadPackets return (!sendReadPackets
&& !sendOnlinePackets && !sendOnlinePackets
@ -161,6 +165,7 @@ namespace AyuSettings {
} }
rpl::producer<QString> get_deletedMarkReactive() { rpl::producer<QString> get_deletedMarkReactive() {
return deletedMarkReactive.value(); return deletedMarkReactive.value();
} }

View file

@ -39,6 +39,7 @@ namespace AyuSettings {
// ~ Beta functionality // ~ Beta functionality
stickerConfirmation = false; stickerConfirmation = false;
GIFConfirmation = false; GIFConfirmation = false;
voiceConfirmation = false;
/* /*
* showPeerId = 0 means no ID shown * showPeerId = 0 means no ID shown
@ -86,6 +87,8 @@ namespace AyuSettings {
QS_FIELD(bool, GIFConfirmation) QS_FIELD(bool, GIFConfirmation)
QS_FIELD(bool, voiceConfirmation)
public: public:
void set_sendReadPackets(bool val); void set_sendReadPackets(bool val);
void set_sendOnlinePackets(bool val); void set_sendOnlinePackets(bool val);
@ -110,6 +113,7 @@ namespace AyuSettings {
void set_stickerConfirmation(bool val); void set_stickerConfirmation(bool val);
void set_GIFConfirmation(bool val); void set_GIFConfirmation(bool val);
void set_voiceConfirmation(bool val);
bool getGhostModeValue(); bool getGhostModeValue();
}; };

View file

@ -0,0 +1,103 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "ui/boxes/confirm_box.h"
#include "lang/lang_keys.h"
#include "ui/widgets/buttons.h"
#include "styles/style_layers.h"
#include "voice_confirmation_box.h"
namespace AyuUi {
void VoiceConfirmBox(not_null<Ui::GenericBox *> box, Ui::ConfirmBoxArgs &&args) {
const auto weak = Ui::MakeWeak(box);
const auto lifetime = box->lifetime().make_state<rpl::lifetime>();
v::match(args.text, [](v::null_t) {
}, [&](auto &&) {
const auto label = box->addRow(
object_ptr<Ui::FlatLabel>(
box.get(),
v::text::take_marked(std::move(args.text)),
args.labelStyle ? *args.labelStyle : st::boxLabel),
st::boxPadding);
if (args.labelFilter) {
label->setClickHandlerFilter(std::move(args.labelFilter));
}
});
const auto prepareCallback = [&](Ui::ConfirmBoxArgs::Callback &callback) {
return [=, confirmed = std::move(callback)]() {
if (const auto callbackPtr = std::get_if<1>(&confirmed)) {
if (auto callback = (*callbackPtr)) {
callback();
}
} else if (const auto callbackPtr = std::get_if<2>(&confirmed)) {
if (auto callback = (*callbackPtr)) {
callback(crl::guard(weak, [=] { weak->closeBox(); }));
}
} else if (weak) {
weak->closeBox();
}
};
};
const auto &defaultButtonStyle = box->getDelegate()->style().button;
const auto confirmButton = box->addButton(
v::text::take_plain(std::move(args.confirmText), tr::lng_box_ok()),
[=, c = prepareCallback(args.confirmed)]() {
lifetime->destroy();
c();
weak->closeBox();
},
args.confirmStyle ? *args.confirmStyle : defaultButtonStyle);
box->events(
) | rpl::start_with_next([=](not_null<QEvent *> e) {
if ((e->type() != QEvent::KeyPress) || !confirmButton) {
return;
}
const auto k = static_cast<QKeyEvent *>(e.get());
if (k->key() == Qt::Key_Enter || k->key() == Qt::Key_Return) {
confirmButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton);
}
}, box->lifetime());
if (!args.inform) {
const auto cancelButton = box->addButton(
v::text::take_plain(std::move(args.cancelText), tr::lng_cancel()),
crl::guard(weak, [=, c = prepareCallback(args.cancelled)]() {
lifetime->destroy();
c();
}),
args.cancelStyle ? *args.cancelStyle : defaultButtonStyle);
box->boxClosing(
) | rpl::start_with_next(crl::guard(cancelButton, [=] {
cancelButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton);
}), *lifetime);
}
if (args.strictCancel) {
lifetime->destroy();
}
}
object_ptr<Ui::GenericBox> MakeConfirmBox(Ui::ConfirmBoxArgs &&args) {
return Box(VoiceConfirmBox, std::move(args));
}
object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text) {
return MakeConfirmBox({
.text = std::move(text),
.inform = true,
});
}
} // namespace AyuUi

View file

@ -0,0 +1,21 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "ui/layers/generic_box.h"
#include "ui/text/text_variant.h"
#include "ui/boxes/confirm_box.h"
namespace AyuUi {
void VoiceConfirmBox(not_null<Ui::GenericBox*> box, Ui::ConfirmBoxArgs &&args);
[[nodiscard]] object_ptr<Ui::GenericBox> MakeConfirmBox(
Ui::ConfirmBoxArgs &&args);
[[nodiscard]] object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text);
} // namespace Ui

View file

@ -336,6 +336,34 @@ namespace Settings {
settings->set_stickerConfirmation(enabled); settings->set_stickerConfirmation(enabled);
AyuSettings::save(); AyuSettings::save();
}, container->lifetime()); }, container->lifetime());
AddButton(
container,
rpl::single(QString("Send GIF confirmation")),
st::settingsButtonNoIcon
)->toggleOn(
rpl::single(settings->GIFConfirmation)
)->toggledValue(
) | rpl::filter([=] (bool enabled) {
return (enabled != settings->GIFConfirmation);
}) | rpl::start_with_next([=] (bool enabled) {
settings->set_GIFConfirmation(enabled);
AyuSettings::save();
}, container->lifetime());
AddButton(
container,
rpl::single(QString("Send voice confirmation")),
st::settingsButtonNoIcon
)->toggleOn(
rpl::single(settings->voiceConfirmation)
)->toggledValue(
) | rpl::filter([=] (bool enabled) {
return (enabled != settings->voiceConfirmation);
}) | rpl::start_with_next([=] (bool enabled) {
settings->set_voiceConfirmation(enabled);
AyuSettings::save();
}, container->lifetime());
} }
void Ayu::SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container, not_null<Window::SessionController *> controller) { void Ayu::SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container, not_null<Window::SessionController *> controller) {

View file

@ -43,6 +43,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_menu_icons.h" #include "styles/style_menu_icons.h"
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
#include <ayu/ayu_settings.h>
#include <ui/boxes/confirm_box.h>
namespace ChatHelpers { namespace ChatHelpers {
namespace { namespace {
@ -470,9 +472,11 @@ void GifsListWidget::selectInlineResult(
if (forceSend if (forceSend
|| (media && media->image(PhotoSize::Thumbnail)) || (media && media->image(PhotoSize::Thumbnail))
|| (media && media->image(PhotoSize::Large))) { || (media && media->image(PhotoSize::Large))) {
// why photo type in GIF sender?
_photoChosen.fire({ _photoChosen.fire({
.photo = photo, .photo = photo,
.options = options }); .options = options });
} else if (!photo->loading(PhotoSize::Thumbnail)) { } else if (!photo->loading(PhotoSize::Thumbnail)) {
photo->load(PhotoSize::Thumbnail, Data::FileOrigin()); photo->load(PhotoSize::Thumbnail, Data::FileOrigin());
} }
@ -480,11 +484,25 @@ void GifsListWidget::selectInlineResult(
const auto media = document->activeMediaView(); const auto media = document->activeMediaView();
const auto preview = Data::VideoPreviewState(media.get()); const auto preview = Data::VideoPreviewState(media.get());
if (forceSend || (media && preview.loaded())) { if (forceSend || (media && preview.loaded())) {
_fileChosen.fire({ auto settings = &AyuSettings::getInstance();
.document = document, auto sendGIFCallback = [=, this] {
.options = options, _fileChosen.fire({
.messageSendingFrom = messageSendingFrom(), .document = document,
}); .options = options,
.messageSendingFrom = messageSendingFrom(),
});
};
if (settings->GIFConfirmation) {
Ui::show(Ui::MakeConfirmBox({
.text = rpl::single(QString("Do you want to send this GIF?")),
.confirmed = sendGIFCallback,
.confirmText = rpl::single(QString("Send")),
}));
}
else {
sendGIFCallback();
}
} else if (!preview.usingThumbnail()) { } else if (!preview.usingThumbnail()) {
if (preview.loading()) { if (preview.loading()) {
document->cancel(); document->cancel();

View file

@ -5,6 +5,8 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link: For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include <ayu/ayu_settings.h>
#include <ayu/boxes/voice_confirmation_box.h>
#include "history/view/controls/history_view_voice_record_bar.h" #include "history/view/controls/history_view_voice_record_bar.h"
#include "api/api_send_progress.h" #include "api/api_send_progress.h"
@ -35,6 +37,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/ripple_animation.h" #include "ui/effects/ripple_animation.h"
#include "ui/text/format_values.h" #include "ui/text/format_values.h"
#include "ui/painter.h" #include "ui/painter.h"
#include "boxes/abstract_box.h"
namespace HistoryView::Controls { namespace HistoryView::Controls {
@ -1426,8 +1429,24 @@ void VoiceRecordBar::stopRecording(StopType type) {
window()->raise(); window()->raise();
window()->activateWindow(); window()->activateWindow();
const auto duration = Duration(data.samples); const auto duration = Duration(data.samples);
auto settings = &AyuSettings::getInstance();
if (type == StopType::Send) { if (type == StopType::Send) {
_sendVoiceRequests.fire({ data.bytes, data.waveform, duration }); auto sendVoiceCallback = [=, this] {
_sendVoiceRequests.fire({ data.bytes, data.waveform, duration });
};
if (settings->voiceConfirmation) {
Ui::show(AyuUi::MakeConfirmBox({
.text = rpl::single(QString("Do you want to send voice message?")),
.confirmed = sendVoiceCallback,
.confirmText = rpl::single(QString("Send"))
}));
}
else {
sendVoiceCallback();
}
} else if (type == StopType::Listen) { } else if (type == StopType::Listen) {
_listen = std::make_unique<ListenWrap>( _listen = std::make_unique<ListenWrap>(
this, this,
@ -1500,11 +1519,27 @@ void VoiceRecordBar::drawMessage(Painter &p, float64 recordActive) {
void VoiceRecordBar::requestToSendWithOptions(Api::SendOptions options) { void VoiceRecordBar::requestToSendWithOptions(Api::SendOptions options) {
if (isListenState()) { if (isListenState()) {
const auto data = _listen->data(); const auto data = _listen->data();
_sendVoiceRequests.fire({ auto settings = &AyuSettings::getInstance();
data->bytes,
data->waveform, auto sendVoiceCallback = [=, this] {
Duration(data->samples), _sendVoiceRequests.fire({
options }); data->bytes,
data->waveform,
Duration(data->samples),
options
});
};
if (settings->voiceConfirmation) {
Ui::show(AyuUi::MakeConfirmBox({
.text = rpl::single(QString("Do you want to send voice message?")),
.confirmed = sendVoiceCallback,
.confirmText = rpl::single(QString("Send"))
}));
}
else {
sendVoiceCallback();
}
} }
} }

View file

@ -90,28 +90,28 @@ void Tray::rebuildMenu() {
[=] { toggleSoundNotifications(); }); [=] { toggleSoundNotifications(); });
} }
auto turnGhostModeText = _textUpdates.events( // auto turnGhostModeText = _textUpdates.events(
) | rpl::map([=] { // ) | rpl::map([=] {
auto settings = AyuSettings::AyuGramSettings(); // auto settings = AyuSettings::AyuGramSettings();
bool ghostModeEnabled = settings.getGhostModeValue(); // bool ghostModeEnabled = settings.getGhostModeValue();
//
// return ghostModeEnabled
// ? tr::ayu_DisableGhostMode(tr::now)
// : tr::ayu_EnableGhostMode(tr::now);
// });
return ghostModeEnabled // _tray.addAction(rpl::single(QString("Toggle ghost mode")), [=] {
? tr::ayu_DisableGhostMode(tr::now) // auto settings = &AyuSettings::getInstance();
: tr::ayu_EnableGhostMode(tr::now); // bool ghostMode = (bool) AyuSettings::get_ghostModeEnabled();
}); //
// settings->set_sendReadPackets(!ghostMode);
_tray.addAction(rpl::single(QString("Toggle ghost mode")), [=] { // settings->set_sendOnlinePackets(!ghostMode);
auto settings = &AyuSettings::getInstance(); // settings->set_sendUploadProgress(!ghostMode);
bool ghostMode = (bool) AyuSettings::get_ghostModeEnabled(); //
// settings->set_sendOfflinePacketAfterOnline(ghostMode);
settings->set_sendReadPackets(!ghostMode); //
settings->set_sendOnlinePackets(!ghostMode); // AyuSettings::save();
settings->set_sendUploadProgress(!ghostMode); // });
settings->set_sendOfflinePacketAfterOnline(ghostMode);
AyuSettings::save();
});
auto quitText = _textUpdates.events( auto quitText = _textUpdates.events(
) | rpl::map([=] { ) | rpl::map([=] {