Added Api::SendOptions passing from TabbedSelector for inline results.

This commit is contained in:
23rd 2020-08-07 19:13:47 +03:00 committed by John Preston
parent 5b95585725
commit d1d153e886
9 changed files with 43 additions and 24 deletions

View File

@ -189,7 +189,8 @@ rpl::producer<TabbedSelector::FileChosen> GifsListWidget::fileChosen() const {
return _fileChosen.events();
}
rpl::producer<not_null<PhotoData*>> GifsListWidget::photoChosen() const {
auto GifsListWidget::photoChosen() const
-> rpl::producer<TabbedSelector::PhotoChosen> {
return _photoChosen.events();
}
@ -457,7 +458,9 @@ void GifsListWidget::selectInlineResult(
if (forceSend
|| (media && media->image(PhotoSize::Thumbnail))
|| (media && media->image(PhotoSize::Large))) {
_photoChosen.fire_copy(photo);
_photoChosen.fire_copy({
.photo = photo,
.options = options });
} else if (!photo->loading(PhotoSize::Thumbnail)) {
photo->load(PhotoSize::Thumbnail, Data::FileOrigin());
}
@ -479,7 +482,7 @@ void GifsListWidget::selectInlineResult(
}
} else if (const auto inlineResult = item->getResult()) {
if (inlineResult->onChoose(item)) {
_inlineResultChosen.fire({ inlineResult, _searchBot });
_inlineResultChosen.fire({ inlineResult, _searchBot, options });
}
}
}

View File

@ -50,7 +50,7 @@ public:
GifsListWidget(QWidget *parent, not_null<Window::SessionController*> controller);
rpl::producer<TabbedSelector::FileChosen> fileChosen() const;
rpl::producer<not_null<PhotoData*>> photoChosen() const;
rpl::producer<TabbedSelector::PhotoChosen> photoChosen() const;
rpl::producer<InlineChosen> inlineResultChosen() const;
void refreshRecent() override;
@ -196,7 +196,7 @@ private:
mtpRequestId _inlineRequestId = 0;
rpl::event_stream<TabbedSelector::FileChosen> _fileChosen;
rpl::event_stream<not_null<PhotoData*>> _photoChosen;
rpl::event_stream<TabbedSelector::PhotoChosen> _photoChosen;
rpl::event_stream<InlineChosen> _inlineResultChosen;
rpl::event_stream<> _cancelled;

View File

