mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 15:17:07 +02:00
Send paid stickers/gifs/inline-results.
This commit is contained in:
parent
22b99b6d3e
commit
93a590774e
19 changed files with 161 additions and 95 deletions
Telegram/SourceFiles
chat_helpers
history
inline_bots
inline_bot_layout_internal.cppinline_bot_layout_internal.hinline_bot_layout_item.cppinline_bot_layout_item.hinline_bot_result.cppinline_bot_result.hinline_results_inner.cppinline_results_inner.h
media/stories
settings/business
window
|
@ -666,14 +666,15 @@ GifsListWidget::LayoutItem *GifsListWidget::layoutPrepareSavedGif(
|
|||
}
|
||||
|
||||
GifsListWidget::LayoutItem *GifsListWidget::layoutPrepareInlineResult(
|
||||
not_null<InlineResult*> result) {
|
||||
auto it = _inlineLayouts.find(result);
|
||||
std::shared_ptr<InlineResult> result) {
|
||||
const auto raw = result.get();
|
||||
auto it = _inlineLayouts.find(raw);
|
||||
if (it == _inlineLayouts.cend()) {
|
||||
if (auto layout = LayoutItem::createLayout(
|
||||
this,
|
||||
result,
|
||||
std::move(result),
|
||||
_inlineWithThumb)) {
|
||||
it = _inlineLayouts.emplace(result, std::move(layout)).first;
|
||||
it = _inlineLayouts.emplace(raw, std::move(layout)).first;
|
||||
it->second->initDimensions();
|
||||
} else {
|
||||
return nullptr;
|
||||
|
@ -746,8 +747,8 @@ int GifsListWidget::refreshInlineRows(const InlineCacheEntry *entry, bool result
|
|||
from,
|
||||
count
|
||||
) | ranges::views::transform([&](
|
||||
const std::unique_ptr<InlineBots::Result> &r) {
|
||||
return layoutPrepareInlineResult(r.get());
|
||||
const std::shared_ptr<InlineBots::Result> &r) {
|
||||
return layoutPrepareInlineResult(r);
|
||||
}) | ranges::views::filter([](const LayoutItem *item) {
|
||||
return item != nullptr;
|
||||
}) | ranges::to<std::vector<not_null<LayoutItem*>>>;
|
||||
|
@ -770,7 +771,7 @@ int GifsListWidget::validateExistingInlineRows(const InlineResults &results) {
|
|||
const auto until = _mosaic.validateExistingRows([&](
|
||||
not_null<const LayoutItem*> item,
|
||||
int untilIndex) {
|
||||
return item->getResult() != results[untilIndex].get();
|
||||
return item->getResult().get() != results[untilIndex].get();
|
||||
}, results.size());
|
||||
|
||||
if (_mosaic.empty()) {
|
||||
|
|
|
@ -131,7 +131,7 @@ private:
|
|||
};
|
||||
|
||||
using InlineResult = InlineBots::Result;
|
||||
using InlineResults = std::vector<std::unique_ptr<InlineResult>>;
|
||||
using InlineResults = std::vector<std::shared_ptr<InlineResult>>;
|
||||
using LayoutItem = InlineBots::Layout::ItemBase;
|
||||
|
||||
struct InlineCacheEntry {
|
||||
|
@ -162,7 +162,8 @@ private:
|
|||
|
||||
void clearInlineRows(bool resultsDeleted);
|
||||
LayoutItem *layoutPrepareSavedGif(not_null<DocumentData*> document);
|
||||
LayoutItem *layoutPrepareInlineResult(not_null<InlineResult*> result);
|
||||
LayoutItem *layoutPrepareInlineResult(
|
||||
std::shared_ptr<InlineResult> result);
|
||||
|
||||
void deleteUnusedGifLayouts();
|
||||
|
||||
|
|
|
@ -7329,10 +7329,21 @@ void HistoryWidget::sendInlineResult(InlineBots::ResultSelected result) {
|
|||
return;
|
||||
} else if (showSlowmodeError()) {
|
||||
return;
|
||||
} else if (const auto error = result.result->getErrorOnSend(_history)) {
|
||||
Data::ShowSendErrorToast(controller(), _peer, error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (const auto error = result.result->getErrorOnSend(_history)) {
|
||||
Data::ShowSendErrorToast(controller(), _peer, error);
|
||||
const auto withPaymentApproved = [=](int approved) {
|
||||
auto copy = result;
|
||||
copy.options.starsApproved = approved;
|
||||
sendInlineResult(copy);
|
||||
};
|
||||
const auto checked = checkSendPayment(
|
||||
1,
|
||||
result.options.starsApproved,
|
||||
withPaymentApproved);
|
||||
if (!checked) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -7343,7 +7354,7 @@ void HistoryWidget::sendInlineResult(InlineBots::ResultSelected result) {
|
|||
action.generateLocal = true;
|
||||
session().api().sendInlineResult(
|
||||
result.bot,
|
||||
result.result,
|
||||
result.result.get(),
|
||||
action,
|
||||
result.messageSendingFrom.localId);
|
||||
|
||||
|
@ -7984,6 +7995,18 @@ bool HistoryWidget::sendExistingDocument(
|
|||
|| ShowSendPremiumError(controller(), document)) {
|
||||
return false;
|
||||
}
|
||||
const auto withPaymentApproved = [=](int approved) {
|
||||
auto copy = messageToSend;
|
||||
copy.action.options.starsApproved = approved;
|
||||
sendExistingDocument(document, std::move(copy), localId);
|
||||
};
|
||||
const auto checked = checkSendPayment(
|
||||
1,
|
||||
messageToSend.action.options.starsApproved,
|
||||
withPaymentApproved);
|
||||
if (!checked) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Api::SendExistingDocument(
|
||||
std::move(messageToSend),
|
||||
|
@ -8021,6 +8044,19 @@ bool HistoryWidget::sendExistingPhoto(
|
|||
return false;
|
||||
}
|
||||
|
||||
const auto withPaymentApproved = [=](int approved) {
|
||||
auto copy = options;
|
||||
copy.starsApproved = approved;
|
||||
sendExistingPhoto(photo, copy);
|
||||
};
|
||||
const auto checked = checkSendPayment(
|
||||
1,
|
||||
options.starsApproved,
|
||||
withPaymentApproved);
|
||||
if (!checked) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Api::SendExistingPhoto(
|
||||
Api::MessageToSend(prepareSendAction(options)),
|
||||
photo);
|
||||
|
|
|
@ -1458,13 +1458,13 @@ bool RepliesWidget::sendExistingPhoto(
|
|||
}
|
||||
|
||||
void RepliesWidget::sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot) {
|
||||
if (const auto error = result->getErrorOnSend(_history)) {
|
||||
Data::ShowSendErrorToast(controller(), _history->peer, error);
|
||||
return;
|
||||
}
|
||||
sendInlineResult(result, bot, {}, std::nullopt);
|
||||
sendInlineResult(std::move(result), bot, {}, std::nullopt);
|
||||
//const auto callback = [=](Api::SendOptions options) {
|
||||
// sendInlineResult(result, bot, options);
|
||||
//};
|
||||
|
@ -1474,13 +1474,17 @@ void RepliesWidget::sendInlineResult(
|
|||
}
|
||||
|
||||
void RepliesWidget::sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot,
|
||||
Api::SendOptions options,
|
||||
std::optional<MsgId> localMessageId) {
|
||||
auto action = prepareSendAction(options);
|
||||
action.generateLocal = true;
|
||||
session().api().sendInlineResult(bot, result, action, localMessageId);
|
||||
session().api().sendInlineResult(
|
||||
bot,
|
||||
result.get(),
|
||||
action,
|
||||
localMessageId);
|
||||
|
||||
_composeControls->clear();
|
||||
//_saveDraftText = true;
|
||||
|
|
|
@ -318,10 +318,10 @@ private:
|
|||
not_null<PhotoData*> photo,
|
||||
Api::SendOptions options);
|
||||
void sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot);
|
||||
void sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot,
|
||||
Api::SendOptions options,
|
||||
std::optional<MsgId> localMessageId);
|
||||
|
|
|
@ -909,7 +909,7 @@ bool ScheduledWidget::sendExistingPhoto(
|
|||
}
|
||||
|
||||
void ScheduledWidget::sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot) {
|
||||
if (const auto error = result->getErrorOnSend(_history)) {
|
||||
Data::ShowSendErrorToast(controller(), _history->peer, error);
|
||||
|
@ -923,12 +923,16 @@ void ScheduledWidget::sendInlineResult(
|
|||
}
|
||||
|
||||
void ScheduledWidget::sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot,
|
||||
Api::SendOptions options) {
|
||||
auto action = prepareSendAction(options);
|
||||
action.generateLocal = true;
|
||||
session().api().sendInlineResult(bot, result, action, std::nullopt);
|
||||
session().api().sendInlineResult(
|
||||
bot,
|
||||
result.get(),
|
||||
action,
|
||||
std::nullopt);
|
||||
|
||||
_composeControls->clear();
|
||||
//_saveDraftText = true;
|
||||
|
|
|
@ -274,10 +274,10 @@ private:
|
|||
not_null<PhotoData*> photo,
|
||||
Api::SendOptions options);
|
||||
void sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot);
|
||||
void sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot,
|
||||
Api::SendOptions options);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -307,7 +307,7 @@ bool ReplyArea::sendExistingPhoto(
|
|||
}
|
||||
|
||||
void ReplyArea::sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot) {
|
||||
if (const auto error = result->getErrorOnSend(history())) {
|
||||
const auto show = _controller->uiShow();
|
||||
|
@ -318,13 +318,17 @@ void ReplyArea::sendInlineResult(
|
|||
}
|
||||
|
||||
void ReplyArea::sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot,
|
||||
Api::SendOptions options,
|
||||
std::optional<MsgId> localMessageId) {
|
||||
auto action = prepareSendAction(options);
|
||||
action.generateLocal = true;
|
||||
session().api().sendInlineResult(bot, result, action, localMessageId);
|
||||
session().api().sendInlineResult(
|
||||
bot,
|
||||
result.get(),
|
||||
action,
|
||||
localMessageId);
|
||||
|
||||
auto &bots = cRefRecentInlineBots();
|
||||
const auto index = bots.indexOf(bot);
|
||||
|
|
|
@ -127,10 +127,10 @@ private:
|
|||
not_null<PhotoData*> photo,
|
||||
Api::SendOptions options);
|
||||
void sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot);
|
||||
void sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot,
|
||||
Api::SendOptions options,
|
||||
std::optional<MsgId> localMessageId);
|
||||
|
|
|
@ -223,10 +223,10 @@ private:
|
|||
not_null<PhotoData*> photo,
|
||||
Api::SendOptions options);
|
||||
void sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot);
|
||||
void sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot,
|
||||
Api::SendOptions options,
|
||||
std::optional<MsgId> localMessageId);
|
||||
|
@ -1534,7 +1534,7 @@ bool ShortcutMessages::sendExistingPhoto(
|
|||
}
|
||||
|
||||
void ShortcutMessages::sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot) {
|
||||
if (showPremiumRequired()) {
|
||||
return;
|
||||
|
@ -1542,11 +1542,11 @@ void ShortcutMessages::sendInlineResult(
|
|||
Data::ShowSendErrorToast(_controller, _history->peer, error);
|
||||
return;
|
||||
}
|
||||
sendInlineResult(result, bot, {}, std::nullopt);
|
||||
sendInlineResult(std::move(result), bot, {}, std::nullopt);
|
||||
}
|
||||
|
||||
void ShortcutMessages::sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
std::shared_ptr<InlineBots::Result> result,
|
||||
not_null<UserData*> bot,
|
||||
Api::SendOptions options,
|
||||
std::optional<MsgId> localMessageId) {
|
||||
|
@ -1555,7 +1555,11 @@ void ShortcutMessages::sendInlineResult(
|
|||
}
|
||||
auto action = prepareSendAction(options);
|
||||
action.generateLocal = true;
|
||||
_session->api().sendInlineResult(bot, result, action, localMessageId);
|
||||
_session->api().sendInlineResult(
|
||||
bot,
|
||||
result.get(),
|
||||
action,
|
||||
localMessageId);
|
||||
|
||||
_composeControls->clear();
|
||||
//_saveDraftText = true;
|
||||
|
|
|
@ -1684,12 +1684,12 @@ void PeerMenuShareContactBox(
|
|||
: ('\xAB' + title + '\xBB');
|
||||
struct State {
|
||||
base::weak_ptr<Data::Thread> weak;
|
||||
Fn<void(Api::SendOptions)> share;
|
||||
FnMut<void(Api::SendOptions)> share;
|
||||
SendPaymentHelper sendPayment;
|
||||
};
|
||||
const auto state = std::make_shared<State>();
|
||||
auto state = std::make_shared<State>();
|
||||
state->weak = thread;
|
||||
state->share = [=](Api::SendOptions options) {
|
||||
state->share = [=](Api::SendOptions options) mutable {
|
||||
const auto strong = state->weak.get();
|
||||
if (!strong) {
|
||||
return;
|
||||
|
@ -1715,6 +1715,7 @@ void PeerMenuShareContactBox(
|
|||
auto action = Api::SendAction(strong, options);
|
||||
action.clearDraft = false;
|
||||
strong->session().api().shareContact(user, action);
|
||||
state = nullptr;
|
||||
};
|
||||
|
||||
navigation->parentController()->show(
|
||||
|
|
Loading…
Add table
Reference in a new issue