2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
2016-11-28 15:45:07 +00:00
|
|
|
#include "boxes/send_files_box.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2017-12-19 16:57:42 +00:00
|
|
|
#include "storage/storage_media_prepare.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "mainwidget.h"
|
2020-06-18 12:47:09 +00:00
|
|
|
#include "main/main_session.h"
|
2021-04-26 08:23:54 +00:00
|
|
|
#include "main/main_session_settings.h"
|
2020-06-17 09:36:25 +00:00
|
|
|
#include "mtproto/mtproto_config.h"
|
2018-05-24 13:03:21 +00:00
|
|
|
#include "chat_helpers/message_field.h"
|
2022-03-27 10:01:34 +00:00
|
|
|
#include "menu/menu_send.h"
|
2018-11-21 10:09:46 +00:00
|
|
|
#include "chat_helpers/emoji_suggestions_widget.h"
|
2018-11-22 12:48:50 +00:00
|
|
|
#include "chat_helpers/tabbed_panel.h"
|
|
|
|
#include "chat_helpers/tabbed_selector.h"
|
2021-02-20 03:30:14 +00:00
|
|
|
#include "editor/photo_editor_layer_widget.h"
|
2020-06-13 14:13:56 +00:00
|
|
|
#include "history/history_drag_area.h"
|
2019-08-13 15:35:49 +00:00
|
|
|
#include "history/view/history_view_schedule_box.h"
|
2017-02-28 14:05:30 +00:00
|
|
|
#include "core/file_utilities.h"
|
2018-06-13 22:06:21 +00:00
|
|
|
#include "core/mime_type.h"
|
2019-09-19 09:28:36 +00:00
|
|
|
#include "base/event_filter.h"
|
2022-11-30 12:55:51 +00:00
|
|
|
#include "base/call_delayed.h"
|
2022-05-11 09:59:38 +00:00
|
|
|
#include "boxes/premium_limits_box.h"
|
2022-09-14 10:45:23 +00:00
|
|
|
#include "boxes/premium_preview_box.h"
|
2022-04-13 10:22:10 +00:00
|
|
|
#include "ui/effects/scroll_content_shadow.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
2023-08-31 11:21:24 +00:00
|
|
|
#include "ui/widgets/fields/input_field.h"
|
2017-12-22 17:42:33 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2022-12-16 08:36:50 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2020-10-16 07:52:55 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2020-10-13 12:07:53 +00:00
|
|
|
#include "ui/chat/attach/attach_prepare.h"
|
2020-10-15 14:27:16 +00:00
|
|
|
#include "ui/chat/attach/attach_send_files_way.h"
|
2020-10-13 15:11:53 +00:00
|
|
|
#include "ui/chat/attach/attach_album_preview.h"
|
|
|
|
#include "ui/chat/attach/attach_single_file_preview.h"
|
2020-10-13 17:15:52 +00:00
|
|
|
#include "ui/chat/attach/attach_single_media_preview.h"
|
2017-12-19 16:57:42 +00:00
|
|
|
#include "ui/grouped_layout.h"
|
2020-10-16 14:11:23 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2020-10-13 10:00:35 +00:00
|
|
|
#include "ui/controls/emoji_button.h"
|
2022-09-16 20:23:27 +00:00
|
|
|
#include "ui/painter.h"
|
2019-07-03 11:03:01 +00:00
|
|
|
#include "lottie/lottie_single_player.h"
|
2018-12-18 10:45:06 +00:00
|
|
|
#include "data/data_document.h"
|
2022-05-10 14:22:28 +00:00
|
|
|
#include "data/data_user.h"
|
2022-06-15 22:24:10 +00:00
|
|
|
#include "data/data_premium_limits.h"
|
2022-09-14 10:45:23 +00:00
|
|
|
#include "data/stickers/data_stickers.h"
|
2022-07-25 10:34:18 +00:00
|
|
|
#include "data/stickers/data_custom_emoji.h"
|
2019-08-12 12:11:34 +00:00
|
|
|
#include "api/api_common.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/core_settings.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2017-12-22 17:42:33 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2018-11-22 12:48:50 +00:00
|
|
|
#include "styles/style_chat_helpers.h"
|
2022-12-16 08:36:50 +00:00
|
|
|
#include "styles/style_menu_icons.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtCore/QMimeData>
|
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
namespace {
|
|
|
|
|
2022-05-11 09:59:38 +00:00
|
|
|
constexpr auto kMaxMessageLength = 4096;
|
|
|
|
|
2020-10-13 15:11:53 +00:00
|
|
|
using Ui::SendFilesWay;
|
2020-01-09 13:16:49 +00:00
|
|
|
|
2023-08-28 18:24:09 +00:00
|
|
|
[[nodiscard]] inline bool CanAddUrls(const QList<QUrl> &urls) {
|
2020-05-18 19:33:14 +00:00
|
|
|
return !urls.isEmpty() && ranges::all_of(urls, &QUrl::isLocalFile);
|
2020-01-05 20:45:15 +00:00
|
|
|
}
|
|
|
|
|
2023-08-28 18:24:09 +00:00
|
|
|
[[nodiscard]] bool CanAddFiles(not_null<const QMimeData*> data) {
|
|
|
|
return data->hasImage() || CanAddUrls(Core::ReadMimeUrls(data));
|
|
|
|
}
|
|
|
|
|
2020-01-05 21:04:47 +00:00
|
|
|
void FileDialogCallback(
|
2020-10-16 14:11:23 +00:00
|
|
|
FileDialog::OpenResult &&result,
|
|
|
|
Fn<bool(const Ui::PreparedList&)> checkResult,
|
2022-05-10 14:22:28 +00:00
|
|
|
Fn<void(Ui::PreparedList)> callback,
|
2022-06-14 09:48:25 +00:00
|
|
|
bool premium,
|
2023-05-02 09:33:19 +00:00
|
|
|
std::shared_ptr<Ui::Show> show) {
|
2022-06-14 09:48:25 +00:00
|
|
|
auto showError = [=](tr::phrase<> text) {
|
2023-05-02 09:33:19 +00:00
|
|
|
show->showToast(text(tr::now));
|
2020-01-05 21:04:47 +00:00
|
|
|
};
|
|
|
|
|
2020-10-13 12:07:53 +00:00
|
|
|
auto list = Storage::PreparedFileFromFilesDialog(
|
2020-01-05 21:04:47 +00:00
|
|
|
std::move(result),
|
2020-10-16 14:11:23 +00:00
|
|
|
checkResult,
|
|
|
|
showError,
|
2022-05-10 14:22:28 +00:00
|
|
|
st::sendMediaPreviewSize,
|
|
|
|
premium);
|
2020-01-05 21:04:47 +00:00
|
|
|
|
|
|
|
if (!list) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(std::move(*list));
|
|
|
|
}
|
|
|
|
|
2019-06-18 14:07:45 +00:00
|
|
|
rpl::producer<QString> FieldPlaceholder(
|
2020-10-13 12:07:53 +00:00
|
|
|
const Ui::PreparedList &list,
|
2018-12-26 06:47:03 +00:00
|
|
|
SendFilesWay way) {
|
2022-11-10 15:34:37 +00:00
|
|
|
return list.canAddCaption(
|
|
|
|
way.groupFiles() && way.sendImagesAsPhotos(),
|
|
|
|
way.sendImagesAsPhotos())
|
2019-06-18 14:07:45 +00:00
|
|
|
? tr::lng_photo_caption()
|
|
|
|
: tr::lng_photos_comment();
|
2017-12-22 17:42:33 +00:00
|
|
|
}
|
2015-12-28 15:58:38 +00:00
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
} // namespace
|
2014-08-22 09:35:22 +00:00
|
|
|
|
2023-01-10 18:56:20 +00:00
|
|
|
SendFilesLimits DefaultLimitsForPeer(not_null<PeerData*> peer) {
|
|
|
|
using Flag = SendFilesAllow;
|
|
|
|
using Restriction = ChatRestriction;
|
|
|
|
const auto allowByRestriction = [&](Restriction check, Flag allow) {
|
|
|
|
return Data::RestrictionError(peer, check) ? Flag() : allow;
|
|
|
|
};
|
|
|
|
return Flag()
|
|
|
|
| (peer->slowmodeApplied() ? Flag::OnlyOne : Flag())
|
|
|
|
| (Data::AllowEmojiWithoutPremium(peer)
|
|
|
|
? Flag::EmojiWithoutPremium
|
|
|
|
: Flag())
|
|
|
|
| allowByRestriction(Restriction::SendPhotos, Flag::Photos)
|
|
|
|
| allowByRestriction(Restriction::SendVideos, Flag::Videos)
|
|
|
|
| allowByRestriction(Restriction::SendMusic, Flag::Music)
|
|
|
|
| allowByRestriction(Restriction::SendFiles, Flag::Files)
|
|
|
|
| allowByRestriction(Restriction::SendStickers, Flag::Stickers)
|
|
|
|
| allowByRestriction(Restriction::SendGifs, Flag::Gifs)
|
|
|
|
| allowByRestriction(Restriction::SendOther, Flag::Texts);
|
|
|
|
}
|
|
|
|
|
|
|
|
SendFilesCheck DefaultCheckForPeer(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<PeerData*> peer) {
|
2023-05-18 13:46:24 +00:00
|
|
|
return DefaultCheckForPeer(controller->uiShow(), peer);
|
|
|
|
}
|
|
|
|
|
|
|
|
SendFilesCheck DefaultCheckForPeer(
|
|
|
|
std::shared_ptr<Ui::Show> show,
|
|
|
|
not_null<PeerData*> peer) {
|
2023-01-10 18:56:20 +00:00
|
|
|
return [=](
|
|
|
|
const Ui::PreparedFile &file,
|
|
|
|
bool compress,
|
|
|
|
bool silent) {
|
|
|
|
const auto error = Data::FileRestrictionError(peer, file, compress);
|
|
|
|
if (error && !silent) {
|
2023-05-18 13:46:24 +00:00
|
|
|
show->showToast(*error);
|
2023-01-10 18:56:20 +00:00
|
|
|
}
|
|
|
|
return !error.has_value();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-16 10:38:12 +00:00
|
|
|
SendFilesBox::Block::Block(
|
|
|
|
not_null<QWidget*> parent,
|
2023-05-18 13:46:24 +00:00
|
|
|
const style::ComposeControls &st,
|
2020-10-16 10:38:12 +00:00
|
|
|
not_null<std::vector<Ui::PreparedFile>*> items,
|
|
|
|
int from,
|
|
|
|
int till,
|
|
|
|
Fn<bool()> gifPaused,
|
|
|
|
SendFilesWay way)
|
|
|
|
: _items(items)
|
|
|
|
, _from(from)
|
|
|
|
, _till(till) {
|
|
|
|
Expects(from >= 0);
|
|
|
|
Expects(till > from);
|
|
|
|
Expects(till <= items->size());
|
|
|
|
|
|
|
|
const auto count = till - from;
|
|
|
|
const auto my = gsl::make_span(*items).subspan(from, count);
|
|
|
|
const auto &first = my.front();
|
2020-10-19 10:25:28 +00:00
|
|
|
_isAlbum = (my.size() > 1);
|
2020-10-16 10:38:12 +00:00
|
|
|
if (_isAlbum) {
|
|
|
|
const auto preview = Ui::CreateChild<Ui::AlbumPreview>(
|
|
|
|
parent.get(),
|
2023-05-18 13:46:24 +00:00
|
|
|
st,
|
2020-10-16 10:38:12 +00:00
|
|
|
my,
|
|
|
|
way);
|
|
|
|
_preview.reset(preview);
|
|
|
|
} else {
|
|
|
|
const auto media = Ui::SingleMediaPreview::Create(
|
|
|
|
parent,
|
2023-05-18 13:46:24 +00:00
|
|
|
st,
|
2020-10-16 10:38:12 +00:00
|
|
|
gifPaused,
|
|
|
|
first);
|
|
|
|
if (media) {
|
2020-10-19 08:49:31 +00:00
|
|
|
_isSingleMedia = true;
|
2020-10-16 10:38:12 +00:00
|
|
|
_preview.reset(media);
|
|
|
|
} else {
|
2023-05-18 13:46:24 +00:00
|
|
|
_preview.reset(Ui::CreateChild<Ui::SingleFilePreview>(
|
|
|
|
parent.get(),
|
|
|
|
st,
|
|
|
|
first));
|
2020-10-16 10:38:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_preview->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
int SendFilesBox::Block::fromIndex() const {
|
|
|
|
return _from;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SendFilesBox::Block::tillIndex() const {
|
|
|
|
return _till;
|
|
|
|
}
|
|
|
|
|
|
|
|
object_ptr<Ui::RpWidget> SendFilesBox::Block::takeWidget() {
|
|
|
|
return object_ptr<Ui::RpWidget>::fromRaw(_preview.get());
|
|
|
|
}
|
|
|
|
|
2020-10-17 17:09:06 +00:00
|
|
|
rpl::producer<int> SendFilesBox::Block::itemDeleteRequest() const {
|
2020-10-19 08:49:31 +00:00
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
|
|
|
const auto preview = _preview.get();
|
2020-10-20 18:20:56 +00:00
|
|
|
const auto from = _from;
|
2020-10-19 08:49:31 +00:00
|
|
|
if (_isAlbum) {
|
|
|
|
const auto album = static_cast<Ui::AlbumPreview*>(_preview.get());
|
2020-10-20 18:20:56 +00:00
|
|
|
return album->thumbDeleted() | rpl::map(_1 + from);
|
2020-10-19 08:49:31 +00:00
|
|
|
} else if (_isSingleMedia) {
|
|
|
|
const auto media = static_cast<Ui::SingleMediaPreview*>(preview);
|
2020-10-20 18:20:56 +00:00
|
|
|
return media->deleteRequests() | rpl::map([from] { return from; });
|
2020-10-19 08:49:31 +00:00
|
|
|
} else {
|
|
|
|
const auto single = static_cast<Ui::SingleFilePreview*>(preview);
|
2020-10-20 18:20:56 +00:00
|
|
|
return single->deleteRequests() | rpl::map([from] { return from; });
|
2020-10-17 17:09:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<int> SendFilesBox::Block::itemReplaceRequest() const {
|
2020-10-19 08:49:31 +00:00
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
|
|
|
const auto preview = _preview.get();
|
2020-10-20 18:20:56 +00:00
|
|
|
const auto from = _from;
|
2020-10-19 08:49:31 +00:00
|
|
|
if (_isAlbum) {
|
|
|
|
const auto album = static_cast<Ui::AlbumPreview*>(preview);
|
2020-10-20 18:20:56 +00:00
|
|
|
return album->thumbChanged() | rpl::map(_1 + from);
|
2020-10-19 08:49:31 +00:00
|
|
|
} else if (_isSingleMedia) {
|
|
|
|
const auto media = static_cast<Ui::SingleMediaPreview*>(preview);
|
2020-10-20 18:20:56 +00:00
|
|
|
return media->editRequests() | rpl::map([from] { return from; });
|
2020-10-19 08:49:31 +00:00
|
|
|
} else {
|
|
|
|
const auto single = static_cast<Ui::SingleFilePreview*>(preview);
|
2020-10-20 18:20:56 +00:00
|
|
|
return single->editRequests() | rpl::map([from] { return from; });
|
2020-10-17 17:09:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-20 03:30:14 +00:00
|
|
|
rpl::producer<int> SendFilesBox::Block::itemModifyRequest() const {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
|
|
|
const auto preview = _preview.get();
|
|
|
|
const auto from = _from;
|
|
|
|
if (_isAlbum) {
|
|
|
|
const auto album = static_cast<Ui::AlbumPreview*>(preview);
|
|
|
|
return album->thumbModified() | rpl::map(_1 + from);
|
|
|
|
} else if (_isSingleMedia) {
|
|
|
|
const auto media = static_cast<Ui::SingleMediaPreview*>(preview);
|
|
|
|
return media->modifyRequests() | rpl::map_to(from);
|
|
|
|
} else {
|
|
|
|
return rpl::never<int>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-16 10:38:12 +00:00
|
|
|
void SendFilesBox::Block::setSendWay(Ui::SendFilesWay way) {
|
|
|
|
if (!_isAlbum) {
|
2022-12-13 12:11:52 +00:00
|
|
|
if (_isSingleMedia) {
|
|
|
|
const auto media = static_cast<Ui::SingleMediaPreview*>(
|
|
|
|
_preview.get());
|
|
|
|
media->setSendWay(way);
|
|
|
|
}
|
2020-10-16 10:38:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-12-13 12:11:52 +00:00
|
|
|
applyChanges();
|
2020-10-16 10:38:12 +00:00
|
|
|
const auto album = static_cast<Ui::AlbumPreview*>(_preview.get());
|
|
|
|
album->setSendWay(way);
|
|
|
|
}
|
|
|
|
|
2022-12-16 08:36:50 +00:00
|
|
|
void SendFilesBox::Block::toggleSpoilers(bool enabled) {
|
|
|
|
if (_isAlbum) {
|
|
|
|
const auto album = static_cast<Ui::AlbumPreview*>(_preview.get());
|
|
|
|
album->toggleSpoilers(enabled);
|
|
|
|
} else if (_isSingleMedia) {
|
|
|
|
const auto media = static_cast<Ui::SingleMediaPreview*>(
|
|
|
|
_preview.get());
|
|
|
|
media->setSpoiler(enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-13 12:11:52 +00:00
|
|
|
void SendFilesBox::Block::applyChanges() {
|
2020-10-16 10:38:12 +00:00
|
|
|
if (!_isAlbum) {
|
2022-12-13 12:11:52 +00:00
|
|
|
if (_isSingleMedia) {
|
|
|
|
const auto media = static_cast<Ui::SingleMediaPreview*>(
|
|
|
|
_preview.get());
|
2022-12-13 13:31:54 +00:00
|
|
|
if (media->canHaveSpoiler()) {
|
|
|
|
(*_items)[_from].spoiler = media->hasSpoiler();
|
|
|
|
}
|
2022-12-13 12:11:52 +00:00
|
|
|
}
|
2020-10-16 10:38:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto album = static_cast<Ui::AlbumPreview*>(_preview.get());
|
|
|
|
const auto order = album->takeOrder();
|
2022-12-13 12:11:52 +00:00
|
|
|
const auto guard = gsl::finally([&] {
|
2022-12-13 13:31:54 +00:00
|
|
|
const auto spoilered = album->collectSpoileredIndices();
|
2022-12-13 12:11:52 +00:00
|
|
|
for (auto i = 0, count = int(order.size()); i != count; ++i) {
|
2022-12-13 13:31:54 +00:00
|
|
|
if (album->canHaveSpoiler(i)) {
|
|
|
|
(*_items)[_from + i].spoiler = spoilered.contains(i);
|
|
|
|
}
|
2022-12-13 12:11:52 +00:00
|
|
|
}
|
|
|
|
});
|
2020-10-16 10:38:12 +00:00
|
|
|
const auto isIdentity = [&] {
|
|
|
|
for (auto i = 0, count = int(order.size()); i != count; ++i) {
|
|
|
|
if (order[i] != i) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}();
|
|
|
|
if (isIdentity) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto elements = std::vector<Ui::PreparedFile>();
|
|
|
|
elements.reserve(order.size());
|
|
|
|
for (const auto index : order) {
|
|
|
|
elements.push_back(std::move((*_items)[_from + index]));
|
|
|
|
}
|
|
|
|
for (auto i = 0, count = int(order.size()); i != count; ++i) {
|
|
|
|
(*_items)[_from + i] = std::move(elements[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
SendFilesBox::SendFilesBox(
|
|
|
|
QWidget*,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2020-10-13 12:07:53 +00:00
|
|
|
Ui::PreparedList &&list,
|
2018-05-24 14:57:41 +00:00
|
|
|
const TextWithTags &caption,
|
2023-01-10 18:56:20 +00:00
|
|
|
SendFilesLimits limits,
|
|
|
|
SendFilesCheck check,
|
2019-08-28 16:46:47 +00:00
|
|
|
Api::SendType sendType,
|
2020-08-10 12:22:54 +00:00
|
|
|
SendMenu::Type sendMenuType)
|
2023-05-18 13:46:24 +00:00
|
|
|
: SendFilesBox(nullptr, {
|
|
|
|
.show = controller->uiShow(),
|
|
|
|
.list = std::move(list),
|
|
|
|
.caption = caption,
|
|
|
|
.limits = limits,
|
|
|
|
.check = check,
|
|
|
|
.sendType = sendType,
|
|
|
|
.sendMenuType = sendMenuType,
|
|
|
|
}) {
|
|
|
|
}
|
|
|
|
|
|
|
|
SendFilesBox::SendFilesBox(QWidget*, SendFilesBoxDescriptor &&descriptor)
|
|
|
|
: _show(std::move(descriptor.show))
|
|
|
|
, _st(descriptor.stOverride
|
|
|
|
? *descriptor.stOverride
|
|
|
|
: st::defaultComposeControls)
|
|
|
|
, _sendType(descriptor.sendType)
|
2020-10-19 10:02:39 +00:00
|
|
|
, _titleHeight(st::boxTitleHeight)
|
2023-05-18 13:46:24 +00:00
|
|
|
, _list(std::move(descriptor.list))
|
|
|
|
, _limits(descriptor.limits)
|
|
|
|
, _sendMenuType(descriptor.sendMenuType)
|
|
|
|
, _check(std::move(descriptor.check))
|
|
|
|
, _confirmedCallback(std::move(descriptor.confirmed))
|
|
|
|
, _cancelledCallback(std::move(descriptor.cancelled))
|
|
|
|
, _caption(this, _st.files.caption, Ui::InputField::Mode::MultiLine)
|
|
|
|
, _prefilledCaptionText(std::move(descriptor.caption))
|
2020-10-16 07:52:55 +00:00
|
|
|
, _scroll(this, st::boxScroll)
|
|
|
|
, _inner(
|
|
|
|
_scroll->setOwnedWidget(
|
|
|
|
object_ptr<Ui::VerticalLayout>(_scroll.data()))) {
|
2020-10-16 14:11:23 +00:00
|
|
|
enqueueNextPrepare();
|
2017-12-22 17:42:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 07:52:55 +00:00
|
|
|
void SendFilesBox::initPreview() {
|
2020-10-15 14:27:16 +00:00
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
2022-12-16 08:36:50 +00:00
|
|
|
refreshControls(true);
|
2017-12-22 17:42:33 +00:00
|
|
|
|
|
|
|
updateBoxSize();
|
|
|
|
|
2020-10-15 14:27:16 +00:00
|
|
|
_dimensionsLifetime.destroy();
|
2020-10-16 07:52:55 +00:00
|
|
|
_inner->resizeToWidth(st::boxWideWidth);
|
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
rpl::combine(
|
2020-10-16 07:52:55 +00:00
|
|
|
_inner->heightValue(),
|
2017-12-22 17:42:33 +00:00
|
|
|
_footerHeight.value(),
|
2020-10-19 10:02:39 +00:00
|
|
|
_titleHeight.value(),
|
|
|
|
_1 + _2 + _3
|
2019-01-14 06:28:20 +00:00
|
|
|
) | rpl::start_with_next([=](int height) {
|
2017-12-22 17:42:33 +00:00
|
|
|
setDimensions(
|
|
|
|
st::boxWideWidth,
|
2020-01-03 21:49:35 +00:00
|
|
|
std::min(st::sendMediaPreviewHeightMax, height),
|
|
|
|
true);
|
2020-10-15 14:27:16 +00:00
|
|
|
}, _dimensionsLifetime);
|
2017-12-22 17:42:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 14:11:23 +00:00
|
|
|
void SendFilesBox::enqueueNextPrepare() {
|
|
|
|
if (_preparing) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (!_list.filesToProcess.empty()
|
|
|
|
&& _list.filesToProcess.front().information) {
|
2020-11-19 12:37:23 +00:00
|
|
|
auto file = std::move(_list.filesToProcess.front());
|
2020-10-16 14:11:23 +00:00
|
|
|
_list.filesToProcess.pop_front();
|
2020-11-19 12:37:23 +00:00
|
|
|
addFile(std::move(file));
|
2020-10-16 14:11:23 +00:00
|
|
|
}
|
|
|
|
if (_list.filesToProcess.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto file = std::move(_list.filesToProcess.front());
|
|
|
|
_list.filesToProcess.pop_front();
|
|
|
|
const auto weak = Ui::MakeWeak(this);
|
|
|
|
_preparing = true;
|
2023-01-02 10:25:44 +00:00
|
|
|
const auto sideLimit = PhotoSideLimit(); // Get on main thread.
|
|
|
|
crl::async([weak, sideLimit, file = std::move(file)]() mutable {
|
|
|
|
Storage::PrepareDetails(file, st::sendMediaPreviewSize, sideLimit);
|
2020-10-16 14:11:23 +00:00
|
|
|
crl::on_main([weak, file = std::move(file)]() mutable {
|
|
|
|
if (weak) {
|
|
|
|
weak->addPreparedAsyncFile(std::move(file));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
void SendFilesBox::prepare() {
|
|
|
|
initSendWay();
|
2018-12-26 06:47:03 +00:00
|
|
|
setupCaption();
|
2020-10-15 14:27:16 +00:00
|
|
|
setupSendWayControls();
|
2017-12-29 17:02:23 +00:00
|
|
|
preparePreview();
|
2020-10-16 07:52:55 +00:00
|
|
|
initPreview();
|
2022-04-13 10:22:10 +00:00
|
|
|
SetupShadowsToScrollContent(this, _scroll, _inner->heightValue());
|
2020-10-15 14:27:16 +00:00
|
|
|
|
2018-03-29 19:49:31 +00:00
|
|
|
boxClosing() | rpl::start_with_next([=] {
|
2017-12-22 17:42:33 +00:00
|
|
|
if (!_confirmed && _cancelledCallback) {
|
|
|
|
_cancelledCallback();
|
|
|
|
}
|
2018-03-29 19:49:31 +00:00
|
|
|
}, lifetime());
|
2020-01-05 21:04:47 +00:00
|
|
|
|
2020-06-13 14:13:56 +00:00
|
|
|
setupDragArea();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::setupDragArea() {
|
|
|
|
// Avoid both drag areas appearing at one time.
|
|
|
|
auto computeState = [=](const QMimeData *data) {
|
2020-07-30 07:50:12 +00:00
|
|
|
using DragState = Storage::MimeDataState;
|
2020-06-13 14:13:56 +00:00
|
|
|
const auto state = Storage::ComputeMimeDataState(data);
|
2023-08-30 17:49:22 +00:00
|
|
|
return (state == DragState::PhotoFiles || state == DragState::Image)
|
|
|
|
? (_sendWay.current().sendImagesAsPhotos()
|
|
|
|
? DragState::Image
|
|
|
|
: DragState::Files)
|
2020-06-13 14:13:56 +00:00
|
|
|
: state;
|
|
|
|
};
|
|
|
|
const auto areas = DragArea::SetupDragAreaToContainer(
|
|
|
|
this,
|
2023-08-28 18:24:09 +00:00
|
|
|
CanAddFiles,
|
2020-06-13 14:13:56 +00:00
|
|
|
[=](bool f) { _caption->setAcceptDrops(f); },
|
|
|
|
[=] { updateControlsGeometry(); },
|
|
|
|
std::move(computeState));
|
|
|
|
|
|
|
|
const auto droppedCallback = [=](bool compress) {
|
|
|
|
return [=](const QMimeData *data) {
|
|
|
|
addFiles(data);
|
2023-05-18 13:46:24 +00:00
|
|
|
_show->activate();
|
2020-06-13 14:13:56 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
areas.document->setDroppedCallback(droppedCallback(false));
|
|
|
|
areas.photo->setDroppedCallback(droppedCallback(true));
|
2020-01-05 21:04:47 +00:00
|
|
|
}
|
|
|
|
|
2022-12-13 12:11:52 +00:00
|
|
|
void SendFilesBox::refreshAllAfterChanges(int fromItem, Fn<void()> perform) {
|
2020-10-16 14:11:23 +00:00
|
|
|
auto fromBlock = 0;
|
|
|
|
for (auto count = int(_blocks.size()); fromBlock != count; ++fromBlock) {
|
|
|
|
if (_blocks[fromBlock].tillIndex() >= fromItem) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-12-13 12:11:52 +00:00
|
|
|
for (auto index = fromBlock; index < _blocks.size(); ++index) {
|
|
|
|
_blocks[index].applyChanges();
|
|
|
|
}
|
|
|
|
if (perform) {
|
|
|
|
perform();
|
|
|
|
}
|
|
|
|
generatePreviewFrom(fromBlock);
|
2022-11-10 15:34:37 +00:00
|
|
|
{
|
|
|
|
auto sendWay = _sendWay.current();
|
|
|
|
sendWay.setHasCompressedStickers(_list.hasSticker());
|
2023-01-10 18:56:20 +00:00
|
|
|
if (_limits & SendFilesAllow::OnlyOne) {
|
|
|
|
if (_list.files.size() > 1) {
|
|
|
|
sendWay.setGroupFiles(true);
|
|
|
|
}
|
|
|
|
}
|
2022-11-10 15:34:37 +00:00
|
|
|
_sendWay = sendWay;
|
|
|
|
}
|
2020-10-16 14:11:23 +00:00
|
|
|
_inner->resizeToWidth(st::boxWideWidth);
|
|
|
|
refreshControls();
|
2020-01-05 21:04:47 +00:00
|
|
|
captionResized();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::openDialogToAddFileToAlbum() {
|
2023-05-02 09:33:19 +00:00
|
|
|
const auto show = uiShow();
|
2020-10-16 14:11:23 +00:00
|
|
|
const auto checkResult = [=](const Ui::PreparedList &list) {
|
2023-01-10 18:56:20 +00:00
|
|
|
if (!(_limits & SendFilesAllow::OnlyOne)) {
|
2020-10-16 14:11:23 +00:00
|
|
|
return true;
|
|
|
|
} else if (!_list.canBeSentInSlowmodeWith(list)) {
|
2023-05-02 09:33:19 +00:00
|
|
|
showToast(tr::lng_slowmode_no_many(tr::now));
|
2020-10-16 14:11:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2020-01-05 21:04:47 +00:00
|
|
|
const auto callback = [=](FileDialog::OpenResult &&result) {
|
2023-05-18 13:46:24 +00:00
|
|
|
const auto premium = _show->session().premium();
|
2020-01-05 21:04:47 +00:00
|
|
|
FileDialogCallback(
|
|
|
|
std::move(result),
|
2020-10-16 14:11:23 +00:00
|
|
|
checkResult,
|
2022-05-10 14:22:28 +00:00
|
|
|
[=](Ui::PreparedList list) { addFiles(std::move(list)); },
|
2022-06-14 09:48:25 +00:00
|
|
|
premium,
|
2023-05-02 09:33:19 +00:00
|
|
|
show);
|
2020-01-05 21:04:47 +00:00
|
|
|
};
|
|
|
|
|
2020-01-21 20:31:34 +00:00
|
|
|
FileDialog::GetOpenPaths(
|
2020-01-05 21:04:47 +00:00
|
|
|
this,
|
|
|
|
tr::lng_choose_file(tr::now),
|
2020-10-16 14:11:23 +00:00
|
|
|
FileDialog::AllOrImagesFilter(),
|
2020-01-05 21:04:47 +00:00
|
|
|
crl::guard(this, callback));
|
2017-12-22 17:42:33 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 08:36:50 +00:00
|
|
|
void SendFilesBox::refreshButtons() {
|
|
|
|
clearButtons();
|
|
|
|
|
|
|
|
_send = addButton(
|
|
|
|
(_sendType == Api::SendType::Normal
|
|
|
|
? tr::lng_send_button()
|
|
|
|
: tr::lng_create_group_next()),
|
|
|
|
[=] { send({}); });
|
|
|
|
if (_sendType == Api::SendType::Normal) {
|
|
|
|
SendMenu::SetupMenuAndShortcuts(
|
|
|
|
_send,
|
|
|
|
[=] { return _sendMenuType; },
|
|
|
|
[=] { sendSilent(); },
|
2023-04-22 18:26:09 +00:00
|
|
|
[=] { sendScheduled(); },
|
|
|
|
[=] { sendWhenOnline(); });
|
2022-12-16 08:36:50 +00:00
|
|
|
}
|
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
|
|
|
_addFile = addLeftButton(
|
|
|
|
tr::lng_stickers_featured_add(),
|
|
|
|
base::fn_delayed(st::historyAttach.ripple.hideDuration, this, [=] {
|
|
|
|
openDialogToAddFileToAlbum();
|
|
|
|
}));
|
|
|
|
|
|
|
|
addMenuButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SendFilesBox::hasSendMenu() const {
|
|
|
|
return (_sendMenuType != SendMenu::Type::Disabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SendFilesBox::hasSpoilerMenu() const {
|
|
|
|
const auto allAreVideo = !ranges::any_of(_list.files, [](const auto &f) {
|
|
|
|
using Type = Ui::PreparedFile::Type;
|
|
|
|
return (f.type != Type::Video);
|
|
|
|
});
|
|
|
|
const auto allAreMedia = !ranges::any_of(_list.files, [](const auto &f) {
|
|
|
|
using Type = Ui::PreparedFile::Type;
|
|
|
|
return (f.type != Type::Photo) && (f.type != Type::Video);
|
|
|
|
});
|
|
|
|
return allAreVideo
|
|
|
|
|| (allAreMedia && _sendWay.current().sendImagesAsPhotos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::applyBlockChanges() {
|
|
|
|
for (auto &block : _blocks) {
|
|
|
|
block.applyChanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SendFilesBox::allWithSpoilers() {
|
|
|
|
applyBlockChanges();
|
|
|
|
return ranges::all_of(_list.files, &Ui::PreparedFile::spoiler);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::toggleSpoilers(bool enabled) {
|
|
|
|
for (auto &file : _list.files) {
|
|
|
|
file.spoiler = enabled;
|
|
|
|
}
|
|
|
|
for (auto &block : _blocks) {
|
|
|
|
block.toggleSpoilers(enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::addMenuButton() {
|
|
|
|
if (!hasSendMenu() && !hasSpoilerMenu()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-18 13:46:24 +00:00
|
|
|
const auto top = addTopButton(_st.files.menu);
|
2022-12-16 08:36:50 +00:00
|
|
|
top->setClickedCallback([=] {
|
2023-05-18 13:46:24 +00:00
|
|
|
const auto &tabbed = _st.tabbed;
|
|
|
|
const auto &icons = tabbed.icons;
|
|
|
|
_menu = base::make_unique_q<Ui::PopupMenu>(top, tabbed.menu);
|
2022-12-16 08:36:50 +00:00
|
|
|
if (hasSpoilerMenu()) {
|
|
|
|
const auto spoilered = allWithSpoilers();
|
|
|
|
_menu->addAction(
|
|
|
|
(spoilered
|
|
|
|
? tr::lng_context_disable_spoiler(tr::now)
|
|
|
|
: tr::lng_context_spoiler_effect(tr::now)),
|
|
|
|
[=] { toggleSpoilers(!spoilered); },
|
2023-05-18 13:46:24 +00:00
|
|
|
spoilered ? &icons.menuSpoilerOff : &icons.menuSpoiler);
|
2022-12-16 08:36:50 +00:00
|
|
|
if (hasSendMenu()) {
|
2023-05-18 13:46:24 +00:00
|
|
|
_menu->addSeparator(&tabbed.expandedSeparator);
|
2022-12-16 08:36:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasSendMenu()) {
|
|
|
|
SendMenu::FillSendMenu(
|
|
|
|
_menu.get(),
|
|
|
|
_sendMenuType,
|
|
|
|
[=] { sendSilent(); },
|
2023-04-22 18:26:09 +00:00
|
|
|
[=] { sendScheduled(); },
|
2023-05-18 13:46:24 +00:00
|
|
|
[=] { sendWhenOnline(); },
|
|
|
|
&_st.tabbed.icons);
|
2022-12-16 08:36:50 +00:00
|
|
|
}
|
|
|
|
_menu->popup(QCursor::pos());
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
void SendFilesBox::initSendWay() {
|
2020-10-15 14:27:16 +00:00
|
|
|
_sendWay = [&] {
|
|
|
|
auto result = Core::App().settings().sendFilesWay();
|
2022-11-10 15:34:37 +00:00
|
|
|
result.setHasCompressedStickers(_list.hasSticker());
|
2023-01-10 18:56:20 +00:00
|
|
|
if ((_limits & SendFilesAllow::OnlyOne)
|
|
|
|
&& (_list.files.size() > 1)) {
|
2020-10-15 14:27:16 +00:00
|
|
|
result.setGroupFiles(true);
|
2023-01-10 18:56:20 +00:00
|
|
|
}
|
|
|
|
if (_list.overrideSendImagesAsPhotos == false) {
|
|
|
|
if (!(_limits & SendFilesAllow::OnlyOne)
|
|
|
|
|| !_list.hasSticker()) {
|
|
|
|
result.setSendImagesAsPhotos(false);
|
|
|
|
}
|
2020-10-15 14:27:16 +00:00
|
|
|
return result;
|
|
|
|
} else if (_list.overrideSendImagesAsPhotos == true) {
|
|
|
|
result.setSendImagesAsPhotos(true);
|
2023-01-10 18:56:20 +00:00
|
|
|
const auto silent = true;
|
|
|
|
if (!checkWithWay(result, silent)) {
|
|
|
|
result.setSendImagesAsPhotos(false);
|
|
|
|
}
|
2020-10-15 14:27:16 +00:00
|
|
|
return result;
|
2017-12-25 11:13:27 +00:00
|
|
|
}
|
2023-01-10 18:56:20 +00:00
|
|
|
const auto silent = true;
|
|
|
|
if (!checkWithWay(result, silent)) {
|
|
|
|
result.setSendImagesAsPhotos(!result.sendImagesAsPhotos());
|
|
|
|
}
|
2020-10-15 14:27:16 +00:00
|
|
|
return result;
|
2017-12-25 11:13:27 +00:00
|
|
|
}();
|
2020-10-15 14:27:16 +00:00
|
|
|
_sendWay.changes(
|
|
|
|
) | rpl::start_with_next([=](SendFilesWay value) {
|
2023-01-10 18:56:20 +00:00
|
|
|
const auto hidden = [&] {
|
|
|
|
return !_caption || _caption->isHidden();
|
|
|
|
};
|
|
|
|
const auto was = hidden();
|
2018-12-26 06:47:03 +00:00
|
|
|
updateCaptionPlaceholder();
|
2020-05-01 12:05:24 +00:00
|
|
|
updateEmojiPanelGeometry();
|
2020-10-16 10:38:12 +00:00
|
|
|
for (auto &block : _blocks) {
|
|
|
|
block.setSendWay(value);
|
|
|
|
}
|
2022-12-16 08:36:50 +00:00
|
|
|
if (!hasSendMenu()) {
|
|
|
|
refreshButtons();
|
|
|
|
}
|
2023-01-10 18:56:20 +00:00
|
|
|
if (was != hidden()) {
|
|
|
|
updateBoxSize();
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
2017-12-29 17:02:23 +00:00
|
|
|
setInnerFocus();
|
2020-10-15 14:27:16 +00:00
|
|
|
}, lifetime());
|
2017-12-29 17:02:23 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 06:47:03 +00:00
|
|
|
void SendFilesBox::updateCaptionPlaceholder() {
|
2019-07-17 10:37:42 +00:00
|
|
|
if (!_caption) {
|
|
|
|
return;
|
|
|
|
}
|
2020-10-17 09:51:55 +00:00
|
|
|
const auto way = _sendWay.current();
|
2022-11-10 15:34:37 +00:00
|
|
|
if (!_list.canAddCaption(
|
|
|
|
way.groupFiles() && way.sendImagesAsPhotos(),
|
|
|
|
way.sendImagesAsPhotos())
|
2023-01-10 18:56:20 +00:00
|
|
|
&& ((_limits & SendFilesAllow::OnlyOne)
|
|
|
|
|| !(_limits & SendFilesAllow::Texts))) {
|
2019-07-17 10:37:42 +00:00
|
|
|
_caption->hide();
|
|
|
|
if (_emojiToggle) {
|
|
|
|
_emojiToggle->hide();
|
|
|
|
}
|
|
|
|
} else {
|
2020-10-17 09:51:55 +00:00
|
|
|
_caption->setPlaceholder(FieldPlaceholder(_list, way));
|
2019-07-17 10:37:42 +00:00
|
|
|
_caption->show();
|
|
|
|
if (_emojiToggle) {
|
|
|
|
_emojiToggle->show();
|
|
|
|
}
|
2019-01-14 06:28:20 +00:00
|
|
|
}
|
2018-12-26 06:47:03 +00:00
|
|
|
}
|
|
|
|
|
2017-12-29 17:02:23 +00:00
|
|
|
void SendFilesBox::preparePreview() {
|
2020-10-16 10:38:12 +00:00
|
|
|
generatePreviewFrom(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::generatePreviewFrom(int fromBlock) {
|
|
|
|
Expects(fromBlock <= _blocks.size());
|
|
|
|
|
2020-10-20 08:19:48 +00:00
|
|
|
using Type = Ui::PreparedFile::Type;
|
2020-10-16 07:52:55 +00:00
|
|
|
|
2022-12-13 12:11:52 +00:00
|
|
|
_blocks.erase(_blocks.begin() + fromBlock, _blocks.end());
|
2020-10-16 10:38:12 +00:00
|
|
|
|
|
|
|
const auto fromItem = _blocks.empty() ? 0 : _blocks.back().tillIndex();
|
|
|
|
Assert(fromItem <= _list.files.size());
|
|
|
|
|
2020-10-16 07:52:55 +00:00
|
|
|
auto albumStart = -1;
|
2020-10-16 10:38:12 +00:00
|
|
|
for (auto i = fromItem, till = int(_list.files.size()); i != till; ++i) {
|
2020-10-16 07:52:55 +00:00
|
|
|
const auto type = _list.files[i].type;
|
|
|
|
if (albumStart >= 0) {
|
|
|
|
const auto albumCount = (i - albumStart);
|
2020-10-16 10:38:12 +00:00
|
|
|
if ((type == Type::File)
|
|
|
|
|| (type == Type::None)
|
2020-10-19 10:25:28 +00:00
|
|
|
|| (type == Type::Music)
|
2020-10-16 10:38:12 +00:00
|
|
|
|| (albumCount == Ui::MaxAlbumItems())) {
|
|
|
|
pushBlock(std::exchange(albumStart, -1), i);
|
2020-10-16 07:52:55 +00:00
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-10-22 10:23:14 +00:00
|
|
|
if (type != Type::File
|
|
|
|
&& type != Type::Music
|
|
|
|
&& type != Type::None) {
|
2020-10-16 07:52:55 +00:00
|
|
|
if (albumStart < 0) {
|
|
|
|
albumStart = i;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-10-16 10:38:12 +00:00
|
|
|
pushBlock(i, i + 1);
|
2017-12-29 17:02:23 +00:00
|
|
|
}
|
2020-10-16 10:38:12 +00:00
|
|
|
if (albumStart >= 0) {
|
|
|
|
pushBlock(albumStart, _list.files.size());
|
|
|
|
}
|
2017-12-25 11:13:27 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 17:09:06 +00:00
|
|
|
void SendFilesBox::pushBlock(int from, int till) {
|
2023-05-18 13:46:24 +00:00
|
|
|
const auto gifPaused = [show = _show] {
|
|
|
|
return show->paused(Window::GifPauseReason::Layer);
|
2020-10-17 17:09:06 +00:00
|
|
|
};
|
|
|
|
_blocks.emplace_back(
|
|
|
|
_inner.data(),
|
2023-05-18 13:46:24 +00:00
|
|
|
_st,
|
2020-10-17 17:09:06 +00:00
|
|
|
&_list.files,
|
|
|
|
from,
|
|
|
|
till,
|
|
|
|
gifPaused,
|
|
|
|
_sendWay.current());
|
|
|
|
auto &block = _blocks.back();
|
2020-10-19 10:02:39 +00:00
|
|
|
const auto widget = _inner->add(
|
|
|
|
block.takeWidget(),
|
2020-10-19 15:37:59 +00:00
|
|
|
QMargins(0, _inner->count() ? st::sendMediaRowSkip : 0, 0, 0));
|
2020-10-17 17:09:06 +00:00
|
|
|
|
|
|
|
block.itemDeleteRequest(
|
|
|
|
) | rpl::filter([=] {
|
|
|
|
return !_removingIndex;
|
|
|
|
}) | rpl::start_with_next([=](int index) {
|
2023-08-16 11:23:06 +00:00
|
|
|
applyBlockChanges();
|
|
|
|
|
2020-10-19 08:49:31 +00:00
|
|
|
_removingIndex = index;
|
2020-10-17 17:09:06 +00:00
|
|
|
crl::on_main(this, [=] {
|
|
|
|
const auto index = base::take(_removingIndex).value_or(-1);
|
|
|
|
if (index < 0 || index >= _list.files.size()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-19 14:36:29 +00:00
|
|
|
// Just close the box if it is the only one.
|
2020-11-05 13:51:26 +00:00
|
|
|
if (_list.files.size() == 1) {
|
2021-09-19 14:36:29 +00:00
|
|
|
closeBox();
|
2020-11-05 13:51:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-12-13 12:11:52 +00:00
|
|
|
refreshAllAfterChanges(index, [&] {
|
|
|
|
_list.files.erase(_list.files.begin() + index);
|
|
|
|
});
|
2020-10-17 17:09:06 +00:00
|
|
|
});
|
|
|
|
}, widget->lifetime());
|
|
|
|
|
2023-05-02 09:33:19 +00:00
|
|
|
const auto show = uiShow();
|
2021-09-19 14:36:29 +00:00
|
|
|
block.itemReplaceRequest(
|
2020-10-17 17:09:06 +00:00
|
|
|
) | rpl::start_with_next([=](int index) {
|
2023-08-16 11:23:06 +00:00
|
|
|
applyBlockChanges();
|
|
|
|
|
2020-10-17 17:09:06 +00:00
|
|
|
const auto replace = [=](Ui::PreparedList list) {
|
|
|
|
if (list.files.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2022-12-13 12:11:52 +00:00
|
|
|
refreshAllAfterChanges(from, [&] {
|
|
|
|
_list.files[index] = std::move(list.files.front());
|
|
|
|
});
|
2020-10-17 17:09:06 +00:00
|
|
|
};
|
2023-01-10 18:56:20 +00:00
|
|
|
const auto checkSlowmode = [=](const Ui::PreparedList &list) {
|
|
|
|
if (list.files.empty() || !(_limits & SendFilesAllow::OnlyOne)) {
|
2020-10-17 17:09:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-10-19 08:49:31 +00:00
|
|
|
auto removing = std::move(_list.files[index]);
|
|
|
|
std::swap(_list.files[index], _list.files.back());
|
2020-10-17 17:09:06 +00:00
|
|
|
_list.files.pop_back();
|
|
|
|
const auto result = _list.canBeSentInSlowmodeWith(list);
|
|
|
|
_list.files.push_back(std::move(removing));
|
2020-10-19 08:49:31 +00:00
|
|
|
std::swap(_list.files[index], _list.files.back());
|
2020-10-17 17:09:06 +00:00
|
|
|
if (!result) {
|
2023-05-02 09:33:19 +00:00
|
|
|
show->showToast(tr::lng_slowmode_no_many(tr::now));
|
2020-10-17 17:09:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2023-01-10 18:56:20 +00:00
|
|
|
const auto checkRights = [=](const Ui::PreparedList &list) {
|
|
|
|
if (list.files.empty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
auto removing = std::move(_list.files[index]);
|
|
|
|
std::swap(_list.files[index], _list.files.back());
|
|
|
|
_list.files.pop_back();
|
|
|
|
auto way = _sendWay.current();
|
|
|
|
const auto has = _list.hasSticker()
|
|
|
|
|| list.files.front().isSticker();
|
|
|
|
way.setHasCompressedStickers(has);
|
|
|
|
if (_limits & SendFilesAllow::OnlyOne) {
|
|
|
|
way.setGroupFiles(true);
|
|
|
|
}
|
|
|
|
const auto silent = true;
|
|
|
|
if (!checkWith(list, way, silent)
|
|
|
|
&& (!(_limits & SendFilesAllow::OnlyOne) || !has)) {
|
|
|
|
way.setSendImagesAsPhotos(!way.sendImagesAsPhotos());
|
|
|
|
}
|
|
|
|
const auto result = checkWith(list, way);
|
|
|
|
_list.files.push_back(std::move(removing));
|
|
|
|
std::swap(_list.files[index], _list.files.back());
|
|
|
|
if (!result) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
_sendWay = way;
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
const auto checkResult = [=](const Ui::PreparedList &list) {
|
|
|
|
return checkSlowmode(list) && checkRights(list);
|
|
|
|
};
|
2020-10-17 17:09:06 +00:00
|
|
|
const auto callback = [=](FileDialog::OpenResult &&result) {
|
2023-05-18 13:46:24 +00:00
|
|
|
const auto premium = _show->session().premium();
|
2020-10-17 17:09:06 +00:00
|
|
|
FileDialogCallback(
|
|
|
|
std::move(result),
|
|
|
|
checkResult,
|
2022-05-10 14:22:28 +00:00
|
|
|
replace,
|
2022-06-14 09:48:25 +00:00
|
|
|
premium,
|
2023-05-02 09:33:19 +00:00
|
|
|
show);
|
2020-10-17 17:09:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
FileDialog::GetOpenPath(
|
|
|
|
this,
|
|
|
|
tr::lng_choose_file(tr::now),
|
|
|
|
FileDialog::AllOrImagesFilter(),
|
|
|
|
crl::guard(this, callback));
|
|
|
|
}, widget->lifetime());
|
2021-02-20 03:30:14 +00:00
|
|
|
|
2021-09-05 09:37:30 +00:00
|
|
|
const auto openedOnce = widget->lifetime().make_state<bool>(false);
|
2021-02-20 03:30:14 +00:00
|
|
|
block.itemModifyRequest(
|
2023-05-18 13:46:24 +00:00
|
|
|
) | rpl::start_with_next([=, show = _show](int index) {
|
2023-08-16 11:23:06 +00:00
|
|
|
applyBlockChanges();
|
|
|
|
|
2021-09-05 09:37:30 +00:00
|
|
|
if (!(*openedOnce)) {
|
2023-05-18 13:46:24 +00:00
|
|
|
show->session().settings().incrementPhotoEditorHintShown();
|
|
|
|
show->session().saveSettings();
|
2021-09-05 09:37:30 +00:00
|
|
|
}
|
|
|
|
*openedOnce = true;
|
2021-02-20 07:52:48 +00:00
|
|
|
Editor::OpenWithPreparedFile(
|
|
|
|
this,
|
2023-05-18 13:46:24 +00:00
|
|
|
show,
|
2021-02-20 07:52:48 +00:00
|
|
|
&_list.files[index],
|
|
|
|
st::sendMediaPreviewSize,
|
|
|
|
[=] { refreshAllAfterChanges(from); });
|
2021-02-20 03:30:14 +00:00
|
|
|
}, widget->lifetime());
|
2020-10-17 17:09:06 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 08:36:50 +00:00
|
|
|
void SendFilesBox::refreshControls(bool initial) {
|
|
|
|
if (initial || !hasSendMenu()) {
|
|
|
|
refreshButtons();
|
|
|
|
}
|
2020-10-16 14:11:23 +00:00
|
|
|
refreshTitleText();
|
2022-12-16 08:36:50 +00:00
|
|
|
updateSendWayControls();
|
2020-11-02 07:35:38 +00:00
|
|
|
updateCaptionPlaceholder();
|
2017-12-22 17:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::setupSendWayControls() {
|
2022-12-12 11:35:41 +00:00
|
|
|
const auto groupFilesFirst = _sendWay.current().groupFiles();
|
|
|
|
const auto asPhotosFirst = _sendWay.current().sendImagesAsPhotos();
|
2020-10-17 09:51:55 +00:00
|
|
|
_groupFiles.create(
|
2020-10-15 14:27:16 +00:00
|
|
|
this,
|
2020-10-19 15:37:59 +00:00
|
|
|
tr::lng_send_grouped(tr::now),
|
2022-12-12 11:35:41 +00:00
|
|
|
groupFilesFirst,
|
2023-05-18 13:46:24 +00:00
|
|
|
_st.files.checkbox,
|
|
|
|
_st.files.check);
|
2020-10-15 14:27:16 +00:00
|
|
|
_sendImagesAsPhotos.create(
|
|
|
|
this,
|
2020-10-19 15:37:59 +00:00
|
|
|
tr::lng_send_compressed(tr::now),
|
2023-01-10 18:56:20 +00:00
|
|
|
_sendWay.current().sendImagesAsPhotos(),
|
2023-05-18 13:46:24 +00:00
|
|
|
_st.files.checkbox,
|
|
|
|
_st.files.check);
|
2020-10-15 14:27:16 +00:00
|
|
|
|
|
|
|
_sendWay.changes(
|
|
|
|
) | rpl::start_with_next([=](SendFilesWay value) {
|
|
|
|
_groupFiles->setChecked(value.groupFiles());
|
2020-10-17 09:51:55 +00:00
|
|
|
_sendImagesAsPhotos->setChecked(value.sendImagesAsPhotos());
|
2020-10-15 14:27:16 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2020-10-17 09:51:55 +00:00
|
|
|
_groupFiles->checkedChanges(
|
2023-01-10 18:56:20 +00:00
|
|
|
) | rpl::start_with_next([=](bool checked) {
|
2020-10-15 14:27:16 +00:00
|
|
|
auto sendWay = _sendWay.current();
|
2023-01-10 18:56:20 +00:00
|
|
|
if (sendWay.groupFiles() == checked) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sendWay.setGroupFiles(checked);
|
|
|
|
if (checkWithWay(sendWay)) {
|
|
|
|
_sendWay = sendWay;
|
|
|
|
} else {
|
|
|
|
Ui::PostponeCall(_groupFiles.data(), [=] {
|
|
|
|
_groupFiles->setChecked(!checked);
|
|
|
|
});
|
|
|
|
}
|
2020-10-15 14:27:16 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_sendImagesAsPhotos->checkedChanges(
|
2023-01-10 18:56:20 +00:00
|
|
|
) | rpl::start_with_next([=](bool checked) {
|
2020-10-15 14:27:16 +00:00
|
|
|
auto sendWay = _sendWay.current();
|
2023-01-10 18:56:20 +00:00
|
|
|
if (sendWay.sendImagesAsPhotos() == checked) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sendWay.setSendImagesAsPhotos(checked);
|
|
|
|
if (checkWithWay(sendWay)) {
|
|
|
|
_sendWay = sendWay;
|
|
|
|
} else {
|
|
|
|
Ui::PostponeCall(_sendImagesAsPhotos.data(), [=] {
|
|
|
|
_sendImagesAsPhotos->setChecked(!checked);
|
|
|
|
});
|
|
|
|
}
|
2020-10-15 14:27:16 +00:00
|
|
|
}, lifetime());
|
2021-04-26 08:23:54 +00:00
|
|
|
|
2022-12-12 11:35:41 +00:00
|
|
|
_wayRemember.create(
|
|
|
|
this,
|
|
|
|
tr::lng_remember(tr::now),
|
|
|
|
false,
|
2023-05-18 13:46:24 +00:00
|
|
|
_st.files.checkbox,
|
|
|
|
_st.files.check);
|
2022-12-12 11:35:41 +00:00
|
|
|
_wayRemember->hide();
|
|
|
|
rpl::combine(
|
|
|
|
_groupFiles->checkedValue(),
|
|
|
|
_sendImagesAsPhotos->checkedValue()
|
|
|
|
) | rpl::start_with_next([=](bool groupFiles, bool asPhoto) {
|
|
|
|
_wayRemember->setVisible(
|
|
|
|
(groupFiles != groupFilesFirst) || (asPhoto != asPhotosFirst));
|
|
|
|
captionResized();
|
|
|
|
}, lifetime());
|
|
|
|
|
2021-04-26 08:23:54 +00:00
|
|
|
_hintLabel.create(
|
|
|
|
this,
|
|
|
|
tr::lng_edit_photo_editor_hint(tr::now),
|
|
|
|
st::editMediaHintLabel);
|
2020-10-15 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2023-01-10 18:56:20 +00:00
|
|
|
bool SendFilesBox::checkWithWay(Ui::SendFilesWay way, bool silent) const {
|
|
|
|
return checkWith({}, way, silent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SendFilesBox::checkWith(
|
|
|
|
const Ui::PreparedList &added,
|
|
|
|
Ui::SendFilesWay way,
|
|
|
|
bool silent) const {
|
|
|
|
if (!_check) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const auto compress = way.sendImagesAsPhotos();
|
|
|
|
auto &already = _list.files;
|
|
|
|
for (const auto &file : ranges::views::concat(already, added.files)) {
|
|
|
|
if (!_check(file, compress, silent)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-16 08:36:50 +00:00
|
|
|
void SendFilesBox::updateSendWayControls() {
|
2023-01-10 18:56:20 +00:00
|
|
|
const auto onlyOne = (_limits & SendFilesAllow::OnlyOne);
|
2020-10-19 15:37:59 +00:00
|
|
|
_groupFiles->setVisible(_list.hasGroupOption(onlyOne));
|
|
|
|
_sendImagesAsPhotos->setVisible(
|
|
|
|
_list.hasSendImagesAsPhotosOption(onlyOne));
|
2022-12-16 08:36:50 +00:00
|
|
|
_sendImagesAsPhotos->setText((_list.files.size() > 1)
|
|
|
|
? tr::lng_send_compressed(tr::now)
|
|
|
|
: tr::lng_send_compressed_one(tr::now));
|
2021-04-26 08:23:54 +00:00
|
|
|
|
|
|
|
_hintLabel->setVisible(
|
2023-05-18 13:46:24 +00:00
|
|
|
_show->session().settings().photoEditorHintShown()
|
2022-11-10 15:34:37 +00:00
|
|
|
? _list.canHaveEditorHintLabel()
|
2021-04-26 08:23:54 +00:00
|
|
|
: false);
|
2017-12-22 17:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::setupCaption() {
|
2023-05-18 13:46:24 +00:00
|
|
|
const auto allow = [=](const auto &) {
|
2023-01-10 18:56:20 +00:00
|
|
|
return (_limits & SendFilesAllow::EmojiWithoutPremium);
|
2022-08-02 16:23:06 +00:00
|
|
|
};
|
2023-05-18 13:46:24 +00:00
|
|
|
const auto show = _show;
|
2022-07-01 13:01:39 +00:00
|
|
|
InitMessageFieldHandlers(
|
2023-05-18 13:46:24 +00:00
|
|
|
&show->session(),
|
|
|
|
show,
|
2022-07-01 13:01:39 +00:00
|
|
|
_caption.data(),
|
2023-05-18 13:46:24 +00:00
|
|
|
[=] { return show->paused(Window::GifPauseReason::Layer); },
|
|
|
|
allow,
|
|
|
|
&_st.files.caption);
|
2022-07-01 13:01:39 +00:00
|
|
|
Ui::Emoji::SuggestionsController::Init(
|
|
|
|
getDelegate()->outerContainer(),
|
|
|
|
_caption,
|
2023-05-18 13:46:24 +00:00
|
|
|
&_show->session(),
|
|
|
|
{
|
|
|
|
.suggestCustomEmoji = true,
|
|
|
|
.allowCustomWithoutPremium = allow,
|
|
|
|
.st = &_st.suggestions,
|
|
|
|
});
|
2022-07-01 13:01:39 +00:00
|
|
|
|
2022-08-15 16:10:38 +00:00
|
|
|
if (!_prefilledCaptionText.text.isEmpty()) {
|
|
|
|
_caption->setTextWithTags(
|
|
|
|
_prefilledCaptionText,
|
|
|
|
Ui::InputField::HistoryAction::Clear);
|
|
|
|
|
|
|
|
auto cursor = _caption->textCursor();
|
|
|
|
cursor.movePosition(QTextCursor::End);
|
|
|
|
_caption->setTextCursor(cursor);
|
|
|
|
}
|
2020-06-17 09:36:25 +00:00
|
|
|
_caption->setSubmitSettings(
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().settings().sendSubmitWay());
|
2022-07-01 13:01:39 +00:00
|
|
|
_caption->setMaxLength(kMaxMessageLength);
|
|
|
|
|
2023-08-31 11:21:24 +00:00
|
|
|
_caption->heightChanges(
|
|
|
|
) | rpl::start_with_next([=] {
|
2017-12-22 17:42:33 +00:00
|
|
|
captionResized();
|
2023-08-31 11:21:24 +00:00
|
|
|
}, _caption->lifetime());
|
|
|
|
_caption->submits(
|
|
|
|
) | rpl::start_with_next([=](Qt::KeyboardModifiers modifiers) {
|
2018-05-31 12:20:28 +00:00
|
|
|
const auto ctrlShiftEnter = modifiers.testFlag(Qt::ShiftModifier)
|
|
|
|
&& (modifiers.testFlag(Qt::ControlModifier)
|
|
|
|
|| modifiers.testFlag(Qt::MetaModifier));
|
2019-08-12 12:11:34 +00:00
|
|
|
send({}, ctrlShiftEnter);
|
2023-08-31 11:21:24 +00:00
|
|
|
}, _caption->lifetime());
|
|
|
|
_caption->cancelled(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
closeBox();
|
|
|
|
}, _caption->lifetime());
|
2018-05-31 12:20:28 +00:00
|
|
|
_caption->setMimeDataHook([=](
|
2017-12-29 17:02:23 +00:00
|
|
|
not_null<const QMimeData*> data,
|
2018-05-20 17:42:30 +00:00
|
|
|
Ui::InputField::MimeAction action) {
|
|
|
|
if (action == Ui::InputField::MimeAction::Check) {
|
2023-08-28 18:24:09 +00:00
|
|
|
return CanAddFiles(data);
|
2018-05-20 17:42:30 +00:00
|
|
|
} else if (action == Ui::InputField::MimeAction::Insert) {
|
2017-12-29 17:02:23 +00:00
|
|
|
return addFiles(data);
|
|
|
|
}
|
|
|
|
Unexpected("action in MimeData hook.");
|
|
|
|
});
|
2019-10-18 13:54:26 +00:00
|
|
|
|
2018-12-26 06:47:03 +00:00
|
|
|
updateCaptionPlaceholder();
|
2018-11-22 12:48:50 +00:00
|
|
|
setupEmojiPanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::setupEmojiPanel() {
|
2019-07-17 10:37:42 +00:00
|
|
|
Expects(_caption != nullptr);
|
|
|
|
|
2018-11-22 12:48:50 +00:00
|
|
|
const auto container = getDelegate()->outerContainer();
|
2022-07-25 10:34:18 +00:00
|
|
|
using Selector = ChatHelpers::TabbedSelector;
|
2018-11-22 12:48:50 +00:00
|
|
|
_emojiPanel = base::make_unique_q<ChatHelpers::TabbedPanel>(
|
|
|
|
container,
|
2023-05-18 13:46:24 +00:00
|
|
|
ChatHelpers::TabbedPanelDescriptor{
|
|
|
|
.ownedSelector = object_ptr<Selector>(
|
|
|
|
nullptr,
|
|
|
|
ChatHelpers::TabbedSelectorDescriptor{
|
|
|
|
.show = _show,
|
|
|
|
.st = _st.tabbed,
|
|
|
|
.level = Window::GifPauseReason::Layer,
|
|
|
|
.mode = ChatHelpers::TabbedSelector::Mode::EmojiOnly,
|
|
|
|
.features = {
|
|
|
|
.megagroupSet = false,
|
|
|
|
.stickersSettings = false,
|
|
|
|
.openStickerSets = false,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
});
|
2018-11-22 12:48:50 +00:00
|
|
|
_emojiPanel->setDesiredHeightValues(
|
|
|
|
1.,
|
|
|
|
st::emojiPanMinHeight / 2,
|
|
|
|
st::emojiPanMinHeight);
|
|
|
|
_emojiPanel->hide();
|
2022-08-01 13:24:51 +00:00
|
|
|
_emojiPanel->selector()->setAllowEmojiWithoutPremium(
|
2023-01-10 18:56:20 +00:00
|
|
|
_limits & SendFilesAllow::EmojiWithoutPremium);
|
2019-08-16 12:44:20 +00:00
|
|
|
_emojiPanel->selector()->emojiChosen(
|
2022-09-14 10:45:23 +00:00
|
|
|
) | rpl::start_with_next([=](ChatHelpers::EmojiChosen data) {
|
2022-09-06 13:08:20 +00:00
|
|
|
Ui::InsertEmojiAtCursor(_caption->textCursor(), data.emoji);
|
2018-11-22 12:48:50 +00:00
|
|
|
}, lifetime());
|
2022-07-25 10:34:18 +00:00
|
|
|
_emojiPanel->selector()->customEmojiChosen(
|
2022-09-14 10:45:23 +00:00
|
|
|
) | rpl::start_with_next([=](ChatHelpers::FileChosen data) {
|
|
|
|
const auto info = data.document->sticker();
|
|
|
|
if (info
|
|
|
|
&& info->setType == Data::StickersType::Emoji
|
2023-05-18 13:46:24 +00:00
|
|
|
&& !_show->session().premium()
|
2023-01-10 18:56:20 +00:00
|
|
|
&& !(_limits & SendFilesAllow::EmojiWithoutPremium)) {
|
2023-05-18 13:46:24 +00:00
|
|
|
ShowPremiumPreviewBox(_show, PremiumPreview::AnimatedEmoji);
|
2022-09-14 10:45:23 +00:00
|
|
|
} else {
|
|
|
|
Data::InsertCustomEmoji(_caption.data(), data.document);
|
|
|
|
}
|
2022-07-25 10:34:18 +00:00
|
|
|
}, lifetime());
|
2018-11-22 12:48:50 +00:00
|
|
|
|
2019-09-05 10:51:36 +00:00
|
|
|
const auto filterCallback = [=](not_null<QEvent*> event) {
|
|
|
|
emojiFilterForGeometry(event);
|
2019-09-19 09:28:36 +00:00
|
|
|
return base::EventFilterResult::Continue;
|
2019-09-05 10:51:36 +00:00
|
|
|
};
|
2019-09-19 09:28:36 +00:00
|
|
|
_emojiFilter.reset(base::install_event_filter(container, filterCallback));
|
2018-11-22 12:48:50 +00:00
|
|
|
|
2023-05-18 13:46:24 +00:00
|
|
|
_emojiToggle.create(this, _st.files.emoji);
|
2019-07-17 10:37:42 +00:00
|
|
|
_emojiToggle->setVisible(!_caption->isHidden());
|
2018-11-22 12:48:50 +00:00
|
|
|
_emojiToggle->installEventFilter(_emojiPanel);
|
|
|
|
_emojiToggle->addClickHandler([=] {
|
|
|
|
_emojiPanel->toggleAnimated();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-05 10:51:36 +00:00
|
|
|
void SendFilesBox::emojiFilterForGeometry(not_null<QEvent*> event) {
|
2018-11-22 12:48:50 +00:00
|
|
|
const auto type = event->type();
|
|
|
|
if (type == QEvent::Move || type == QEvent::Resize) {
|
|
|
|
// updateEmojiPanelGeometry uses not only container geometry, but
|
|
|
|
// also container children geometries that will be updated later.
|
|
|
|
crl::on_main(this, [=] { updateEmojiPanelGeometry(); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::updateEmojiPanelGeometry() {
|
|
|
|
const auto parent = _emojiPanel->parentWidget();
|
|
|
|
const auto global = _emojiToggle->mapToGlobal({ 0, 0 });
|
|
|
|
const auto local = parent->mapFromGlobal(global);
|
|
|
|
_emojiPanel->moveBottomRight(
|
|
|
|
local.y(),
|
|
|
|
local.x() + _emojiToggle->width() * 3);
|
2017-12-22 17:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::captionResized() {
|
2017-12-19 16:57:42 +00:00
|
|
|
updateBoxSize();
|
|
|
|
updateControlsGeometry();
|
2018-11-22 12:48:50 +00:00
|
|
|
updateEmojiPanelGeometry();
|
2017-12-19 16:57:42 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-12-29 17:02:23 +00:00
|
|
|
bool SendFilesBox::addFiles(not_null<const QMimeData*> data) {
|
2023-05-18 13:46:24 +00:00
|
|
|
const auto premium = _show->session().premium();
|
2017-12-29 17:02:23 +00:00
|
|
|
auto list = [&] {
|
2023-03-06 07:58:25 +00:00
|
|
|
const auto urls = Core::ReadMimeUrls(data);
|
2020-01-05 20:45:15 +00:00
|
|
|
auto result = CanAddUrls(urls)
|
2022-05-10 14:22:28 +00:00
|
|
|
? Storage::PrepareMediaList(
|
|
|
|
urls,
|
|
|
|
st::sendMediaPreviewSize,
|
|
|
|
premium)
|
2020-10-13 12:07:53 +00:00
|
|
|
: Ui::PreparedList(
|
|
|
|
Ui::PreparedList::Error::EmptyFile,
|
2018-03-09 21:09:12 +00:00
|
|
|
QString());
|
2020-10-13 12:07:53 +00:00
|
|
|
if (result.error == Ui::PreparedList::Error::None) {
|
2018-03-09 21:09:12 +00:00
|
|
|
return result;
|
2023-01-13 07:51:59 +00:00
|
|
|
} else if (auto read = Core::ReadMimeImage(data)) {
|
|
|
|
return Storage::PrepareMediaFromImage(
|
|
|
|
std::move(read.image),
|
|
|
|
std::move(read.content),
|
|
|
|
st::sendMediaPreviewSize);
|
2017-12-29 17:02:23 +00:00
|
|
|
}
|
2018-03-09 21:09:12 +00:00
|
|
|
return result;
|
2017-12-29 17:02:23 +00:00
|
|
|
}();
|
2020-01-05 20:45:15 +00:00
|
|
|
return addFiles(std::move(list));
|
|
|
|
}
|
|
|
|
|
2020-10-13 12:07:53 +00:00
|
|
|
bool SendFilesBox::addFiles(Ui::PreparedList list) {
|
|
|
|
if (list.error != Ui::PreparedList::Error::None) {
|
2017-12-29 17:02:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-10-16 14:11:23 +00:00
|
|
|
const auto count = int(_list.files.size());
|
|
|
|
_list.filesToProcess.insert(
|
|
|
|
_list.filesToProcess.end(),
|
|
|
|
std::make_move_iterator(list.files.begin()),
|
|
|
|
std::make_move_iterator(list.files.end()));
|
|
|
|
_list.filesToProcess.insert(
|
|
|
|
_list.filesToProcess.end(),
|
|
|
|
std::make_move_iterator(list.filesToProcess.begin()),
|
|
|
|
std::make_move_iterator(list.filesToProcess.end()));
|
|
|
|
enqueueNextPrepare();
|
|
|
|
if (_list.files.size() > count) {
|
|
|
|
refreshAllAfterChanges(count);
|
|
|
|
}
|
2017-12-29 17:02:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-16 14:11:23 +00:00
|
|
|
void SendFilesBox::addPreparedAsyncFile(Ui::PreparedFile &&file) {
|
|
|
|
Expects(file.information != nullptr);
|
|
|
|
|
|
|
|
_preparing = false;
|
|
|
|
const auto count = int(_list.files.size());
|
|
|
|
addFile(std::move(file));
|
|
|
|
enqueueNextPrepare();
|
|
|
|
if (_list.files.size() > count) {
|
|
|
|
refreshAllAfterChanges(count);
|
|
|
|
}
|
2020-10-16 17:48:27 +00:00
|
|
|
if (!_preparing && _whenReadySend) {
|
|
|
|
_whenReadySend();
|
|
|
|
}
|
2020-10-16 14:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::addFile(Ui::PreparedFile &&file) {
|
2020-11-19 12:37:23 +00:00
|
|
|
// canBeSentInSlowmode checks for non empty filesToProcess.
|
|
|
|
auto saved = base::take(_list.filesToProcess);
|
2020-10-16 14:11:23 +00:00
|
|
|
_list.files.push_back(std::move(file));
|
2023-01-10 18:56:20 +00:00
|
|
|
const auto lastOk = [&] {
|
|
|
|
auto way = _sendWay.current();
|
|
|
|
if (_limits & SendFilesAllow::OnlyOne) {
|
|
|
|
way.setGroupFiles(true);
|
|
|
|
if (!_list.canBeSentInSlowmode()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (!checkWithWay(way)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
_sendWay = way;
|
|
|
|
return true;
|
|
|
|
}();
|
|
|
|
if (!lastOk) {
|
2020-10-16 14:11:23 +00:00
|
|
|
_list.files.pop_back();
|
|
|
|
}
|
2020-11-19 12:37:23 +00:00
|
|
|
_list.filesToProcess = std::move(saved);
|
2020-10-16 14:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::refreshTitleText() {
|
2022-12-16 08:36:50 +00:00
|
|
|
using Type = Ui::PreparedFile::Type;
|
2020-10-16 14:11:23 +00:00
|
|
|
const auto count = int(_list.files.size());
|
|
|
|
if (count > 1) {
|
|
|
|
const auto imagesCount = ranges::count(
|
|
|
|
_list.files,
|
2022-12-16 08:36:50 +00:00
|
|
|
Type::Photo,
|
2020-10-16 14:11:23 +00:00
|
|
|
&Ui::PreparedFile::type);
|
|
|
|
_titleText = (imagesCount == count)
|
|
|
|
? tr::lng_send_images_selected(tr::now, lt_count, count)
|
|
|
|
: tr::lng_send_files_selected(tr::now, lt_count, count);
|
2017-12-22 17:42:33 +00:00
|
|
|
} else {
|
2022-12-16 08:36:50 +00:00
|
|
|
const auto type = _list.files.empty()
|
|
|
|
? Type::None
|
|
|
|
: _list.files.front().type;
|
|
|
|
_titleText = (type == Type::Photo)
|
|
|
|
? tr::lng_send_image(tr::now)
|
|
|
|
: (type == Type::Video)
|
|
|
|
? tr::lng_send_video(tr::now)
|
|
|
|
: tr::lng_send_file(tr::now);
|
2017-12-22 17:42:33 +00:00
|
|
|
}
|
2022-12-16 08:36:50 +00:00
|
|
|
_titleHeight = st::boxTitleHeight;
|
2017-12-22 17:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::updateBoxSize() {
|
|
|
|
auto footerHeight = 0;
|
2023-01-10 18:56:20 +00:00
|
|
|
if (_caption && !_caption->isHidden()) {
|
2017-12-22 17:42:33 +00:00
|
|
|
footerHeight += st::boxPhotoCaptionSkip + _caption->height();
|
2017-12-19 16:57:42 +00:00
|
|
|
}
|
2022-12-12 11:35:41 +00:00
|
|
|
const auto pairs = std::array<std::pair<RpWidget*, int>, 4>{ {
|
2021-04-26 08:23:54 +00:00
|
|
|
{ _groupFiles.data(), st::boxPhotoCompressedSkip },
|
|
|
|
{ _sendImagesAsPhotos.data(), st::boxPhotoCompressedSkip },
|
2022-12-12 11:35:41 +00:00
|
|
|
{ _wayRemember.data(), st::boxPhotoCompressedSkip },
|
2021-04-26 08:23:54 +00:00
|
|
|
{ _hintLabel.data(), st::editMediaLabelMargins.top() },
|
|
|
|
} };
|
|
|
|
for (const auto &pair : pairs) {
|
|
|
|
const auto pointer = pair.first;
|
2020-10-15 14:27:16 +00:00
|
|
|
if (pointer && !pointer->isHidden()) {
|
2021-04-26 08:23:54 +00:00
|
|
|
footerHeight += pair.second + pointer->heightNoMargins();
|
2017-12-22 17:42:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_footerHeight = footerHeight;
|
2017-12-19 16:57:42 +00:00
|
|
|
}
|
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
void SendFilesBox::keyPressEvent(QKeyEvent *e) {
|
2020-10-15 14:27:16 +00:00
|
|
|
if (e->matches(QKeySequence::Open)) {
|
2020-01-05 21:04:47 +00:00
|
|
|
openDialogToAddFileToAlbum();
|
|
|
|
} else if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
2017-12-19 16:57:42 +00:00
|
|
|
const auto modifiers = e->modifiers();
|
|
|
|
const auto ctrl = modifiers.testFlag(Qt::ControlModifier)
|
|
|
|
|| modifiers.testFlag(Qt::MetaModifier);
|
|
|
|
const auto shift = modifiers.testFlag(Qt::ShiftModifier);
|
2019-08-12 12:11:34 +00:00
|
|
|
send({}, ctrl && shift);
|
2017-12-19 16:57:42 +00:00
|
|
|
} else {
|
|
|
|
BoxContent::keyPressEvent(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
void SendFilesBox::paintEvent(QPaintEvent *e) {
|
2017-12-19 16:57:42 +00:00
|
|
|
BoxContent::paintEvent(e);
|
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
if (!_titleText.isEmpty()) {
|
|
|
|
Painter p(this);
|
2017-12-19 16:57:42 +00:00
|
|
|
|
2020-10-19 10:02:39 +00:00
|
|
|
p.setFont(st::boxTitleFont);
|
2023-05-18 13:46:24 +00:00
|
|
|
p.setPen(getDelegate()->style().title.textFg);
|
2017-12-22 17:42:33 +00:00
|
|
|
p.drawTextLeft(
|
|
|
|
st::boxPhotoTitlePosition.x(),
|
2022-02-07 15:35:32 +00:00
|
|
|
st::boxTitlePosition.y() - st::boxTopMargin,
|
2017-12-22 17:42:33 +00:00
|
|
|
width(),
|
|
|
|
_titleText);
|
2017-12-19 16:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
void SendFilesBox::resizeEvent(QResizeEvent *e) {
|
2017-12-19 16:57:42 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
void SendFilesBox::updateControlsGeometry() {
|
2017-12-19 16:57:42 +00:00
|
|
|
auto bottom = height();
|
2023-01-10 18:56:20 +00:00
|
|
|
if (_caption && !_caption->isHidden()) {
|
2017-12-19 16:57:42 +00:00
|
|
|
_caption->resize(st::sendMediaPreviewSize, _caption->height());
|
2017-12-22 17:42:33 +00:00
|
|
|
_caption->moveToLeft(
|
|
|
|
st::boxPhotoPadding.left(),
|
|
|
|
bottom - _caption->height());
|
2017-12-19 16:57:42 +00:00
|
|
|
bottom -= st::boxPhotoCaptionSkip + _caption->height();
|
2018-11-22 12:48:50 +00:00
|
|
|
|
2019-01-14 06:28:20 +00:00
|
|
|
if (_emojiToggle) {
|
|
|
|
_emojiToggle->moveToLeft(
|
|
|
|
(st::boxPhotoPadding.left()
|
|
|
|
+ st::sendMediaPreviewSize
|
|
|
|
- _emojiToggle->width()),
|
|
|
|
_caption->y() + st::boxAttachEmojiTop);
|
2020-10-19 10:02:39 +00:00
|
|
|
_emojiToggle->update();
|
2019-01-14 06:28:20 +00:00
|
|
|
}
|
2017-12-19 16:57:42 +00:00
|
|
|
}
|
2022-12-12 11:35:41 +00:00
|
|
|
const auto pairs = std::array<std::pair<RpWidget*, int>, 4>{ {
|
2021-04-26 08:23:54 +00:00
|
|
|
{ _hintLabel.data(), st::editMediaLabelMargins.top() },
|
|
|
|
{ _groupFiles.data(), st::boxPhotoCompressedSkip },
|
|
|
|
{ _sendImagesAsPhotos.data(), st::boxPhotoCompressedSkip },
|
2022-12-12 11:35:41 +00:00
|
|
|
{ _wayRemember.data(), st::boxPhotoCompressedSkip },
|
2021-04-26 08:23:54 +00:00
|
|
|
} };
|
|
|
|
for (const auto &pair : ranges::views::reverse(pairs)) {
|
|
|
|
const auto pointer = pair.first;
|
2020-10-15 14:27:16 +00:00
|
|
|
if (pointer && !pointer->isHidden()) {
|
2017-12-22 17:42:33 +00:00
|
|
|
pointer->moveToLeft(
|
|
|
|
st::boxPhotoPadding.left(),
|
|
|
|
bottom - pointer->heightNoMargins());
|
2021-04-26 08:23:54 +00:00
|
|
|
bottom -= pair.second + pointer->heightNoMargins();
|
2017-12-22 17:42:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-19 10:02:39 +00:00
|
|
|
_scroll->resize(width(), bottom - _titleHeight.current());
|
|
|
|
_scroll->move(0, _titleHeight.current());
|
2017-12-19 16:57:42 +00:00
|
|
|
}
|
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
void SendFilesBox::setInnerFocus() {
|
2022-08-15 12:40:11 +00:00
|
|
|
if (_caption && !_caption->isHidden()) {
|
2017-12-19 16:57:42 +00:00
|
|
|
_caption->setFocusFast();
|
2022-08-15 12:40:11 +00:00
|
|
|
} else {
|
|
|
|
BoxContent::setInnerFocus();
|
2017-12-19 16:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 07:07:03 +00:00
|
|
|
void SendFilesBox::saveSendWaySettings() {
|
|
|
|
auto way = _sendWay.current();
|
|
|
|
auto oldWay = Core::App().settings().sendFilesWay();
|
|
|
|
if (_groupFiles->isHidden()) {
|
|
|
|
way.setGroupFiles(oldWay.groupFiles());
|
|
|
|
}
|
|
|
|
if (_list.overrideSendImagesAsPhotos == way.sendImagesAsPhotos()
|
|
|
|
|| _sendImagesAsPhotos->isHidden()) {
|
|
|
|
way.setSendImagesAsPhotos(oldWay.sendImagesAsPhotos());
|
|
|
|
}
|
|
|
|
if (way != oldWay) {
|
|
|
|
Core::App().settings().setSendFilesWay(way);
|
|
|
|
Core::App().saveSettingsDelayed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-11 09:59:38 +00:00
|
|
|
bool SendFilesBox::validateLength(const QString &text) const {
|
2023-05-18 13:46:24 +00:00
|
|
|
const auto session = &_show->session();
|
2022-06-15 22:24:10 +00:00
|
|
|
const auto limit = Data::PremiumLimits(session).captionLengthCurrent();
|
2022-05-11 09:59:38 +00:00
|
|
|
const auto remove = int(text.size()) - limit;
|
|
|
|
const auto way = _sendWay.current();
|
|
|
|
if (remove <= 0
|
|
|
|
|| !_list.canAddCaption(
|
2022-11-10 15:34:37 +00:00
|
|
|
way.groupFiles() && way.sendImagesAsPhotos(),
|
|
|
|
way.sendImagesAsPhotos())) {
|
2022-05-11 09:59:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-05-18 13:46:24 +00:00
|
|
|
_show->showBox(
|
|
|
|
Box(CaptionLimitReachedBox, session, remove, &_st.premium));
|
2022-05-11 09:59:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-12 12:11:34 +00:00
|
|
|
void SendFilesBox::send(
|
|
|
|
Api::SendOptions options,
|
|
|
|
bool ctrlShiftEnter) {
|
2020-01-15 02:31:28 +00:00
|
|
|
if ((_sendType == Api::SendType::Scheduled
|
|
|
|
|| _sendType == Api::SendType::ScheduledToUser)
|
|
|
|
&& !options.scheduled) {
|
2019-08-20 13:21:10 +00:00
|
|
|
return sendScheduled();
|
|
|
|
}
|
2020-10-16 17:48:27 +00:00
|
|
|
if (_preparing) {
|
|
|
|
_whenReadySend = [=] {
|
|
|
|
send(options, ctrlShiftEnter);
|
|
|
|
};
|
|
|
|
return;
|
|
|
|
}
|
2019-08-20 13:21:10 +00:00
|
|
|
|
2022-12-12 11:35:41 +00:00
|
|
|
if (_wayRemember && _wayRemember->checked()) {
|
|
|
|
saveSendWaySettings();
|
|
|
|
}
|
2017-12-25 19:26:08 +00:00
|
|
|
|
2022-12-13 13:31:54 +00:00
|
|
|
for (auto &item : _list.files) {
|
|
|
|
item.spoiler = false;
|
|
|
|
}
|
2022-12-16 08:36:50 +00:00
|
|
|
applyBlockChanges();
|
2021-02-08 03:13:40 +00:00
|
|
|
|
2021-09-05 09:37:30 +00:00
|
|
|
Storage::ApplyModifications(_list);
|
2021-02-08 03:13:40 +00:00
|
|
|
|
2017-12-19 16:57:42 +00:00
|
|
|
_confirmed = true;
|
|
|
|
if (_confirmedCallback) {
|
2019-07-17 10:37:42 +00:00
|
|
|
auto caption = (_caption && !_caption->isHidden())
|
2018-05-31 18:28:37 +00:00
|
|
|
? _caption->getTextWithAppliedMarkdown()
|
2018-05-24 13:03:21 +00:00
|
|
|
: TextWithTags();
|
2022-05-11 09:59:38 +00:00
|
|
|
if (!validateLength(caption.text)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-19 16:57:42 +00:00
|
|
|
_confirmedCallback(
|
|
|
|
std::move(_list),
|
2020-11-02 07:07:03 +00:00
|
|
|
_sendWay.current(),
|
2017-12-22 17:42:33 +00:00
|
|
|
std::move(caption),
|
2019-08-12 12:11:34 +00:00
|
|
|
options,
|
2017-12-19 16:57:42 +00:00
|
|
|
ctrlShiftEnter);
|
|
|
|
}
|
|
|
|
closeBox();
|
|
|
|
}
|
|
|
|
|
2019-08-12 12:11:34 +00:00
|
|
|
void SendFilesBox::sendSilent() {
|
2021-11-09 15:24:13 +00:00
|
|
|
send({ .silent = true });
|
2019-08-12 12:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendFilesBox::sendScheduled() {
|
2020-01-15 02:31:28 +00:00
|
|
|
const auto type = (_sendType == Api::SendType::ScheduledToUser)
|
2020-08-10 12:22:54 +00:00
|
|
|
? SendMenu::Type::ScheduledToUser
|
2020-01-15 02:31:28 +00:00
|
|
|
: _sendMenuType;
|
2019-08-20 13:21:10 +00:00
|
|
|
const auto callback = [=](Api::SendOptions options) { send(options); };
|
2023-05-18 13:46:24 +00:00
|
|
|
_show->showBox(HistoryView::PrepareScheduleBox(this, type, callback));
|
2019-08-12 12:11:34 +00:00
|
|
|
}
|
|
|
|
|
2023-04-22 18:26:09 +00:00
|
|
|
void SendFilesBox::sendWhenOnline() {
|
|
|
|
send(Api::DefaultSendWhenOnlineOptions());
|
|
|
|
}
|
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
SendFilesBox::~SendFilesBox() = default;
|