@ -417,7 +417,8 @@ rpl::producer<TabbedSelector::FileChosen> TabbedSelector::fileChosen() const {
: rpl::never<TabbedSelector::FileChosen>() | rpl::type_erased();
}
rpl::producer<not_null<PhotoData*>> TabbedSelector::photoChosen() const {
auto TabbedSelector::photoChosen() const
-> rpl::producer<TabbedSelector::PhotoChosen>{
return full() ? gifs()->photoChosen() : nullptr;
}

View File

@ -54,9 +54,14 @@ public:
not_null<DocumentData*> document;
Api::SendOptions options;
};
struct PhotoChosen {
not_null<PhotoData*> photo;
Api::SendOptions options;
};
struct InlineChosen {
not_null<InlineBots::Result*> result;
not_null<UserData*> bot;
Api::SendOptions options;
};
enum class Mode {
Full,
@ -73,7 +78,7 @@ public:
rpl::producer<EmojiPtr> emojiChosen() const;
rpl::producer<FileChosen> fileChosen() const;
rpl::producer<not_null<PhotoData*>> photoChosen() const;
rpl::producer<PhotoChosen> photoChosen() const;
rpl::producer<InlineChosen> inlineResultChosen() const;
rpl::producer<> cancelled() const;

View File

@ -825,15 +825,15 @@ void HistoryWidget::initTabbedSelector() {
selector->photoChosen(
) | rpl::filter([=] {
return !isHidden();
}) | rpl::start_with_next([=](not_null<PhotoData*> photo) {
sendExistingPhoto(photo);
}) | rpl::start_with_next([=](TabbedSelector::PhotoChosen data) {
sendExistingPhoto(data.photo, data.options);
}, lifetime());
selector->inlineResultChosen(
) | rpl::filter([=] {
return !isHidden();
}) | rpl::start_with_next([=](TabbedSelector::InlineChosen data) {
sendInlineResult(data.result, data.bot);
sendInlineResult(data.result, data.bot, data.options);
}, lifetime());
selector->setSendMenuType([=] { return sendMenuType(); });
@ -1200,7 +1200,7 @@ void HistoryWidget::applyInlineBotQuery(UserData *bot, const QString &query) {
_inlineResults->setResultSelectedCallback([=](
InlineBots::Result *result,
UserData *bot) {
sendInlineResult(result, bot);
sendInlineResult(result, bot, Api::SendOptions());
});
_inlineResults->requesting(
) | rpl::start_with_next([=](bool requesting) {
@ -5218,7 +5218,8 @@ void HistoryWidget::onFieldTabbed() {
void HistoryWidget::sendInlineResult(
not_null<InlineBots::Result*> result,
not_null<UserData*> bot) {
not_null<UserData*> bot,
Api::SendOptions options) {
if (!_peer || !_peer->canWrite()) {
return;
} else if (showSlowmodeError()) {
@ -5233,6 +5234,7 @@ void HistoryWidget::sendInlineResult(
auto action = Api::SendAction(_history);
action.replyTo = replyToId();
action.options = std::move(options);
action.generateLocal = true;
session().api().sendInlineResult(bot, result, action);
@ -5404,7 +5406,9 @@ bool HistoryWidget::sendExistingDocument(
return true;
}
bool HistoryWidget::sendExistingPhoto(not_null<PhotoData*> photo) {
bool HistoryWidget::sendExistingPhoto(
not_null<PhotoData*> photo,
Api::SendOptions options) {
const auto error = _peer
? Data::RestrictionError(_peer, ChatRestriction::f_send_media)
: std::nullopt;
@ -5419,6 +5423,7 @@ bool HistoryWidget::sendExistingPhoto(not_null<PhotoData*> photo) {
auto message = Api::MessageToSend(_history);
message.action.replyTo = replyToId();
message.action.options = std::move(options);
Api::SendExistingPhoto(std::move(message), photo);
hideSelectorControlsAnimated();

View File

@ -251,7 +251,9 @@ public:
bool sendExistingDocument(
not_null<DocumentData*> document,
Api::SendOptions options);
bool sendExistingPhoto(not_null<PhotoData*> photo);
bool sendExistingPhoto(
not_null<PhotoData*> photo,
Api::SendOptions options);
void showInfoTooltip(
const TextWithEntities &text,
@ -501,7 +503,8 @@ private:
void sendInlineResult(
not_null<InlineBots::Result*> result,
not_null<UserData*> bot);
not_null<UserData*> bot,
Api::SendOptions options);
void drawField(Painter &p, const QRect &rect);
void paintEditHeader(

View File

@ -40,6 +40,7 @@ namespace HistoryView {
namespace {
using FileChosen = ComposeControls::FileChosen;
using PhotoChosen = ComposeControls::PhotoChosen;
using MessageToEdit = ComposeControls::MessageToEdit;
constexpr auto kMouseEvent = {
@ -507,7 +508,7 @@ rpl::producer<FileChosen> ComposeControls::fileChosen() const {
return _fileChosen.events();
}
rpl::producer<not_null<PhotoData*>> ComposeControls::photoChosen() const {
rpl::producer<PhotoChosen> ComposeControls::photoChosen() const {
return _photoChosen.events();
}

View File

@ -55,6 +55,7 @@ class FieldHeader;
class ComposeControls final {
public:
using FileChosen = ChatHelpers::TabbedSelector::FileChosen;
using PhotoChosen = ChatHelpers::TabbedSelector::PhotoChosen;
enum class Mode {
Normal,
Scheduled,
@ -87,7 +88,7 @@ public:
[[nodiscard]] rpl::producer<MessageToEdit> editRequests() const;
[[nodiscard]] rpl::producer<> attachRequests() const;
[[nodiscard]] rpl::producer<FileChosen> fileChosen() const;
[[nodiscard]] rpl::producer<not_null<PhotoData*>> photoChosen() const;
[[nodiscard]] rpl::producer<PhotoChosen> photoChosen() const;
[[nodiscard]] rpl::producer<Data::MessagePosition> scrollRequests() const;
[[nodiscard]] rpl::producer<not_null<QKeyEvent*>> keyEvents() const;
[[nodiscard]] auto inlineResultChosen() const
@ -156,7 +157,7 @@ private:
rpl::event_stream<> _cancelRequests;
rpl::event_stream<FileChosen> _fileChosen;
rpl::event_stream<not_null<PhotoData*>> _photoChosen;
rpl::event_stream<PhotoChosen> _photoChosen;
rpl::event_stream<ChatHelpers::TabbedSelector::InlineChosen> _inlineResultChosen;
TextWithTags _localSavedText;

View File

@ -198,20 +198,20 @@ void ScheduledWidget::setupComposeControls() {
[=] { _choosingAttach = false; chooseAttach(); });
}, lifetime());
using Selector = ChatHelpers::TabbedSelector;
_composeControls->fileChosen(
) | rpl::start_with_next([=](
ChatHelpers::TabbedSelector::FileChosen chosen) {
) | rpl::start_with_next([=](Selector::FileChosen chosen) {
sendExistingDocument(chosen.document);
}, lifetime());
_composeControls->photoChosen(
) | rpl::start_with_next([=](not_null<PhotoData*> photo) {
sendExistingPhoto(photo);
) | rpl::start_with_next([=](Selector::PhotoChosen chosen) {
sendExistingPhoto(chosen.photo);
}, lifetime());
_composeControls->inlineResultChosen(
) | rpl::start_with_next([=](
ChatHelpers::TabbedSelector::InlineChosen chosen) {
) | rpl::start_with_next([=](Selector::InlineChosen chosen) {
sendInlineResult(chosen.result, chosen.bot);
}, lifetime());