2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Show inline bot results in a separate widget.

Add a InlineBots::Layout::Widget for inline bot results.
GIF search from EmojiPan is disabled for now.
This commit is contained in:
John Preston
2017-03-27 21:11:51 +03:00
parent 5cb66c99bd
commit 3d846fcd49
19 changed files with 1616 additions and 287 deletions

View File

@@ -37,10 +37,10 @@ namespace InlineBots {
namespace Layout {
namespace internal {
FileBase::FileBase(Result *result) : ItemBase(result) {
FileBase::FileBase(gsl::not_null<Context*> context, Result *result) : ItemBase(context, result) {
}
FileBase::FileBase(DocumentData *document) : ItemBase(document) {
FileBase::FileBase(gsl::not_null<Context*> context, DocumentData *document) : ItemBase(context, document) {
}
DocumentData *FileBase::getShownDocument() const {
@@ -94,11 +94,13 @@ ImagePtr FileBase::content_thumb() const {
return getResultThumb();
}
Gif::Gif(Result *result) : FileBase(result) {
Gif::Gif(gsl::not_null<Context*> context, Result *result) : FileBase(context, result) {
}
Gif::Gif(DocumentData *document, bool hasDeleteButton) : FileBase(document)
, _delete(hasDeleteButton ? new DeleteSavedGifClickHandler(document) : nullptr) {
Gif::Gif(gsl::not_null<Context*> context, DocumentData *document, bool hasDeleteButton) : FileBase(context, document) {
if (hasDeleteButton) {
_delete = MakeShared<DeleteSavedGifClickHandler>(document);
}
}
void Gif::initDimensions() {
@@ -338,7 +340,7 @@ void Gif::clipCallback(Media::Clip::Notification notification) {
int32 height = st::inlineMediaHeight;
QSize frame = countFrameSize();
_gif->start(frame.width(), frame.height(), _width, height, ImageRoundRadius::None, ImageRoundCorner::None);
} else if (_gif->autoPausedGif() && !Ui::isInlineItemVisible(this)) {
} else if (_gif->autoPausedGif() && !context()->inlineItemVisible(this)) {
_gif.reset();
getShownDocument()->forget();
}
@@ -355,7 +357,7 @@ void Gif::clipCallback(Media::Clip::Notification notification) {
}
}
Sticker::Sticker(Result *result) : FileBase(result) {
Sticker::Sticker(gsl::not_null<Context*> context, Result *result) : FileBase(context, result) {
}
void Sticker::initDimensions() {
@@ -455,7 +457,7 @@ void Sticker::prepareThumb() const {
}
}
Photo::Photo(Result *result) : ItemBase(result) {
Photo::Photo(gsl::not_null<Context*> context, Result *result) : ItemBase(context, result) {
}
void Photo::initDimensions() {
@@ -551,7 +553,7 @@ void Photo::prepareThumb(int32 width, int32 height, const QSize &frame) const {
}
}
Video::Video(Result *result) : FileBase(result)
Video::Video(gsl::not_null<Context*> context, Result *result) : FileBase(context, result)
, _link(getResultContentUrlHandler())
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
@@ -668,11 +670,11 @@ void CancelFileClickHandler::onClickImpl() const {
_result->cancelFile();
}
File::File(Result *result) : FileBase(result)
File::File(gsl::not_null<Context*> context, Result *result) : FileBase(context, result)
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::msgFileSize - st::inlineThumbSkip)
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::msgFileSize - st::inlineThumbSkip)
, _open(new OpenFileClickHandler(result))
, _cancel(new CancelFileClickHandler(result)) {
, _open(MakeShared<OpenFileClickHandler>(result))
, _cancel(MakeShared<CancelFileClickHandler>(result)) {
updateStatusText();
regDocumentItem(getShownDocument(), this);
}
@@ -789,12 +791,12 @@ File::~File() {
}
void File::thumbAnimationCallback() {
Ui::repaintInlineItem(this);
update();
}
void File::step_radial(TimeMs ms, bool timer) {
if (timer) {
Ui::repaintInlineItem(this);
update();
} else {
DocumentData *document = getShownDocument();
_animation->radial.update(document->progress(), !document->loading() || document->loaded(), ms);
@@ -806,7 +808,7 @@ void File::step_radial(TimeMs ms, bool timer) {
void File::ensureAnimation() const {
if (!_animation) {
_animation.reset(new AnimationData(animation(const_cast<File*>(this), &File::step_radial)));
_animation = std::make_unique<AnimationData>(animation(const_cast<File*>(this), &File::step_radial));
}
}
@@ -877,7 +879,7 @@ void File::setStatusSize(int32 newSize, int32 fullSize, int32 duration, qint64 r
}
}
Contact::Contact(Result *result) : ItemBase(result)
Contact::Contact(gsl::not_null<Context*> context, Result *result) : ItemBase(context, result)
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
}
@@ -966,7 +968,7 @@ void Contact::prepareThumb(int width, int height) const {
}
}
Article::Article(Result *result, bool withThumb) : ItemBase(result)
Article::Article(gsl::not_null<Context*> context, Result *result, bool withThumb) : ItemBase(context, result)
, _url(getResultUrlHandler())
, _link(getResultContentUrlHandler())
, _withThumb(withThumb)
@@ -974,7 +976,7 @@ Article::Article(Result *result, bool withThumb) : ItemBase(result)
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
LocationCoords location;
if (!_link && result->getLocationCoords(&location)) {
_link.reset(new LocationClickHandler(location));
_link = MakeShared<LocationClickHandler>(location);
}
_thumbLetter = getResultThumbLetter();
}
@@ -1113,7 +1115,7 @@ void Article::prepareThumb(int width, int height) const {
}
}
Game::Game(Result *result) : ItemBase(result)
Game::Game(gsl::not_null<Context*> context, Result *result) : ItemBase(context, result)
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
countFrameSize();
@@ -1322,7 +1324,7 @@ void Game::clipCallback(Media::Clip::Notification notification) {
getResultDocument()->forget();
} else if (_gif->ready() && !_gif->started()) {
_gif->start(_frameSize.width(), _frameSize.height(), st::inlineThumbSize, st::inlineThumbSize, ImageRoundRadius::None, ImageRoundCorner::None);
} else if (_gif->autoPausedGif() && !Ui::isInlineItemVisible(this)) {
} else if (_gif->autoPausedGif() && !context()->inlineItemVisible(this)) {
_gif.reset();
getResultDocument()->forget();
}