2020-11-12 15:46:17 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ui/rp_widget.h"
|
|
|
|
#include "ui/abstract_button.h"
|
|
|
|
#include "ui/widgets/tooltip.h"
|
|
|
|
#include "ui/effects/animations.h"
|
|
|
|
#include "ui/effects/panel_animation.h"
|
|
|
|
#include "dialogs/dialogs_key.h"
|
|
|
|
#include "base/timer.h"
|
|
|
|
#include "mtproto/sender.h"
|
|
|
|
#include "inline_bots/inline_bot_layout_item.h"
|
2021-07-26 00:25:33 +00:00
|
|
|
#include "layout/layout_mosaic.h"
|
2020-11-12 15:46:17 +00:00
|
|
|
|
|
|
|
namespace Api {
|
|
|
|
struct SendOptions;
|
|
|
|
} // namespace Api
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class ScrollArea;
|
|
|
|
class IconButton;
|
|
|
|
class LinkButton;
|
|
|
|
class RoundButton;
|
|
|
|
class FlatLabel;
|
|
|
|
class RippleAnimation;
|
|
|
|
class PopupMenu;
|
2021-07-02 15:29:13 +00:00
|
|
|
class PathShiftGradient;
|
2020-11-12 15:46:17 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
|
|
|
namespace Window {
|
|
|
|
class SessionController;
|
|
|
|
} // namespace Window
|
|
|
|
|
|
|
|
namespace InlineBots {
|
|
|
|
class Result;
|
|
|
|
struct ResultSelected;
|
|
|
|
} // namespace InlineBots
|
|
|
|
|
2020-11-19 02:58:23 +00:00
|
|
|
namespace SendMenu {
|
|
|
|
enum class Type;
|
|
|
|
} // namespace SendMenu
|
|
|
|
|
2020-11-12 15:46:17 +00:00
|
|
|
namespace InlineBots {
|
|
|
|
namespace Layout {
|
|
|
|
|
|
|
|
class ItemBase;
|
|
|
|
using Results = std::vector<std::unique_ptr<Result>>;
|
|
|
|
|
|
|
|
struct CacheEntry {
|
|
|
|
QString nextOffset;
|
2023-03-01 13:27:13 +00:00
|
|
|
QString switchPmText;
|
|
|
|
QString switchPmStartToken;
|
|
|
|
QByteArray switchPmUrl;
|
2020-11-12 15:46:17 +00:00
|
|
|
Results results;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Inner
|
|
|
|
: public Ui::RpWidget
|
|
|
|
, public Ui::AbstractTooltipShower
|
2021-05-25 10:35:38 +00:00
|
|
|
, public Context {
|
2020-11-12 15:46:17 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
Inner(QWidget *parent, not_null<Window::SessionController*> controller);
|
|
|
|
|
|
|
|
void hideFinished();
|
|
|
|
|
|
|
|
void clearSelection();
|
|
|
|
|
|
|
|
int refreshInlineRows(PeerData *queryPeer, UserData *bot, const CacheEntry *results, bool resultsDeleted);
|
|
|
|
void inlineBotChanged();
|
|
|
|
void hideInlineRowsPanel();
|
|
|
|
void clearInlineRowsPanel();
|
|
|
|
|
|
|
|
void preloadImages();
|
|
|
|
|
|
|
|
void inlineItemLayoutChanged(const ItemBase *layout) override;
|
|
|
|
void inlineItemRepaint(const ItemBase *layout) override;
|
|
|
|
bool inlineItemVisible(const ItemBase *layout) override;
|
|
|
|
Data::FileOrigin inlineItemFileOrigin() override;
|
|
|
|
|
|
|
|
int countHeight();
|
|
|
|
|
|
|
|
void setResultSelectedCallback(Fn<void(ResultSelected)> callback) {
|
|
|
|
_resultSelectedCallback = std::move(callback);
|
|
|
|
}
|
2020-11-19 02:58:23 +00:00
|
|
|
void setSendMenuType(Fn<SendMenu::Type()> &&callback);
|
2020-11-12 15:46:17 +00:00
|
|
|
|
|
|
|
// Ui::AbstractTooltipShower interface.
|
|
|
|
QString tooltipText() const override;
|
|
|
|
QPoint tooltipPos() const override;
|
|
|
|
bool tooltipWindowActive() const override;
|
|
|
|
|
|
|
|
rpl::producer<> inlineRowsCleared() const;
|
|
|
|
|
|
|
|
~Inner();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) override;
|
|
|
|
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
|
|
|
void leaveToChildEvent(QEvent *e, QWidget *child) override;
|
|
|
|
void enterFromChildEvent(QEvent *e, QWidget *child) override;
|
|
|
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
static constexpr bool kRefreshIconsScrollAnimation = true;
|
|
|
|
static constexpr bool kRefreshIconsNoAnimation = false;
|
|
|
|
|
|
|
|
void switchPm();
|
|
|
|
|
|
|
|
void updateSelected();
|
|
|
|
void checkRestrictedPeer();
|
|
|
|
bool isRestrictedView();
|
|
|
|
void clearHeavyData();
|
|
|
|
|
|
|
|
void paintInlineItems(Painter &p, const QRect &r);
|
|
|
|
|
|
|
|
void refreshSwitchPmButton(const CacheEntry *entry);
|
2021-07-26 00:25:33 +00:00
|
|
|
void refreshMosaicOffset();
|
2020-11-12 15:46:17 +00:00
|
|
|
|
|
|
|
void showPreview();
|
|
|
|
void updateInlineItems();
|
2022-01-25 09:51:57 +00:00
|
|
|
void repaintItems(crl::time now = 0);
|
2020-11-12 15:46:17 +00:00
|
|
|
void clearInlineRows(bool resultsDeleted);
|
2021-07-21 22:47:56 +00:00
|
|
|
ItemBase *layoutPrepareInlineResult(Result *result);
|
2020-11-12 15:46:17 +00:00
|
|
|
|
|
|
|
void deleteUnusedInlineLayouts();
|
|
|
|
|
|
|
|
int validateExistingInlineRows(const Results &results);
|
2021-06-14 06:21:56 +00:00
|
|
|
void selectInlineResult(
|
2021-07-21 22:47:56 +00:00
|
|
|
int index,
|
2021-06-14 06:21:56 +00:00
|
|
|
Api::SendOptions options,
|
|
|
|
bool open);
|
2020-11-12 15:46:17 +00:00
|
|
|
|
|
|
|
not_null<Window::SessionController*> _controller;
|
2021-07-02 15:29:13 +00:00
|
|
|
const std::unique_ptr<Ui::PathShiftGradient> _pathGradient;
|
2020-11-12 15:46:17 +00:00
|
|
|
|
|
|
|
int _visibleTop = 0;
|
|
|
|
int _visibleBottom = 0;
|
|
|
|
|
|
|
|
UserData *_inlineBot = nullptr;
|
|
|
|
PeerData *_inlineQueryPeer = nullptr;
|
2022-01-25 09:51:57 +00:00
|
|
|
crl::time _lastScrolledAt = 0;
|
|
|
|
crl::time _lastUpdatedAt = 0;
|
2020-11-12 15:46:17 +00:00
|
|
|
base::Timer _updateInlineItems;
|
|
|
|
bool _inlineWithThumb = false;
|
|
|
|
|
|
|
|
object_ptr<Ui::RoundButton> _switchPmButton = { nullptr };
|
|
|
|
QString _switchPmStartToken;
|
2023-03-01 13:27:13 +00:00
|
|
|
QByteArray _switchPmUrl;
|
2020-11-12 15:46:17 +00:00
|
|
|
|
|
|
|
object_ptr<Ui::FlatLabel> _restrictedLabel = { nullptr };
|
|
|
|
|
|
|
|
base::unique_qptr<Ui::PopupMenu> _menu;
|
|
|
|
|
2021-07-26 00:25:33 +00:00
|
|
|
Mosaic::Layout::MosaicLayout<InlineBots::Layout::ItemBase> _mosaic;
|
2020-11-12 15:46:17 +00:00
|
|
|
|
|
|
|
std::map<Result*, std::unique_ptr<ItemBase>> _inlineLayouts;
|
|
|
|
|
|
|
|
rpl::event_stream<> _inlineRowsCleared;
|
|
|
|
|
|
|
|
int _selected = -1;
|
|
|
|
int _pressed = -1;
|
|
|
|
QPoint _lastMousePos;
|
|
|
|
|
|
|
|
base::Timer _previewTimer;
|
|
|
|
bool _previewShown = false;
|
|
|
|
|
|
|
|
Fn<void(ResultSelected)> _resultSelectedCallback;
|
2020-11-19 02:58:23 +00:00
|
|
|
Fn<SendMenu::Type()> _sendMenuType;
|
2020-11-12 15:46:17 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Layout
|
|
|
|
} // namespace InlineBots
|