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_lang.cpp
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.h
ayu/boxes/edit_deleted_mark.cpp

View file

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

View file

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

View file

@ -43,6 +43,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_menu_icons.h"
#include <QtWidgets/QApplication>
#include <ayu/ayu_settings.h>
#include <ui/boxes/confirm_box.h>
namespace ChatHelpers {
namespace {
@ -470,9 +472,11 @@ void GifsListWidget::selectInlineResult(
if (forceSend
|| (media && media->image(PhotoSize::Thumbnail))
|| (media && media->image(PhotoSize::Large))) {
// why photo type in GIF sender?
_photoChosen.fire({
.photo = photo,
.options = options });
} else if (!photo->loading(PhotoSize::Thumbnail)) {
photo->load(PhotoSize::Thumbnail, Data::FileOrigin());
}
@ -480,11 +484,25 @@ void GifsListWidget::selectInlineResult(
const auto media = document->activeMediaView();
const auto preview = Data::VideoPreviewState(media.get());
if (forceSend || (media && preview.loaded())) {
_fileChosen.fire({
.document = document,
.options = options,
.messageSendingFrom = messageSendingFrom(),
});
auto settings = &AyuSettings::getInstance();
auto sendGIFCallback = [=, this] {
_fileChosen.fire({
.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()) {
if (preview.loading()) {
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:
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 "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/text/format_values.h"
#include "ui/painter.h"
#include "boxes/abstract_box.h"
namespace HistoryView::Controls {
@ -1426,8 +1429,24 @@ void VoiceRecordBar::stopRecording(StopType type) {
window()->raise();
window()->activateWindow();
const auto duration = Duration(data.samples);
auto settings = &AyuSettings::getInstance();
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) {
_listen = std::make_unique<ListenWrap>(
this,
@ -1500,11 +1519,27 @@ void VoiceRecordBar::drawMessage(Painter &p, float64 recordActive) {
void VoiceRecordBar::requestToSendWithOptions(Api::SendOptions options) {
if (isListenState()) {
const auto data = _listen->data();
_sendVoiceRequests.fire({
data->bytes,
data->waveform,
Duration(data->samples),
options });
auto settings = &AyuSettings::getInstance();
auto sendVoiceCallback = [=, this] {
_sendVoiceRequests.fire({
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(); });
}
auto turnGhostModeText = _textUpdates.events(
) | rpl::map([=] {
auto settings = AyuSettings::AyuGramSettings();
bool ghostModeEnabled = settings.getGhostModeValue();
// auto turnGhostModeText = _textUpdates.events(
// ) | rpl::map([=] {
// auto settings = AyuSettings::AyuGramSettings();
// bool ghostModeEnabled = settings.getGhostModeValue();
//
// return ghostModeEnabled
// ? tr::ayu_DisableGhostMode(tr::now)
// : tr::ayu_EnableGhostMode(tr::now);
// });
return ghostModeEnabled
? tr::ayu_DisableGhostMode(tr::now)
: tr::ayu_EnableGhostMode(tr::now);
});
_tray.addAction(rpl::single(QString("Toggle ghost mode")), [=] {
auto settings = &AyuSettings::getInstance();
bool ghostMode = (bool) AyuSettings::get_ghostModeEnabled();
settings->set_sendReadPackets(!ghostMode);
settings->set_sendOnlinePackets(!ghostMode);
settings->set_sendUploadProgress(!ghostMode);
settings->set_sendOfflinePacketAfterOnline(ghostMode);
AyuSettings::save();
});
// _tray.addAction(rpl::single(QString("Toggle ghost mode")), [=] {
// auto settings = &AyuSettings::getInstance();
// bool ghostMode = (bool) AyuSettings::get_ghostModeEnabled();
//
// settings->set_sendReadPackets(!ghostMode);
// settings->set_sendOnlinePackets(!ghostMode);
// settings->set_sendUploadProgress(!ghostMode);
//
// settings->set_sendOfflinePacketAfterOnline(ghostMode);
//
// AyuSettings::save();
// });
auto quitText = _textUpdates.events(
) | rpl::map([=] {