mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 22:54:01 +02:00
Added ability to show content from Controller for inline results.
This commit is contained in:
parent
583c3d3429
commit
7885be4a94
12 changed files with 60 additions and 43 deletions
|
@ -1265,7 +1265,16 @@ void HistoryWidget::applyInlineBotQuery(UserData *bot, const QString &query) {
|
|||
_inlineResults.create(this, controller());
|
||||
_inlineResults->setResultSelectedCallback([=](
|
||||
InlineBots::ResultSelected result) {
|
||||
sendInlineResult(result);
|
||||
if (result.open) {
|
||||
const auto request = result.result->openRequest();
|
||||
if (const auto photo = request.photo()) {
|
||||
controller()->openPhoto(photo, FullMsgId());
|
||||
} else if (const auto document = request.document()) {
|
||||
controller()->openDocument(document, FullMsgId());
|
||||
}
|
||||
} else {
|
||||
sendInlineResult(result);
|
||||
}
|
||||
});
|
||||
_inlineResults->setCurrentDialogsEntryState(
|
||||
computeDialogsEntryState());
|
||||
|
|
|
@ -2394,7 +2394,16 @@ void ComposeControls::applyInlineBotQuery(
|
|||
_currentDialogsEntryState);
|
||||
_inlineResults->setResultSelectedCallback([=](
|
||||
InlineBots::ResultSelected result) {
|
||||
_inlineResultChosen.fire_copy(result);
|
||||
if (result.open) {
|
||||
const auto request = result.result->openRequest();
|
||||
if (const auto photo = request.photo()) {
|
||||
_window->openPhoto(photo, FullMsgId());
|
||||
} else if (const auto document = request.document()) {
|
||||
_window->openDocument(document, FullMsgId());
|
||||
}
|
||||
} else {
|
||||
_inlineResultChosen.fire_copy(result);
|
||||
}
|
||||
});
|
||||
_inlineResults->setSendMenuType([=] { return sendMenuType(); });
|
||||
_inlineResults->requesting(
|
||||
|
|
|
@ -812,10 +812,6 @@ void Video::prepareThumbnail(QSize size) const {
|
|||
}
|
||||
}
|
||||
|
||||
void OpenFileClickHandler::onClickImpl() const {
|
||||
_result->openFile();
|
||||
}
|
||||
|
||||
void CancelFileClickHandler::onClickImpl() const {
|
||||
_result->cancelFile();
|
||||
}
|
||||
|
@ -824,7 +820,6 @@ File::File(not_null<Context*> context, not_null<Result*> result)
|
|||
: FileBase(context, result)
|
||||
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineFileSize - st::inlineThumbSkip)
|
||||
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineFileSize - st::inlineThumbSkip)
|
||||
, _open(std::make_shared<OpenFileClickHandler>(result))
|
||||
, _cancel(std::make_shared<CancelFileClickHandler>(result))
|
||||
, _document(getShownDocument()) {
|
||||
Expects(getResultDocument() != nullptr);
|
||||
|
|
|
@ -246,19 +246,6 @@ private:
|
|||
|
||||
};
|
||||
|
||||
class OpenFileClickHandler : public LeftButtonClickHandler {
|
||||
public:
|
||||
OpenFileClickHandler(not_null<Result*> result) : _result(result) {
|
||||
}
|
||||
|
||||
protected:
|
||||
void onClickImpl() const override;
|
||||
|
||||
private:
|
||||
not_null<Result*> _result;
|
||||
|
||||
};
|
||||
|
||||
class CancelFileClickHandler : public LeftButtonClickHandler {
|
||||
public:
|
||||
CancelFileClickHandler(not_null<Result*> result) : _result(result) {
|
||||
|
@ -328,7 +315,7 @@ private:
|
|||
mutable std::unique_ptr<AnimationData> _animation;
|
||||
|
||||
Ui::Text::String _title, _description;
|
||||
ClickHandlerPtr _open, _cancel;
|
||||
ClickHandlerPtr _cancel;
|
||||
|
||||
// >= 0 will contain download / upload string, _statusSize = loaded bytes
|
||||
// < 0 will contain played string, _statusSize = -(seconds + 1) played
|
||||
|
|
|
@ -199,10 +199,9 @@ ClickHandlerPtr ItemBase::getResultPreviewHandler() const {
|
|||
false);
|
||||
} else if (const auto document = _result->_document
|
||||
&& _result->_document->createMediaView()->canBePlayed()) {
|
||||
return std::make_shared<DocumentOpenClickHandler>(
|
||||
_result->_document);
|
||||
return std::make_shared<OpenFileClickHandler>();
|
||||
} else if (_result->_photo) {
|
||||
return std::make_shared<PhotoOpenClickHandler>(_result->_photo);
|
||||
return std::make_shared<OpenFileClickHandler>();
|
||||
}
|
||||
return ClickHandlerPtr();
|
||||
}
|
||||
|
|
|
@ -42,6 +42,12 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class OpenFileClickHandler : public ClickHandler {
|
||||
public:
|
||||
void onClick(ClickContext context) const override {
|
||||
}
|
||||
};
|
||||
|
||||
class Context {
|
||||
public:
|
||||
virtual void inlineItemLayoutChanged(const ItemBase *layout) = 0;
|
||||
|
@ -131,6 +137,7 @@ protected:
|
|||
PhotoData *_photo = nullptr;
|
||||
|
||||
ClickHandlerPtr _send = ClickHandlerPtr{ new SendClickHandler() };
|
||||
ClickHandlerPtr _open = ClickHandlerPtr{ new OpenFileClickHandler() };
|
||||
|
||||
int _position = 0; // < 0 means removed from layout
|
||||
|
||||
|
|
|
@ -331,12 +331,13 @@ bool Result::onChoose(Layout::ItemBase *layout) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Result::openFile() {
|
||||
Media::View::OpenRequest Result::openRequest() {
|
||||
if (_document) {
|
||||
DocumentOpenClickHandler(_document).onClick({});
|
||||
return Media::View::OpenRequest(_document, nullptr);
|
||||
} else if (_photo) {
|
||||
PhotoOpenClickHandler(_photo).onClick({});
|
||||
return Media::View::OpenRequest(_photo, nullptr);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void Result::cancelFile() {
|
||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "data/data_cloud_file.h"
|
||||
#include "api/api_common.h"
|
||||
#include "media/view/media_view_open_common.h"
|
||||
|
||||
class FileLoader;
|
||||
class History;
|
||||
|
@ -54,7 +55,7 @@ public:
|
|||
// inline bot result. If it returns true you need to send this result.
|
||||
bool onChoose(Layout::ItemBase *layout);
|
||||
|
||||
void openFile();
|
||||
Media::View::OpenRequest openRequest();
|
||||
void cancelFile();
|
||||
|
||||
bool hasThumbDisplay() const;
|
||||
|
@ -131,6 +132,8 @@ struct ResultSelected {
|
|||
not_null<Result*> result;
|
||||
not_null<UserData*> bot;
|
||||
Api::SendOptions options;
|
||||
// Open in OverlayWidget;
|
||||
bool open = false;
|
||||
};
|
||||
|
||||
} // namespace InlineBots
|
||||
|
|
|
@ -236,22 +236,22 @@ void Inner::mouseReleaseEvent(QMouseEvent *e) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (dynamic_cast<InlineBots::Layout::SendClickHandler*>(activated.get())) {
|
||||
int row = _selected / MatrixRowShift, column = _selected % MatrixRowShift;
|
||||
selectInlineResult(row, column);
|
||||
using namespace InlineBots::Layout;
|
||||
const auto open = dynamic_cast<OpenFileClickHandler*>(activated.get());
|
||||
if (dynamic_cast<SendClickHandler*>(activated.get()) || open) {
|
||||
const auto row = int(_selected / MatrixRowShift);
|
||||
const auto column = int(_selected % MatrixRowShift);
|
||||
selectInlineResult(row, column, {}, !!open);
|
||||
} else {
|
||||
ActivateClickHandler(window(), activated, e->button());
|
||||
}
|
||||
}
|
||||
|
||||
void Inner::selectInlineResult(int row, int column) {
|
||||
selectInlineResult(row, column, Api::SendOptions());
|
||||
}
|
||||
|
||||
void Inner::selectInlineResult(
|
||||
int row,
|
||||
int column,
|
||||
Api::SendOptions options) {
|
||||
Api::SendOptions options,
|
||||
bool open) {
|
||||
if (row >= _rows.size() || column >= _rows.at(row).items.size()) {
|
||||
return;
|
||||
}
|
||||
|
@ -262,7 +262,8 @@ void Inner::selectInlineResult(
|
|||
_resultSelectedCallback({
|
||||
.result = inlineResult,
|
||||
.bot = _inlineBot,
|
||||
.options = std::move(options)
|
||||
.options = std::move(options),
|
||||
.open = open,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -300,7 +301,7 @@ void Inner::contextMenuEvent(QContextMenuEvent *e) {
|
|||
_menu = base::make_unique_q<Ui::PopupMenu>(this);
|
||||
|
||||
const auto send = [=](Api::SendOptions options) {
|
||||
selectInlineResult(row, column, options);
|
||||
selectInlineResult(row, column, options, false);
|
||||
};
|
||||
SendMenu::FillSendMenu(
|
||||
_menu,
|
||||
|
|
|
@ -147,8 +147,11 @@ private:
|
|||
void deleteUnusedInlineLayouts();
|
||||
|
||||
int validateExistingInlineRows(const Results &results);
|
||||
void selectInlineResult(int row, int column);
|
||||
void selectInlineResult(int row, int column, Api::SendOptions options);
|
||||
void selectInlineResult(
|
||||
int row,
|
||||
int column,
|
||||
Api::SendOptions options,
|
||||
bool open);
|
||||
|
||||
not_null<Window::SessionController*> _controller;
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@ namespace Media::View {
|
|||
|
||||
struct OpenRequest {
|
||||
public:
|
||||
OpenRequest() {
|
||||
}
|
||||
|
||||
OpenRequest(not_null<PhotoData*> photo, HistoryItem *item)
|
||||
: _photo(photo)
|
||||
, _item(item) {
|
||||
|
|
|
@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/history_view_replies_section.h"
|
||||
#include "media/player/media_player_instance.h"
|
||||
#include "media/view/media_view_open_common.h"
|
||||
#include "data/data_document_resolver.h"
|
||||
#include "data/data_media_types.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_folder.h"
|
||||
|
@ -1235,9 +1236,8 @@ void SessionController::openPhoto(
|
|||
void SessionController::openDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId contextId) {
|
||||
_window->openInMediaView(Media::View::OpenRequest(
|
||||
document,
|
||||
session().data().message(contextId)));
|
||||
// TEMP.
|
||||
Data::ResolveDocument(document, session().data().message(contextId));
|
||||
}
|
||||
|
||||
SessionController::~SessionController() = default;
|
||||
|
|
Loading…
Add table
Reference in a new issue