Added ability to pass Api::SendOptions from TabbedSelector.

This commit is contained in:
23rd 2020-07-24 11:22:45 +03:00 committed by John Preston
parent b71062561a
commit 759e802eba
12 changed files with 35 additions and 22 deletions

View File

@ -165,7 +165,7 @@ GifsListWidget::GifsListWidget(
});
}
rpl::producer<not_null<DocumentData*>> GifsListWidget::fileChosen() const {
rpl::producer<TabbedSelector::FileChosen> GifsListWidget::fileChosen() const {
return _fileChosen.events();
}
@ -391,7 +391,7 @@ void GifsListWidget::selectInlineResult(int row, int column) {
const auto media = document->activeMediaView();
const auto preview = Data::VideoPreviewState(media.get());
if (ctrl || (media && preview.loaded())) {
_fileChosen.fire_copy(document);
_fileChosen.fire_copy({ .document = document });
} else if (!preview.usingThumbnail()) {
if (preview.loading()) {
document->cancel();

View File

@ -40,7 +40,7 @@ public:
GifsListWidget(QWidget *parent, not_null<Window::SessionController*> controller);
rpl::producer<not_null<DocumentData*>> fileChosen() const;
rpl::producer<TabbedSelector::FileChosen> fileChosen() const;
rpl::producer<not_null<PhotoData*>> photoChosen() const;
rpl::producer<InlineChosen> inlineResultChosen() const;
@ -177,7 +177,7 @@ private:
QString _inlineQuery, _inlineNextQuery, _inlineNextOffset;
mtpRequestId _inlineRequestId = 0;
rpl::event_stream<not_null<DocumentData*>> _fileChosen;
rpl::event_stream<TabbedSelector::FileChosen> _fileChosen;
rpl::event_stream<not_null<PhotoData*>> _photoChosen;
rpl::event_stream<InlineChosen> _inlineResultChosen;
rpl::event_stream<> _cancelled;

View File

@ -913,7 +913,7 @@ Main::Session &StickersListWidget::session() const {
return controller()->session();
}
rpl::producer<not_null<DocumentData*>> StickersListWidget::chosen() const {
rpl::producer<TabbedSelector::FileChosen> StickersListWidget::chosen() const {
return _chosen.events();
}
@ -2087,7 +2087,7 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) {
document));
}
} else {
_chosen.fire_copy(document);
_chosen.fire_copy({ .document = document });
}
} else if (auto set = base::get_if<OverSet>(&pressed)) {
Assert(set->section >= 0 && set->section < sets.size());

View File

@ -51,7 +51,7 @@ public:
Main::Session &session() const;
rpl::producer<not_null<DocumentData*>> chosen() const;
rpl::producer<TabbedSelector::FileChosen> chosen() const;
rpl::producer<> scrollUpdated() const;
rpl::producer<> checkForHide() const;
@ -358,7 +358,7 @@ private:
QString _searchQuery, _searchNextQuery;
mtpRequestId _searchRequestId = 0;
rpl::event_stream<not_null<DocumentData*>> _chosen;
rpl::event_stream<TabbedSelector::FileChosen> _chosen;
rpl::event_stream<> _scrollUpdated;
rpl::event_stream<> _checkForHide;

View File

@ -409,10 +409,10 @@ rpl::producer<EmojiPtr> TabbedSelector::emojiChosen() const {
return emoji()->chosen();
}
rpl::producer<not_null<DocumentData*>> TabbedSelector::fileChosen() const {
rpl::producer<TabbedSelector::FileChosen> TabbedSelector::fileChosen() const {
return full()
? rpl::merge(stickers()->chosen(), gifs()->fileChosen())
: rpl::never<not_null<DocumentData*>>() | rpl::type_erased();
: rpl::never<TabbedSelector::FileChosen>() | rpl::type_erased();
}
rpl::producer<not_null<PhotoData*>> TabbedSelector::photoChosen() const {

View File

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "api/api_common.h"
#include "ui/rp_widget.h"
#include "ui/effects/animations.h"
#include "ui/effects/panel_animation.h"
@ -46,6 +47,10 @@ class GifsListWidget;
class TabbedSelector : public Ui::RpWidget, private base::Subscriber {
public:
struct FileChosen {
not_null<DocumentData*> document;
Api::SendOptions options;
};
struct InlineChosen {
not_null<InlineBots::Result*> result;
not_null<UserData*> bot;
@ -64,7 +69,7 @@ public:
Main::Session &session() const;
rpl::producer<EmojiPtr> emojiChosen() const;
rpl::producer<not_null<DocumentData*>> fileChosen() const;
rpl::producer<FileChosen> fileChosen() const;
rpl::producer<not_null<PhotoData*>> photoChosen() const;
rpl::producer<InlineChosen> inlineResultChosen() const;

View File

@ -387,7 +387,7 @@ HistoryWidget::HistoryWidget(
connect(_fieldAutocomplete, SIGNAL(hashtagChosen(QString,FieldAutocomplete::ChooseMethod)), this, SLOT(onHashtagOrBotCommandInsert(QString,FieldAutocomplete::ChooseMethod)));
connect(_fieldAutocomplete, SIGNAL(botCommandChosen(QString,FieldAutocomplete::ChooseMethod)), this, SLOT(onHashtagOrBotCommandInsert(QString,FieldAutocomplete::ChooseMethod)));
connect(_fieldAutocomplete, &FieldAutocomplete::stickerChosen, this, [=](not_null<DocumentData*> document) {
sendExistingDocument(document);
sendExistingDocument(document, Api::SendOptions());
});
connect(_fieldAutocomplete, SIGNAL(moderateKeyActivate(int,bool*)), this, SLOT(onModerateKeyActivate(int,bool*)));
if (_supportAutocomplete) {
@ -818,8 +818,8 @@ void HistoryWidget::initTabbedSelector() {
selector->fileChosen(
) | rpl::filter([=] {
return !isHidden();
}) | rpl::start_with_next([=](not_null<DocumentData*> document) {
sendExistingDocument(document);
}) | rpl::start_with_next([=](TabbedSelector::FileChosen data) {
sendExistingDocument(data.document, data.options);
}, lifetime());
selector->photoChosen(
@ -5368,7 +5368,9 @@ void HistoryWidget::destroyPinnedBar() {
_inPinnedMsg = false;
}
bool HistoryWidget::sendExistingDocument(not_null<DocumentData*> document) {
bool HistoryWidget::sendExistingDocument(
not_null<DocumentData*> document,
Api::SendOptions options) {
const auto error = _peer
? Data::RestrictionError(_peer, ChatRestriction::f_send_stickers)
: std::nullopt;
@ -5382,6 +5384,7 @@ bool HistoryWidget::sendExistingDocument(not_null<DocumentData*> document) {
}
auto message = Api::MessageToSend(_history);
message.action.options = std::move(options);
message.action.replyTo = replyToId();
Api::SendExistingDocument(std::move(message), document);

View File

@ -248,7 +248,9 @@ public:
void confirmDeleteSelected();
void clearSelected();
bool sendExistingDocument(not_null<DocumentData*> document);
bool sendExistingDocument(
not_null<DocumentData*> document,
Api::SendOptions options);
bool sendExistingPhoto(not_null<PhotoData*> photo);
void showInfoTooltip(

View File

@ -39,6 +39,7 @@ namespace HistoryView {
namespace {
using FileChosen = ComposeControls::FileChosen;
using MessageToEdit = ComposeControls::MessageToEdit;
constexpr auto kMouseEvent = {
@ -502,7 +503,7 @@ void ComposeControls::setMimeDataHook(MimeDataHook hook) {
_field->setMimeDataHook(std::move(hook));
}
rpl::producer<not_null<DocumentData*>> ComposeControls::fileChosen() const {
rpl::producer<FileChosen> ComposeControls::fileChosen() const {
return _fileChosen.events();
}

View File

@ -54,6 +54,7 @@ class FieldHeader;
class ComposeControls final {
public:
using FileChosen = ChatHelpers::TabbedSelector::FileChosen;
enum class Mode {
Normal,
Scheduled,
@ -85,7 +86,7 @@ public:
[[nodiscard]] rpl::producer<> sendRequests() const;
[[nodiscard]] rpl::producer<MessageToEdit> editRequests() const;
[[nodiscard]] rpl::producer<> attachRequests() const;
[[nodiscard]] rpl::producer<not_null<DocumentData*>> fileChosen() const;
[[nodiscard]] rpl::producer<FileChosen> fileChosen() const;
[[nodiscard]] rpl::producer<not_null<PhotoData*>> photoChosen() const;
[[nodiscard]] rpl::producer<Data::MessagePosition> scrollRequests() const;
[[nodiscard]] rpl::producer<not_null<QKeyEvent*>> keyEvents() const;
@ -154,7 +155,7 @@ private:
const std::unique_ptr<FieldHeader> _header;
rpl::event_stream<> _cancelRequests;
rpl::event_stream<not_null<DocumentData*>> _fileChosen;
rpl::event_stream<FileChosen> _fileChosen;
rpl::event_stream<not_null<PhotoData*>> _photoChosen;
rpl::event_stream<ChatHelpers::TabbedSelector::InlineChosen> _inlineResultChosen;

View File

@ -199,8 +199,9 @@ void ScheduledWidget::setupComposeControls() {
}, lifetime());
_composeControls->fileChosen(
) | rpl::start_with_next([=](not_null<DocumentData*> document) {
sendExistingDocument(document);
) | rpl::start_with_next([=](
ChatHelpers::TabbedSelector::FileChosen chosen) {
sendExistingDocument(chosen.document);
}, lifetime());
_composeControls->photoChosen(

View File

@ -1081,7 +1081,7 @@ void MainWidget::inlineResultLoadFailed(FileLoader *loader, bool started) {
}
bool MainWidget::sendExistingDocument(not_null<DocumentData*> document) {
return _history->sendExistingDocument(document);
return _history->sendExistingDocument(document, Api::SendOptions());
}
void MainWidget::dialogsCancelled() {