Send paid stickers/gifs/inline-results.
This commit is contained in:
@@ -49,8 +49,8 @@ constexpr auto kMaxInlineArea = 1280 * 720;
|
||||
return dimensions.width() * dimensions.height() <= kMaxInlineArea;
|
||||
}
|
||||
|
||||
FileBase::FileBase(not_null<Context*> context, not_null<Result*> result)
|
||||
: ItemBase(context, result) {
|
||||
FileBase::FileBase(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||
: ItemBase(context, std::move(result)) {
|
||||
}
|
||||
|
||||
FileBase::FileBase(
|
||||
@@ -95,8 +95,8 @@ int FileBase::content_duration() const {
|
||||
return getResultDuration();
|
||||
}
|
||||
|
||||
Gif::Gif(not_null<Context*> context, not_null<Result*> result)
|
||||
: FileBase(context, result) {
|
||||
Gif::Gif(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||
: FileBase(context, std::move(result)) {
|
||||
Expects(getResultDocument() != nullptr);
|
||||
}
|
||||
|
||||
@@ -442,8 +442,8 @@ void Gif::clipCallback(Media::Clip::Notification notification) {
|
||||
}
|
||||
}
|
||||
|
||||
Sticker::Sticker(not_null<Context*> context, not_null<Result*> result)
|
||||
: FileBase(context, result) {
|
||||
Sticker::Sticker(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||
: FileBase(context, std::move(result)) {
|
||||
Expects(getResultDocument() != nullptr);
|
||||
}
|
||||
|
||||
@@ -654,8 +654,8 @@ void Sticker::clipCallback(Media::Clip::Notification notification) {
|
||||
update();
|
||||
}
|
||||
|
||||
Photo::Photo(not_null<Context*> context, not_null<Result*> result)
|
||||
: ItemBase(context, result) {
|
||||
Photo::Photo(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||
: ItemBase(context, std::move(result)) {
|
||||
Expects(getShownPhoto() != nullptr);
|
||||
}
|
||||
|
||||
@@ -769,8 +769,8 @@ void Photo::prepareThumbnail(QSize size, QSize frame) const {
|
||||
validateThumbnail(_photoMedia->thumbnailInline(), size, frame, false);
|
||||
}
|
||||
|
||||
Video::Video(not_null<Context*> context, not_null<Result*> result)
|
||||
: FileBase(context, result)
|
||||
Video::Video(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||
: FileBase(context, std::move(result))
|
||||
, _link(getResultPreviewHandler())
|
||||
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
|
||||
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
|
||||
@@ -925,11 +925,11 @@ void CancelFileClickHandler::onClickImpl() const {
|
||||
_result->cancelFile();
|
||||
}
|
||||
|
||||
File::File(not_null<Context*> context, not_null<Result*> result)
|
||||
: FileBase(context, result)
|
||||
File::File(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||
: FileBase(context, std::move(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)
|
||||
, _cancel(std::make_shared<CancelFileClickHandler>(result))
|
||||
, _cancel(std::make_shared<CancelFileClickHandler>(_result.get()))
|
||||
, _document(getShownDocument()) {
|
||||
Expects(getResultDocument() != nullptr);
|
||||
|
||||
@@ -1173,8 +1173,8 @@ void File::setStatusSize(
|
||||
}
|
||||
}
|
||||
|
||||
Contact::Contact(not_null<Context*> context, not_null<Result*> result)
|
||||
: ItemBase(context, result)
|
||||
Contact::Contact(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||
: ItemBase(context, std::move(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) {
|
||||
}
|
||||
@@ -1265,16 +1265,16 @@ void Contact::prepareThumbnail(int width, int height) const {
|
||||
|
||||
Article::Article(
|
||||
not_null<Context*> context,
|
||||
not_null<Result*> result,
|
||||
std::shared_ptr<Result> result,
|
||||
bool withThumb)
|
||||
: ItemBase(context, result)
|
||||
: ItemBase(context, std::move(result))
|
||||
, _url(getResultUrlHandler())
|
||||
, _link(getResultPreviewHandler())
|
||||
, _withThumb(withThumb)
|
||||
, _title(st::emojiPanWidth / 2)
|
||||
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
|
||||
if (!_link) {
|
||||
if (const auto point = result->getLocationPoint()) {
|
||||
if (const auto point = _result->getLocationPoint()) {
|
||||
_link = std::make_shared<LocationClickHandler>(*point);
|
||||
}
|
||||
}
|
||||
@@ -1300,7 +1300,7 @@ void Article::initDimensions() {
|
||||
_minh += st::inlineRowMargin * 2 + st::inlineRowBorder;
|
||||
}
|
||||
|
||||
int32 Article::resizeGetHeight(int32 width) {
|
||||
int Article::resizeGetHeight(int width) {
|
||||
_width = qMin(width, _maxw);
|
||||
if (_url) {
|
||||
_urlText = getResultUrl();
|
||||
@@ -1422,8 +1422,8 @@ void Article::prepareThumbnail(int width, int height) const {
|
||||
});
|
||||
}
|
||||
|
||||
Game::Game(not_null<Context*> context, not_null<Result*> result)
|
||||
: ItemBase(context, result)
|
||||
Game::Game(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||
: ItemBase(context, std::move(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();
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace internal {
|
||||
|
||||
class FileBase : public ItemBase {
|
||||
public:
|
||||
FileBase(not_null<Context*> context, not_null<Result*> result);
|
||||
FileBase(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||
|
||||
// For saved gif layouts.
|
||||
FileBase(not_null<Context*> context, not_null<DocumentData*> document);
|
||||
@@ -58,7 +58,7 @@ private:
|
||||
|
||||
class Gif final : public FileBase {
|
||||
public:
|
||||
Gif(not_null<Context*> context, not_null<Result*> result);
|
||||
Gif(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||
Gif(
|
||||
not_null<Context*> context,
|
||||
not_null<DocumentData*> document,
|
||||
@@ -138,7 +138,7 @@ private:
|
||||
|
||||
class Photo : public ItemBase {
|
||||
public:
|
||||
Photo(not_null<Context*> context, not_null<Result*> result);
|
||||
Photo(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||
// Not used anywhere currently.
|
||||
//Photo(not_null<Context*> context, not_null<PhotoData*> photo);
|
||||
|
||||
@@ -178,7 +178,7 @@ private:
|
||||
|
||||
class Sticker : public FileBase {
|
||||
public:
|
||||
Sticker(not_null<Context*> context, not_null<Result*> result);
|
||||
Sticker(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||
~Sticker();
|
||||
// Not used anywhere currently.
|
||||
//Sticker(not_null<Context*> context, not_null<DocumentData*> document);
|
||||
@@ -229,7 +229,7 @@ private:
|
||||
|
||||
class Video : public FileBase {
|
||||
public:
|
||||
Video(not_null<Context*> context, not_null<Result*> result);
|
||||
Video(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||
|
||||
void initDimensions() override;
|
||||
|
||||
@@ -269,7 +269,7 @@ private:
|
||||
|
||||
class File : public FileBase {
|
||||
public:
|
||||
File(not_null<Context*> context, not_null<Result*> result);
|
||||
File(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||
~File();
|
||||
|
||||
void initDimensions() override;
|
||||
@@ -347,7 +347,7 @@ private:
|
||||
|
||||
class Contact : public ItemBase {
|
||||
public:
|
||||
Contact(not_null<Context*> context, not_null<Result*> result);
|
||||
Contact(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||
|
||||
void initDimensions() override;
|
||||
|
||||
@@ -366,7 +366,10 @@ private:
|
||||
|
||||
class Article : public ItemBase {
|
||||
public:
|
||||
Article(not_null<Context*> context, not_null<Result*> result, bool withThumb);
|
||||
Article(
|
||||
not_null<Context*> context,
|
||||
std::shared_ptr<Result> result,
|
||||
bool withThumb);
|
||||
|
||||
void initDimensions() override;
|
||||
int resizeGetHeight(int width) override;
|
||||
@@ -391,7 +394,7 @@ private:
|
||||
|
||||
class Game : public ItemBase {
|
||||
public:
|
||||
Game(not_null<Context*> context, not_null<Result*> result);
|
||||
Game(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||
|
||||
void setPosition(int32 position) override;
|
||||
void initDimensions() override;
|
||||
|
||||
@@ -29,7 +29,7 @@ base::NeverFreedPointer<DocumentItems> documentItemsMap;
|
||||
|
||||
} // namespace
|
||||
|
||||
Result *ItemBase::getResult() const {
|
||||
std::shared_ptr<Result> ItemBase::getResult() const {
|
||||
return _result;
|
||||
}
|
||||
|
||||
@@ -92,33 +92,37 @@ void ItemBase::layoutChanged() {
|
||||
|
||||
std::unique_ptr<ItemBase> ItemBase::createLayout(
|
||||
not_null<Context*> context,
|
||||
not_null<Result*> result,
|
||||
std::shared_ptr<Result> result,
|
||||
bool forceThumb) {
|
||||
using Type = Result::Type;
|
||||
|
||||
switch (result->_type) {
|
||||
case Type::Photo:
|
||||
return std::make_unique<internal::Photo>(context, result);
|
||||
return std::make_unique<internal::Photo>(context, std::move(result));
|
||||
case Type::Audio:
|
||||
case Type::File:
|
||||
return std::make_unique<internal::File>(context, result);
|
||||
return std::make_unique<internal::File>(context, std::move(result));
|
||||
case Type::Video:
|
||||
return std::make_unique<internal::Video>(context, result);
|
||||
return std::make_unique<internal::Video>(context, std::move(result));
|
||||
case Type::Sticker:
|
||||
return std::make_unique<internal::Sticker>(context, result);
|
||||
return std::make_unique<internal::Sticker>(
|
||||
context,
|
||||
std::move(result));
|
||||
case Type::Gif:
|
||||
return std::make_unique<internal::Gif>(context, result);
|
||||
return std::make_unique<internal::Gif>(context, std::move(result));
|
||||
case Type::Article:
|
||||
case Type::Geo:
|
||||
case Type::Venue:
|
||||
return std::make_unique<internal::Article>(
|
||||
context,
|
||||
result,
|
||||
std::move(result),
|
||||
forceThumb);
|
||||
case Type::Game:
|
||||
return std::make_unique<internal::Game>(context, result);
|
||||
return std::make_unique<internal::Game>(context, std::move(result));
|
||||
case Type::Contact:
|
||||
return std::make_unique<internal::Contact>(context, result);
|
||||
return std::make_unique<internal::Contact>(
|
||||
context,
|
||||
std::move(result));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
|
||||
class ItemBase : public LayoutItemBase {
|
||||
public:
|
||||
ItemBase(not_null<Context*> context, not_null<Result*> result)
|
||||
ItemBase(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||
: _result(result)
|
||||
, _context(context) {
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
Result *getResult() const;
|
||||
std::shared_ptr<Result> getResult() const;
|
||||
DocumentData *getDocument() const;
|
||||
PhotoData *getPhoto() const;
|
||||
|
||||
@@ -112,7 +112,7 @@ public:
|
||||
|
||||
static std::unique_ptr<ItemBase> createLayout(
|
||||
not_null<Context*> context,
|
||||
not_null<Result*> result,
|
||||
std::shared_ptr<Result> result,
|
||||
bool forceThumb);
|
||||
static std::unique_ptr<ItemBase> createLayoutGif(
|
||||
not_null<Context*> context,
|
||||
@@ -135,7 +135,7 @@ protected:
|
||||
}
|
||||
Data::FileOrigin fileOrigin() const;
|
||||
|
||||
Result *_result = nullptr;
|
||||
std::shared_ptr<Result> _result;
|
||||
DocumentData *_document = nullptr;
|
||||
PhotoData *_photo = nullptr;
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ Result::Result(not_null<Main::Session*> session, const Creator &creator)
|
||||
, _type(creator.type) {
|
||||
}
|
||||
|
||||
std::unique_ptr<Result> Result::Create(
|
||||
std::shared_ptr<Result> Result::Create(
|
||||
not_null<Main::Session*> session,
|
||||
uint64 queryId,
|
||||
const MTPBotInlineResult &data) {
|
||||
@@ -84,7 +84,7 @@ std::unique_ptr<Result> Result::Create(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto result = std::make_unique<Result>(
|
||||
auto result = std::make_shared<Result>(
|
||||
session,
|
||||
Creator{ queryId, type });
|
||||
const auto message = data.match([&](const MTPDbotInlineResult &data) {
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
// You should use create() static method instead.
|
||||
Result(not_null<Main::Session*> session, const Creator &creator);
|
||||
|
||||
static std::unique_ptr<Result> Create(
|
||||
static std::shared_ptr<Result> Create(
|
||||
not_null<Main::Session*> session,
|
||||
uint64 queryId,
|
||||
const MTPBotInlineResult &mtpData);
|
||||
@@ -130,7 +130,7 @@ private:
|
||||
};
|
||||
|
||||
struct ResultSelected {
|
||||
not_null<Result*> result;
|
||||
std::shared_ptr<Result> result;
|
||||
not_null<UserData*> bot;
|
||||
PeerData *recipientOverride = nullptr;
|
||||
Api::SendOptions options;
|
||||
|
||||
@@ -331,7 +331,7 @@ void Inner::selectInlineResult(
|
||||
if (const auto inlineResult = item->getResult()) {
|
||||
if (inlineResult->onChoose(item)) {
|
||||
_resultSelectedCallback({
|
||||
.result = inlineResult,
|
||||
.result = std::move(inlineResult),
|
||||
.bot = _inlineBot,
|
||||
.options = std::move(options),
|
||||
.messageSendingFrom = messageSendingFrom(),
|
||||
@@ -448,11 +448,15 @@ void Inner::clearInlineRows(bool resultsDeleted) {
|
||||
_mosaic.clearRows(resultsDeleted);
|
||||
}
|
||||
|
||||
ItemBase *Inner::layoutPrepareInlineResult(Result *result) {
|
||||
auto it = _inlineLayouts.find(result);
|
||||
ItemBase *Inner::layoutPrepareInlineResult(std::shared_ptr<Result> result) {
|
||||
const auto raw = result.get();
|
||||
auto it = _inlineLayouts.find(raw);
|
||||
if (it == _inlineLayouts.cend()) {
|
||||
if (auto layout = ItemBase::createLayout(this, result, _inlineWithThumb)) {
|
||||
it = _inlineLayouts.emplace(result, std::move(layout)).first;
|
||||
if (auto layout = ItemBase::createLayout(
|
||||
this,
|
||||
std::move(result),
|
||||
_inlineWithThumb)) {
|
||||
it = _inlineLayouts.emplace(raw, std::move(layout)).first;
|
||||
it->second->initDimensions();
|
||||
} else {
|
||||
return nullptr;
|
||||
@@ -560,8 +564,8 @@ int Inner::refreshInlineRows(PeerData *queryPeer, UserData *bot, const CacheEntr
|
||||
const auto resultItems = entry->results | ranges::views::slice(
|
||||
from,
|
||||
count
|
||||
) | ranges::views::transform([&](const std::unique_ptr<Result> &r) {
|
||||
return layoutPrepareInlineResult(r.get());
|
||||
) | ranges::views::transform([&](const std::shared_ptr<Result> &r) {
|
||||
return layoutPrepareInlineResult(r);
|
||||
}) | ranges::views::filter([](const ItemBase *item) {
|
||||
return item != nullptr;
|
||||
}) | ranges::to<std::vector<not_null<ItemBase*>>>;
|
||||
@@ -585,7 +589,7 @@ int Inner::validateExistingInlineRows(const Results &results) {
|
||||
const auto until = _mosaic.validateExistingRows([&](
|
||||
not_null<const ItemBase*> item,
|
||||
int untilIndex) {
|
||||
return item->getResult() != results[untilIndex].get();
|
||||
return item->getResult().get() != results[untilIndex].get();
|
||||
}, results.size());
|
||||
|
||||
if (_mosaic.empty()) {
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace InlineBots {
|
||||
namespace Layout {
|
||||
|
||||
class ItemBase;
|
||||
using Results = std::vector<std::unique_ptr<Result>>;
|
||||
using Results = std::vector<std::shared_ptr<Result>>;
|
||||
|
||||
struct CacheEntry {
|
||||
QString nextOffset;
|
||||
@@ -135,7 +135,7 @@ private:
|
||||
void updateInlineItems();
|
||||
void repaintItems(crl::time now = 0);
|
||||
void clearInlineRows(bool resultsDeleted);
|
||||
ItemBase *layoutPrepareInlineResult(Result *result);
|
||||
ItemBase *layoutPrepareInlineResult(std::shared_ptr<Result> result);
|
||||
|
||||
void updateRestrictedLabelGeometry();
|
||||
void deleteUnusedInlineLayouts();
|
||||
|
||||
Reference in New Issue
Block a user