mirror of https://github.com/procxx/kepka.git
Added ability to paste data in section of scheduled messages.
Fixed #6702. Fixed #6539.
This commit is contained in:
parent
97446ae783
commit
ccbc63cd6e
|
@ -551,10 +551,7 @@ void EditCaptionBox::prepare() {
|
|||
} else if (data->hasImage()) {
|
||||
return true;
|
||||
} else if (const auto urls = data->urls(); !urls.empty()) {
|
||||
if (ranges::find_if(
|
||||
urls,
|
||||
[](const QUrl &url) { return !url.isLocalFile(); }
|
||||
) == urls.end()) {
|
||||
if (ranges::all_of(urls, &QUrl::isLocalFile)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4475,10 +4475,7 @@ bool HistoryWidget::canSendFiles(not_null<const QMimeData*> data) const {
|
|||
} else if (data->hasImage()) {
|
||||
return true;
|
||||
} else if (const auto urls = data->urls(); !urls.empty()) {
|
||||
if (ranges::find_if(
|
||||
urls,
|
||||
[](const QUrl &url) { return !url.isLocalFile(); }
|
||||
) == urls.end()) {
|
||||
if (ranges::all_of(urls, &QUrl::isLocalFile)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,6 +110,10 @@ rpl::producer<> ComposeControls::attachRequests() const {
|
|||
});
|
||||
}
|
||||
|
||||
void ComposeControls::setMimeDataHook(MimeDataHook hook) {
|
||||
_field->setMimeDataHook(std::move(hook));
|
||||
}
|
||||
|
||||
rpl::producer<not_null<DocumentData*>> ComposeControls::fileChosen() const {
|
||||
return _fileChosen.events();
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/unique_qptr.h"
|
||||
#include "ui/rp_widget.h"
|
||||
#include "ui/effects/animations.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
#include "chat_helpers/tabbed_selector.h"
|
||||
|
||||
class History;
|
||||
|
@ -31,7 +32,6 @@ namespace Ui {
|
|||
class SendButton;
|
||||
class IconButton;
|
||||
class EmojiButton;
|
||||
class InputField;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Main {
|
||||
|
@ -76,6 +76,11 @@ public:
|
|||
[[nodiscard]] auto inlineResultChosen() const
|
||||
-> rpl::producer<ChatHelpers::TabbedSelector::InlineChosen>;
|
||||
|
||||
using MimeDataHook = Fn<bool(
|
||||
not_null<const QMimeData*> data,
|
||||
Ui::InputField::MimeAction action)>;
|
||||
void setMimeDataHook(MimeDataHook hook);
|
||||
|
||||
bool pushTabbedSelectorToThirdSection(
|
||||
not_null<PeerData*> peer,
|
||||
const Window::SectionShow ¶ms);
|
||||
|
|
|
@ -44,6 +44,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "styles/style_info.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
||||
#include <QtCore/QMimeData>
|
||||
|
||||
namespace HistoryView {
|
||||
namespace {
|
||||
|
||||
|
@ -55,6 +57,17 @@ void ShowErrorToast(const QString &text) {
|
|||
});
|
||||
}
|
||||
|
||||
bool CanSendFiles(not_null<const QMimeData*> data) {
|
||||
if (data->hasImage()) {
|
||||
return true;
|
||||
} else if (const auto urls = data->urls(); !urls.empty()) {
|
||||
if (ranges::all_of(urls, &QUrl::isLocalFile)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
object_ptr<Window::SectionWidget> ScheduledMemento::createWidget(
|
||||
|
@ -165,6 +178,20 @@ void ScheduledWidget::setupComposeControls() {
|
|||
ChatHelpers::TabbedSelector::InlineChosen chosen) {
|
||||
sendInlineResult(chosen.result, chosen.bot);
|
||||
}, lifetime());
|
||||
|
||||
_composeControls->setMimeDataHook([=](
|
||||
not_null<const QMimeData*> data,
|
||||
Ui::InputField::MimeAction action) {
|
||||
if (action == Ui::InputField::MimeAction::Check) {
|
||||
return CanSendFiles(data);
|
||||
} else if (action == Ui::InputField::MimeAction::Insert) {
|
||||
return confirmSendingFiles(
|
||||
data,
|
||||
CompressConfirm::Auto,
|
||||
data->text());
|
||||
}
|
||||
Unexpected("action in MimeData hook.");
|
||||
});
|
||||
}
|
||||
|
||||
void ScheduledWidget::chooseAttach() {
|
||||
|
@ -214,6 +241,43 @@ void ScheduledWidget::chooseAttach() {
|
|||
}), nullptr);
|
||||
}
|
||||
|
||||
bool ScheduledWidget::confirmSendingFiles(
|
||||
not_null<const QMimeData*> data,
|
||||
CompressConfirm compressed,
|
||||
const QString &insertTextOnCancel) {
|
||||
const auto hasImage = data->hasImage();
|
||||
|
||||
if (const auto urls = data->urls(); !urls.empty()) {
|
||||
auto list = Storage::PrepareMediaList(
|
||||
urls,
|
||||
st::sendMediaPreviewSize);
|
||||
if (list.error != Storage::PreparedList::Error::NonLocalUrl) {
|
||||
if (list.error == Storage::PreparedList::Error::None
|
||||
|| !hasImage) {
|
||||
const auto emptyTextOnCancel = QString();
|
||||
confirmSendingFiles(
|
||||
std::move(list),
|
||||
compressed,
|
||||
emptyTextOnCancel);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasImage) {
|
||||
auto image = qvariant_cast<QImage>(data->imageData());
|
||||
if (!image.isNull()) {
|
||||
confirmSendingFiles(
|
||||
std::move(image),
|
||||
QByteArray(),
|
||||
compressed,
|
||||
insertTextOnCancel);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ScheduledWidget::confirmSendingFiles(
|
||||
Storage::PreparedList &&list,
|
||||
CompressConfirm compressed,
|
||||
|
|
|
@ -159,6 +159,10 @@ private:
|
|||
Storage::PreparedList &&list,
|
||||
CompressConfirm compressed,
|
||||
const QString &insertTextOnCancel = QString());
|
||||
bool confirmSendingFiles(
|
||||
not_null<const QMimeData*> data,
|
||||
CompressConfirm compressed,
|
||||
const QString &insertTextOnCancel = QString());
|
||||
bool showSendingFilesError(const Storage::PreparedList &list) const;
|
||||
void uploadFilesAfterConfirmation(
|
||||
Storage::PreparedList &&list,
|
||||
|
|
Loading…
Reference in New Issue