2017-03-29 17:04:00 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-03-29 17:04:00 +03:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-08 18:20:12 +03:00
|
|
|
#include "chat_helpers/tabbed_selector.h"
|
2018-11-21 22:14:48 +04:00
|
|
|
#include "base/timer.h"
|
2017-03-31 18:50:02 +03:00
|
|
|
#include "inline_bots/inline_bot_layout_item.h"
|
2019-09-13 09:06:02 +03:00
|
|
|
#include "app.h"
|
|
|
|
|
|
|
|
#include <QtCore/QTimer>
|
2017-03-31 18:50:02 +03:00
|
|
|
|
|
|
|
namespace InlineBots {
|
|
|
|
namespace Layout {
|
|
|
|
class ItemBase;
|
|
|
|
} // namespace Layout
|
|
|
|
class Result;
|
|
|
|
} // namespace InlineBots
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
namespace Ui {
|
|
|
|
class RoundButton;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2017-04-07 21:10:49 +03:00
|
|
|
namespace Window {
|
2019-06-06 13:21:40 +03:00
|
|
|
class SessionController;
|
2017-04-07 21:10:49 +03:00
|
|
|
} // namespace Window
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
namespace ChatHelpers {
|
|
|
|
|
2017-11-05 21:07:27 +04:00
|
|
|
class GifsListWidget
|
|
|
|
: public TabbedSelector::Inner
|
|
|
|
, public InlineBots::Layout::Context
|
|
|
|
, private base::Subscriber
|
|
|
|
, private MTP::Sender {
|
2017-03-29 17:04:00 +03:00
|
|
|
public:
|
2018-11-21 22:14:48 +04:00
|
|
|
using InlineChosen = TabbedSelector::InlineChosen;
|
|
|
|
|
2019-06-06 13:21:40 +03:00
|
|
|
GifsListWidget(QWidget *parent, not_null<Window::SessionController*> controller);
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2018-11-21 22:14:48 +04:00
|
|
|
rpl::producer<not_null<DocumentData*>> fileChosen() const;
|
|
|
|
rpl::producer<not_null<PhotoData*>> photoChosen() const;
|
|
|
|
rpl::producer<InlineChosen> inlineResultChosen() const;
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void refreshRecent() override;
|
|
|
|
void preloadImages() override;
|
|
|
|
void clearSelection() override;
|
2017-04-08 18:20:12 +03:00
|
|
|
object_ptr<TabbedSelector::InnerFooter> createFooter() override;
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-03-31 18:50:02 +03:00
|
|
|
void inlineItemLayoutChanged(const InlineBots::Layout::ItemBase *layout) override;
|
|
|
|
void inlineItemRepaint(const InlineBots::Layout::ItemBase *layout) override;
|
|
|
|
bool inlineItemVisible(const InlineBots::Layout::ItemBase *layout) override;
|
2018-07-14 00:25:47 +03:00
|
|
|
Data::FileOrigin inlineItemFileOrigin() override;
|
2017-03-31 18:50:02 +03:00
|
|
|
|
|
|
|
void afterShown() override;
|
|
|
|
void beforeHiding() override;
|
|
|
|
|
|
|
|
void setInlineQueryPeer(PeerData *peer) {
|
|
|
|
_inlineQueryPeer = peer;
|
|
|
|
}
|
|
|
|
void searchForGifs(const QString &query);
|
|
|
|
void sendInlineRequest();
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2018-11-21 22:14:48 +04:00
|
|
|
void cancelled();
|
|
|
|
rpl::producer<> cancelRequests() const;
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
~GifsListWidget();
|
|
|
|
|
|
|
|
protected:
|
2017-09-13 19:57:44 +03:00
|
|
|
void visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) override;
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
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;
|
2017-03-29 18:09:16 +03:00
|
|
|
|
2017-04-08 18:20:12 +03:00
|
|
|
TabbedSelector::InnerFooter *getFooter() const override;
|
2017-03-29 18:09:16 +03:00
|
|
|
void processHideFinished() override;
|
|
|
|
void processPanelHideFinished() override;
|
2017-11-12 13:54:18 +04:00
|
|
|
int countDesiredHeight(int newWidth) override;
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
enum class Section {
|
|
|
|
Inlines,
|
|
|
|
Gifs,
|
|
|
|
};
|
2017-03-29 18:09:16 +03:00
|
|
|
class Footer;
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-03-31 18:50:02 +03:00
|
|
|
using InlineResult = InlineBots::Result;
|
|
|
|
using InlineResults = std::vector<std::unique_ptr<InlineResult>>;
|
|
|
|
using LayoutItem = InlineBots::Layout::ItemBase;
|
|
|
|
|
|
|
|
struct InlineCacheEntry {
|
|
|
|
QString nextOffset;
|
|
|
|
InlineResults results;
|
|
|
|
};
|
|
|
|
|
|
|
|
void cancelGifsSearch();
|
|
|
|
void switchToSavedGifs();
|
|
|
|
void refreshSavedGifs();
|
|
|
|
int refreshInlineRows(const InlineCacheEntry *results, bool resultsDeleted);
|
|
|
|
void checkLoadMore();
|
|
|
|
|
|
|
|
int32 showInlineRows(bool newResults);
|
|
|
|
bool refreshInlineRows(int32 *added = 0);
|
|
|
|
void inlineResultsDone(const MTPmessages_BotResults &result);
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void updateSelected();
|
|
|
|
void paintInlineItems(Painter &p, QRect clip);
|
|
|
|
|
2018-11-21 22:14:48 +04:00
|
|
|
void updateInlineItems();
|
|
|
|
void showPreview();
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
Section _section = Section::Gifs;
|
2019-02-19 10:57:53 +04:00
|
|
|
crl::time _lastScrolled = 0;
|
2018-11-21 22:14:48 +04:00
|
|
|
base::Timer _updateInlineItems;
|
2017-03-29 17:04:00 +03:00
|
|
|
bool _inlineWithThumb = false;
|
|
|
|
|
2017-03-31 18:50:02 +03:00
|
|
|
struct Row {
|
2017-11-12 13:54:18 +04:00
|
|
|
int maxWidth = 0;
|
2017-03-29 17:04:00 +03:00
|
|
|
int height = 0;
|
2017-03-31 18:50:02 +03:00
|
|
|
QVector<LayoutItem*> items;
|
2017-03-29 17:04:00 +03:00
|
|
|
};
|
2017-03-31 18:50:02 +03:00
|
|
|
QVector<Row> _rows;
|
2017-03-29 17:04:00 +03:00
|
|
|
void clearInlineRows(bool resultsDeleted);
|
|
|
|
|
2017-03-31 18:50:02 +03:00
|
|
|
std::map<DocumentData*, std::unique_ptr<LayoutItem>> _gifLayouts;
|
|
|
|
LayoutItem *layoutPrepareSavedGif(DocumentData *doc, int32 position);
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-03-31 18:50:02 +03:00
|
|
|
std::map<InlineResult*, std::unique_ptr<LayoutItem>> _inlineLayouts;
|
|
|
|
LayoutItem *layoutPrepareInlineResult(InlineResult *result, int32 position);
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-03-31 18:50:02 +03:00
|
|
|
bool inlineRowsAddItem(DocumentData *savedGif, InlineResult *result, Row &row, int32 &sumWidth);
|
|
|
|
bool inlineRowFinalize(Row &row, int32 &sumWidth, bool force = false);
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-11-12 13:54:18 +04:00
|
|
|
void layoutInlineRow(Row &row, int fullWidth);
|
2017-03-29 17:04:00 +03:00
|
|
|
void deleteUnusedGifLayouts();
|
|
|
|
|
|
|
|
void deleteUnusedInlineLayouts();
|
|
|
|
|
|
|
|
int validateExistingInlineRows(const InlineResults &results);
|
|
|
|
void selectInlineResult(int row, int column);
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
Footer *_footer = nullptr;
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
int _selected = -1;
|
|
|
|
int _pressed = -1;
|
|
|
|
QPoint _lastMousePos;
|
|
|
|
|
2018-11-21 22:14:48 +04:00
|
|
|
base::Timer _previewTimer;
|
2017-03-29 17:04:00 +03:00
|
|
|
bool _previewShown = false;
|
|
|
|
|
2017-03-31 18:50:02 +03:00
|
|
|
std::map<QString, std::unique_ptr<InlineCacheEntry>> _inlineCache;
|
|
|
|
QTimer _inlineRequestTimer;
|
|
|
|
|
|
|
|
UserData *_searchBot = nullptr;
|
|
|
|
mtpRequestId _searchBotRequestId = 0;
|
|
|
|
PeerData *_inlineQueryPeer = nullptr;
|
|
|
|
QString _inlineQuery, _inlineNextQuery, _inlineNextOffset;
|
|
|
|
mtpRequestId _inlineRequestId = 0;
|
|
|
|
|
2018-11-21 22:14:48 +04:00
|
|
|
rpl::event_stream<not_null<DocumentData*>> _fileChosen;
|
|
|
|
rpl::event_stream<not_null<PhotoData*>> _photoChosen;
|
|
|
|
rpl::event_stream<InlineChosen> _inlineResultChosen;
|
|
|
|
rpl::event_stream<> _cancelled;
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ChatHelpers
|