mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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
|
@ -666,14 +666,15 @@ GifsListWidget::LayoutItem *GifsListWidget::layoutPrepareSavedGif(
|
||||||
}
|
}
|
||||||
|
|
||||||
GifsListWidget::LayoutItem *GifsListWidget::layoutPrepareInlineResult(
|
GifsListWidget::LayoutItem *GifsListWidget::layoutPrepareInlineResult(
|
||||||
not_null<InlineResult*> result) {
|
std::shared_ptr<InlineResult> result) {
|
||||||
auto it = _inlineLayouts.find(result);
|
const auto raw = result.get();
|
||||||
|
auto it = _inlineLayouts.find(raw);
|
||||||
if (it == _inlineLayouts.cend()) {
|
if (it == _inlineLayouts.cend()) {
|
||||||
if (auto layout = LayoutItem::createLayout(
|
if (auto layout = LayoutItem::createLayout(
|
||||||
this,
|
this,
|
||||||
result,
|
std::move(result),
|
||||||
_inlineWithThumb)) {
|
_inlineWithThumb)) {
|
||||||
it = _inlineLayouts.emplace(result, std::move(layout)).first;
|
it = _inlineLayouts.emplace(raw, std::move(layout)).first;
|
||||||
it->second->initDimensions();
|
it->second->initDimensions();
|
||||||
} else {
|
} else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -746,8 +747,8 @@ int GifsListWidget::refreshInlineRows(const InlineCacheEntry *entry, bool result
|
||||||
from,
|
from,
|
||||||
count
|
count
|
||||||
) | ranges::views::transform([&](
|
) | ranges::views::transform([&](
|
||||||
const std::unique_ptr<InlineBots::Result> &r) {
|
const std::shared_ptr<InlineBots::Result> &r) {
|
||||||
return layoutPrepareInlineResult(r.get());
|
return layoutPrepareInlineResult(r);
|
||||||
}) | ranges::views::filter([](const LayoutItem *item) {
|
}) | ranges::views::filter([](const LayoutItem *item) {
|
||||||
return item != nullptr;
|
return item != nullptr;
|
||||||
}) | ranges::to<std::vector<not_null<LayoutItem*>>>;
|
}) | ranges::to<std::vector<not_null<LayoutItem*>>>;
|
||||||
|
@ -770,7 +771,7 @@ int GifsListWidget::validateExistingInlineRows(const InlineResults &results) {
|
||||||
const auto until = _mosaic.validateExistingRows([&](
|
const auto until = _mosaic.validateExistingRows([&](
|
||||||
not_null<const LayoutItem*> item,
|
not_null<const LayoutItem*> item,
|
||||||
int untilIndex) {
|
int untilIndex) {
|
||||||
return item->getResult() != results[untilIndex].get();
|
return item->getResult().get() != results[untilIndex].get();
|
||||||
}, results.size());
|
}, results.size());
|
||||||
|
|
||||||
if (_mosaic.empty()) {
|
if (_mosaic.empty()) {
|
||||||
|
|
|
@ -131,7 +131,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
using InlineResult = InlineBots::Result;
|
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;
|
using LayoutItem = InlineBots::Layout::ItemBase;
|
||||||
|
|
||||||
struct InlineCacheEntry {
|
struct InlineCacheEntry {
|
||||||
|
@ -162,7 +162,8 @@ private:
|
||||||
|
|
||||||
void clearInlineRows(bool resultsDeleted);
|
void clearInlineRows(bool resultsDeleted);
|
||||||
LayoutItem *layoutPrepareSavedGif(not_null<DocumentData*> document);
|
LayoutItem *layoutPrepareSavedGif(not_null<DocumentData*> document);
|
||||||
LayoutItem *layoutPrepareInlineResult(not_null<InlineResult*> result);
|
LayoutItem *layoutPrepareInlineResult(
|
||||||
|
std::shared_ptr<InlineResult> result);
|
||||||
|
|
||||||
void deleteUnusedGifLayouts();
|
void deleteUnusedGifLayouts();
|
||||||
|
|
||||||
|
|
|
@ -7329,10 +7329,21 @@ void HistoryWidget::sendInlineResult(InlineBots::ResultSelected result) {
|
||||||
return;
|
return;
|
||||||
} else if (showSlowmodeError()) {
|
} else if (showSlowmodeError()) {
|
||||||
return;
|
return;
|
||||||
|
} else if (const auto error = result.result->getErrorOnSend(_history)) {
|
||||||
|
Data::ShowSendErrorToast(controller(), _peer, error);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const auto error = result.result->getErrorOnSend(_history)) {
|
const auto withPaymentApproved = [=](int approved) {
|
||||||
Data::ShowSendErrorToast(controller(), _peer, error);
|
auto copy = result;
|
||||||
|
copy.options.starsApproved = approved;
|
||||||
|
sendInlineResult(copy);
|
||||||
|
};
|
||||||
|
const auto checked = checkSendPayment(
|
||||||
|
1,
|
||||||
|
result.options.starsApproved,
|
||||||
|
withPaymentApproved);
|
||||||
|
if (!checked) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7343,7 +7354,7 @@ void HistoryWidget::sendInlineResult(InlineBots::ResultSelected result) {
|
||||||
action.generateLocal = true;
|
action.generateLocal = true;
|
||||||
session().api().sendInlineResult(
|
session().api().sendInlineResult(
|
||||||
result.bot,
|
result.bot,
|
||||||
result.result,
|
result.result.get(),
|
||||||
action,
|
action,
|
||||||
result.messageSendingFrom.localId);
|
result.messageSendingFrom.localId);
|
||||||
|
|
||||||
|
@ -7984,6 +7995,18 @@ bool HistoryWidget::sendExistingDocument(
|
||||||
|| ShowSendPremiumError(controller(), document)) {
|
|| ShowSendPremiumError(controller(), document)) {
|
||||||
return false;
|
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(
|
Api::SendExistingDocument(
|
||||||
std::move(messageToSend),
|
std::move(messageToSend),
|
||||||
|
@ -8021,6 +8044,19 @@ bool HistoryWidget::sendExistingPhoto(
|
||||||
return false;
|
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::SendExistingPhoto(
|
||||||
Api::MessageToSend(prepareSendAction(options)),
|
Api::MessageToSend(prepareSendAction(options)),
|
||||||
photo);
|
photo);
|
||||||
|
|
|
@ -1458,13 +1458,13 @@ bool RepliesWidget::sendExistingPhoto(
|
||||||
}
|
}
|
||||||
|
|
||||||
void RepliesWidget::sendInlineResult(
|
void RepliesWidget::sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot) {
|
not_null<UserData*> bot) {
|
||||||
if (const auto error = result->getErrorOnSend(_history)) {
|
if (const auto error = result->getErrorOnSend(_history)) {
|
||||||
Data::ShowSendErrorToast(controller(), _history->peer, error);
|
Data::ShowSendErrorToast(controller(), _history->peer, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendInlineResult(result, bot, {}, std::nullopt);
|
sendInlineResult(std::move(result), bot, {}, std::nullopt);
|
||||||
//const auto callback = [=](Api::SendOptions options) {
|
//const auto callback = [=](Api::SendOptions options) {
|
||||||
// sendInlineResult(result, bot, options);
|
// sendInlineResult(result, bot, options);
|
||||||
//};
|
//};
|
||||||
|
@ -1474,13 +1474,17 @@ void RepliesWidget::sendInlineResult(
|
||||||
}
|
}
|
||||||
|
|
||||||
void RepliesWidget::sendInlineResult(
|
void RepliesWidget::sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
Api::SendOptions options,
|
Api::SendOptions options,
|
||||||
std::optional<MsgId> localMessageId) {
|
std::optional<MsgId> localMessageId) {
|
||||||
auto action = prepareSendAction(options);
|
auto action = prepareSendAction(options);
|
||||||
action.generateLocal = true;
|
action.generateLocal = true;
|
||||||
session().api().sendInlineResult(bot, result, action, localMessageId);
|
session().api().sendInlineResult(
|
||||||
|
bot,
|
||||||
|
result.get(),
|
||||||
|
action,
|
||||||
|
localMessageId);
|
||||||
|
|
||||||
_composeControls->clear();
|
_composeControls->clear();
|
||||||
//_saveDraftText = true;
|
//_saveDraftText = true;
|
||||||
|
|
|
@ -318,10 +318,10 @@ private:
|
||||||
not_null<PhotoData*> photo,
|
not_null<PhotoData*> photo,
|
||||||
Api::SendOptions options);
|
Api::SendOptions options);
|
||||||
void sendInlineResult(
|
void sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot);
|
not_null<UserData*> bot);
|
||||||
void sendInlineResult(
|
void sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
Api::SendOptions options,
|
Api::SendOptions options,
|
||||||
std::optional<MsgId> localMessageId);
|
std::optional<MsgId> localMessageId);
|
||||||
|
|
|
@ -909,7 +909,7 @@ bool ScheduledWidget::sendExistingPhoto(
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScheduledWidget::sendInlineResult(
|
void ScheduledWidget::sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot) {
|
not_null<UserData*> bot) {
|
||||||
if (const auto error = result->getErrorOnSend(_history)) {
|
if (const auto error = result->getErrorOnSend(_history)) {
|
||||||
Data::ShowSendErrorToast(controller(), _history->peer, error);
|
Data::ShowSendErrorToast(controller(), _history->peer, error);
|
||||||
|
@ -923,12 +923,16 @@ void ScheduledWidget::sendInlineResult(
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScheduledWidget::sendInlineResult(
|
void ScheduledWidget::sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
Api::SendOptions options) {
|
Api::SendOptions options) {
|
||||||
auto action = prepareSendAction(options);
|
auto action = prepareSendAction(options);
|
||||||
action.generateLocal = true;
|
action.generateLocal = true;
|
||||||
session().api().sendInlineResult(bot, result, action, std::nullopt);
|
session().api().sendInlineResult(
|
||||||
|
bot,
|
||||||
|
result.get(),
|
||||||
|
action,
|
||||||
|
std::nullopt);
|
||||||
|
|
||||||
_composeControls->clear();
|
_composeControls->clear();
|
||||||
//_saveDraftText = true;
|
//_saveDraftText = true;
|
||||||
|
|
|
@ -274,10 +274,10 @@ private:
|
||||||
not_null<PhotoData*> photo,
|
not_null<PhotoData*> photo,
|
||||||
Api::SendOptions options);
|
Api::SendOptions options);
|
||||||
void sendInlineResult(
|
void sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot);
|
not_null<UserData*> bot);
|
||||||
void sendInlineResult(
|
void sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
Api::SendOptions options);
|
Api::SendOptions options);
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,8 @@ constexpr auto kMaxInlineArea = 1280 * 720;
|
||||||
return dimensions.width() * dimensions.height() <= kMaxInlineArea;
|
return dimensions.width() * dimensions.height() <= kMaxInlineArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileBase::FileBase(not_null<Context*> context, not_null<Result*> result)
|
FileBase::FileBase(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||||
: ItemBase(context, result) {
|
: ItemBase(context, std::move(result)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FileBase::FileBase(
|
FileBase::FileBase(
|
||||||
|
@ -95,8 +95,8 @@ int FileBase::content_duration() const {
|
||||||
return getResultDuration();
|
return getResultDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
Gif::Gif(not_null<Context*> context, not_null<Result*> result)
|
Gif::Gif(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||||
: FileBase(context, result) {
|
: FileBase(context, std::move(result)) {
|
||||||
Expects(getResultDocument() != nullptr);
|
Expects(getResultDocument() != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,8 +442,8 @@ void Gif::clipCallback(Media::Clip::Notification notification) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sticker::Sticker(not_null<Context*> context, not_null<Result*> result)
|
Sticker::Sticker(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||||
: FileBase(context, result) {
|
: FileBase(context, std::move(result)) {
|
||||||
Expects(getResultDocument() != nullptr);
|
Expects(getResultDocument() != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -654,8 +654,8 @@ void Sticker::clipCallback(Media::Clip::Notification notification) {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
Photo::Photo(not_null<Context*> context, not_null<Result*> result)
|
Photo::Photo(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||||
: ItemBase(context, result) {
|
: ItemBase(context, std::move(result)) {
|
||||||
Expects(getShownPhoto() != nullptr);
|
Expects(getShownPhoto() != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,8 +769,8 @@ void Photo::prepareThumbnail(QSize size, QSize frame) const {
|
||||||
validateThumbnail(_photoMedia->thumbnailInline(), size, frame, false);
|
validateThumbnail(_photoMedia->thumbnailInline(), size, frame, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Video::Video(not_null<Context*> context, not_null<Result*> result)
|
Video::Video(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||||
: FileBase(context, result)
|
: FileBase(context, std::move(result))
|
||||||
, _link(getResultPreviewHandler())
|
, _link(getResultPreviewHandler())
|
||||||
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
|
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
|
||||||
, _description(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();
|
_result->cancelFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
File::File(not_null<Context*> context, not_null<Result*> result)
|
File::File(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||||
: FileBase(context, result)
|
: FileBase(context, std::move(result))
|
||||||
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineFileSize - st::inlineThumbSkip)
|
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineFileSize - st::inlineThumbSkip)
|
||||||
, _description(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()) {
|
, _document(getShownDocument()) {
|
||||||
Expects(getResultDocument() != nullptr);
|
Expects(getResultDocument() != nullptr);
|
||||||
|
|
||||||
|
@ -1173,8 +1173,8 @@ void File::setStatusSize(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact::Contact(not_null<Context*> context, not_null<Result*> result)
|
Contact::Contact(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||||
: ItemBase(context, result)
|
: ItemBase(context, std::move(result))
|
||||||
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
|
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
|
||||||
, _description(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(
|
Article::Article(
|
||||||
not_null<Context*> context,
|
not_null<Context*> context,
|
||||||
not_null<Result*> result,
|
std::shared_ptr<Result> result,
|
||||||
bool withThumb)
|
bool withThumb)
|
||||||
: ItemBase(context, result)
|
: ItemBase(context, std::move(result))
|
||||||
, _url(getResultUrlHandler())
|
, _url(getResultUrlHandler())
|
||||||
, _link(getResultPreviewHandler())
|
, _link(getResultPreviewHandler())
|
||||||
, _withThumb(withThumb)
|
, _withThumb(withThumb)
|
||||||
, _title(st::emojiPanWidth / 2)
|
, _title(st::emojiPanWidth / 2)
|
||||||
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
|
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
|
||||||
if (!_link) {
|
if (!_link) {
|
||||||
if (const auto point = result->getLocationPoint()) {
|
if (const auto point = _result->getLocationPoint()) {
|
||||||
_link = std::make_shared<LocationClickHandler>(*point);
|
_link = std::make_shared<LocationClickHandler>(*point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1300,7 +1300,7 @@ void Article::initDimensions() {
|
||||||
_minh += st::inlineRowMargin * 2 + st::inlineRowBorder;
|
_minh += st::inlineRowMargin * 2 + st::inlineRowBorder;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 Article::resizeGetHeight(int32 width) {
|
int Article::resizeGetHeight(int width) {
|
||||||
_width = qMin(width, _maxw);
|
_width = qMin(width, _maxw);
|
||||||
if (_url) {
|
if (_url) {
|
||||||
_urlText = getResultUrl();
|
_urlText = getResultUrl();
|
||||||
|
@ -1422,8 +1422,8 @@ void Article::prepareThumbnail(int width, int height) const {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::Game(not_null<Context*> context, not_null<Result*> result)
|
Game::Game(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||||
: ItemBase(context, result)
|
: ItemBase(context, std::move(result))
|
||||||
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
|
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
|
||||||
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
|
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
|
||||||
countFrameSize();
|
countFrameSize();
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace internal {
|
||||||
|
|
||||||
class FileBase : public ItemBase {
|
class FileBase : public ItemBase {
|
||||||
public:
|
public:
|
||||||
FileBase(not_null<Context*> context, not_null<Result*> result);
|
FileBase(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||||
|
|
||||||
// For saved gif layouts.
|
// For saved gif layouts.
|
||||||
FileBase(not_null<Context*> context, not_null<DocumentData*> document);
|
FileBase(not_null<Context*> context, not_null<DocumentData*> document);
|
||||||
|
@ -58,7 +58,7 @@ private:
|
||||||
|
|
||||||
class Gif final : public FileBase {
|
class Gif final : public FileBase {
|
||||||
public:
|
public:
|
||||||
Gif(not_null<Context*> context, not_null<Result*> result);
|
Gif(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||||
Gif(
|
Gif(
|
||||||
not_null<Context*> context,
|
not_null<Context*> context,
|
||||||
not_null<DocumentData*> document,
|
not_null<DocumentData*> document,
|
||||||
|
@ -138,7 +138,7 @@ private:
|
||||||
|
|
||||||
class Photo : public ItemBase {
|
class Photo : public ItemBase {
|
||||||
public:
|
public:
|
||||||
Photo(not_null<Context*> context, not_null<Result*> result);
|
Photo(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||||
// Not used anywhere currently.
|
// Not used anywhere currently.
|
||||||
//Photo(not_null<Context*> context, not_null<PhotoData*> photo);
|
//Photo(not_null<Context*> context, not_null<PhotoData*> photo);
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ private:
|
||||||
|
|
||||||
class Sticker : public FileBase {
|
class Sticker : public FileBase {
|
||||||
public:
|
public:
|
||||||
Sticker(not_null<Context*> context, not_null<Result*> result);
|
Sticker(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||||
~Sticker();
|
~Sticker();
|
||||||
// Not used anywhere currently.
|
// Not used anywhere currently.
|
||||||
//Sticker(not_null<Context*> context, not_null<DocumentData*> document);
|
//Sticker(not_null<Context*> context, not_null<DocumentData*> document);
|
||||||
|
@ -229,7 +229,7 @@ private:
|
||||||
|
|
||||||
class Video : public FileBase {
|
class Video : public FileBase {
|
||||||
public:
|
public:
|
||||||
Video(not_null<Context*> context, not_null<Result*> result);
|
Video(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||||
|
|
||||||
void initDimensions() override;
|
void initDimensions() override;
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ private:
|
||||||
|
|
||||||
class File : public FileBase {
|
class File : public FileBase {
|
||||||
public:
|
public:
|
||||||
File(not_null<Context*> context, not_null<Result*> result);
|
File(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||||
~File();
|
~File();
|
||||||
|
|
||||||
void initDimensions() override;
|
void initDimensions() override;
|
||||||
|
@ -347,7 +347,7 @@ private:
|
||||||
|
|
||||||
class Contact : public ItemBase {
|
class Contact : public ItemBase {
|
||||||
public:
|
public:
|
||||||
Contact(not_null<Context*> context, not_null<Result*> result);
|
Contact(not_null<Context*> context, std::shared_ptr<Result> result);
|
||||||
|
|
||||||
void initDimensions() override;
|
void initDimensions() override;
|
||||||
|
|
||||||
|
@ -366,7 +366,10 @@ private:
|
||||||
|
|
||||||
class Article : public ItemBase {
|
class Article : public ItemBase {
|
||||||
public:
|
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;
|
void initDimensions() override;
|
||||||
int resizeGetHeight(int width) override;
|
int resizeGetHeight(int width) override;
|
||||||
|
@ -391,7 +394,7 @@ private:
|
||||||
|
|
||||||
class Game : public ItemBase {
|
class Game : public ItemBase {
|
||||||
public:
|
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 setPosition(int32 position) override;
|
||||||
void initDimensions() override;
|
void initDimensions() override;
|
||||||
|
|
|
@ -29,7 +29,7 @@ base::NeverFreedPointer<DocumentItems> documentItemsMap;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Result *ItemBase::getResult() const {
|
std::shared_ptr<Result> ItemBase::getResult() const {
|
||||||
return _result;
|
return _result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,33 +92,37 @@ void ItemBase::layoutChanged() {
|
||||||
|
|
||||||
std::unique_ptr<ItemBase> ItemBase::createLayout(
|
std::unique_ptr<ItemBase> ItemBase::createLayout(
|
||||||
not_null<Context*> context,
|
not_null<Context*> context,
|
||||||
not_null<Result*> result,
|
std::shared_ptr<Result> result,
|
||||||
bool forceThumb) {
|
bool forceThumb) {
|
||||||
using Type = Result::Type;
|
using Type = Result::Type;
|
||||||
|
|
||||||
switch (result->_type) {
|
switch (result->_type) {
|
||||||
case Type::Photo:
|
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::Audio:
|
||||||
case Type::File:
|
case Type::File:
|
||||||
return std::make_unique<internal::File>(context, result);
|
return std::make_unique<internal::File>(context, std::move(result));
|
||||||
case Type::Video:
|
case Type::Video:
|
||||||
return std::make_unique<internal::Video>(context, result);
|
return std::make_unique<internal::Video>(context, std::move(result));
|
||||||
case Type::Sticker:
|
case Type::Sticker:
|
||||||
return std::make_unique<internal::Sticker>(context, result);
|
return std::make_unique<internal::Sticker>(
|
||||||
|
context,
|
||||||
|
std::move(result));
|
||||||
case Type::Gif:
|
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::Article:
|
||||||
case Type::Geo:
|
case Type::Geo:
|
||||||
case Type::Venue:
|
case Type::Venue:
|
||||||
return std::make_unique<internal::Article>(
|
return std::make_unique<internal::Article>(
|
||||||
context,
|
context,
|
||||||
result,
|
std::move(result),
|
||||||
forceThumb);
|
forceThumb);
|
||||||
case Type::Game:
|
case Type::Game:
|
||||||
return std::make_unique<internal::Game>(context, result);
|
return std::make_unique<internal::Game>(context, std::move(result));
|
||||||
case Type::Contact:
|
case Type::Contact:
|
||||||
return std::make_unique<internal::Contact>(context, result);
|
return std::make_unique<internal::Contact>(
|
||||||
|
context,
|
||||||
|
std::move(result));
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ public:
|
||||||
|
|
||||||
class ItemBase : public LayoutItemBase {
|
class ItemBase : public LayoutItemBase {
|
||||||
public:
|
public:
|
||||||
ItemBase(not_null<Context*> context, not_null<Result*> result)
|
ItemBase(not_null<Context*> context, std::shared_ptr<Result> result)
|
||||||
: _result(result)
|
: _result(result)
|
||||||
, _context(context) {
|
, _context(context) {
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result *getResult() const;
|
std::shared_ptr<Result> getResult() const;
|
||||||
DocumentData *getDocument() const;
|
DocumentData *getDocument() const;
|
||||||
PhotoData *getPhoto() const;
|
PhotoData *getPhoto() const;
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ public:
|
||||||
|
|
||||||
static std::unique_ptr<ItemBase> createLayout(
|
static std::unique_ptr<ItemBase> createLayout(
|
||||||
not_null<Context*> context,
|
not_null<Context*> context,
|
||||||
not_null<Result*> result,
|
std::shared_ptr<Result> result,
|
||||||
bool forceThumb);
|
bool forceThumb);
|
||||||
static std::unique_ptr<ItemBase> createLayoutGif(
|
static std::unique_ptr<ItemBase> createLayoutGif(
|
||||||
not_null<Context*> context,
|
not_null<Context*> context,
|
||||||
|
@ -135,7 +135,7 @@ protected:
|
||||||
}
|
}
|
||||||
Data::FileOrigin fileOrigin() const;
|
Data::FileOrigin fileOrigin() const;
|
||||||
|
|
||||||
Result *_result = nullptr;
|
std::shared_ptr<Result> _result;
|
||||||
DocumentData *_document = nullptr;
|
DocumentData *_document = nullptr;
|
||||||
PhotoData *_photo = nullptr;
|
PhotoData *_photo = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ Result::Result(not_null<Main::Session*> session, const Creator &creator)
|
||||||
, _type(creator.type) {
|
, _type(creator.type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Result> Result::Create(
|
std::shared_ptr<Result> Result::Create(
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
uint64 queryId,
|
uint64 queryId,
|
||||||
const MTPBotInlineResult &data) {
|
const MTPBotInlineResult &data) {
|
||||||
|
@ -84,7 +84,7 @@ std::unique_ptr<Result> Result::Create(
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = std::make_unique<Result>(
|
auto result = std::make_shared<Result>(
|
||||||
session,
|
session,
|
||||||
Creator{ queryId, type });
|
Creator{ queryId, type });
|
||||||
const auto message = data.match([&](const MTPDbotInlineResult &data) {
|
const auto message = data.match([&](const MTPDbotInlineResult &data) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ public:
|
||||||
// You should use create() static method instead.
|
// You should use create() static method instead.
|
||||||
Result(not_null<Main::Session*> session, const Creator &creator);
|
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,
|
not_null<Main::Session*> session,
|
||||||
uint64 queryId,
|
uint64 queryId,
|
||||||
const MTPBotInlineResult &mtpData);
|
const MTPBotInlineResult &mtpData);
|
||||||
|
@ -130,7 +130,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ResultSelected {
|
struct ResultSelected {
|
||||||
not_null<Result*> result;
|
std::shared_ptr<Result> result;
|
||||||
not_null<UserData*> bot;
|
not_null<UserData*> bot;
|
||||||
PeerData *recipientOverride = nullptr;
|
PeerData *recipientOverride = nullptr;
|
||||||
Api::SendOptions options;
|
Api::SendOptions options;
|
||||||
|
|
|
@ -331,7 +331,7 @@ void Inner::selectInlineResult(
|
||||||
if (const auto inlineResult = item->getResult()) {
|
if (const auto inlineResult = item->getResult()) {
|
||||||
if (inlineResult->onChoose(item)) {
|
if (inlineResult->onChoose(item)) {
|
||||||
_resultSelectedCallback({
|
_resultSelectedCallback({
|
||||||
.result = inlineResult,
|
.result = std::move(inlineResult),
|
||||||
.bot = _inlineBot,
|
.bot = _inlineBot,
|
||||||
.options = std::move(options),
|
.options = std::move(options),
|
||||||
.messageSendingFrom = messageSendingFrom(),
|
.messageSendingFrom = messageSendingFrom(),
|
||||||
|
@ -448,11 +448,15 @@ void Inner::clearInlineRows(bool resultsDeleted) {
|
||||||
_mosaic.clearRows(resultsDeleted);
|
_mosaic.clearRows(resultsDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemBase *Inner::layoutPrepareInlineResult(Result *result) {
|
ItemBase *Inner::layoutPrepareInlineResult(std::shared_ptr<Result> result) {
|
||||||
auto it = _inlineLayouts.find(result);
|
const auto raw = result.get();
|
||||||
|
auto it = _inlineLayouts.find(raw);
|
||||||
if (it == _inlineLayouts.cend()) {
|
if (it == _inlineLayouts.cend()) {
|
||||||
if (auto layout = ItemBase::createLayout(this, result, _inlineWithThumb)) {
|
if (auto layout = ItemBase::createLayout(
|
||||||
it = _inlineLayouts.emplace(result, std::move(layout)).first;
|
this,
|
||||||
|
std::move(result),
|
||||||
|
_inlineWithThumb)) {
|
||||||
|
it = _inlineLayouts.emplace(raw, std::move(layout)).first;
|
||||||
it->second->initDimensions();
|
it->second->initDimensions();
|
||||||
} else {
|
} else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -560,8 +564,8 @@ int Inner::refreshInlineRows(PeerData *queryPeer, UserData *bot, const CacheEntr
|
||||||
const auto resultItems = entry->results | ranges::views::slice(
|
const auto resultItems = entry->results | ranges::views::slice(
|
||||||
from,
|
from,
|
||||||
count
|
count
|
||||||
) | ranges::views::transform([&](const std::unique_ptr<Result> &r) {
|
) | ranges::views::transform([&](const std::shared_ptr<Result> &r) {
|
||||||
return layoutPrepareInlineResult(r.get());
|
return layoutPrepareInlineResult(r);
|
||||||
}) | ranges::views::filter([](const ItemBase *item) {
|
}) | ranges::views::filter([](const ItemBase *item) {
|
||||||
return item != nullptr;
|
return item != nullptr;
|
||||||
}) | ranges::to<std::vector<not_null<ItemBase*>>>;
|
}) | ranges::to<std::vector<not_null<ItemBase*>>>;
|
||||||
|
@ -585,7 +589,7 @@ int Inner::validateExistingInlineRows(const Results &results) {
|
||||||
const auto until = _mosaic.validateExistingRows([&](
|
const auto until = _mosaic.validateExistingRows([&](
|
||||||
not_null<const ItemBase*> item,
|
not_null<const ItemBase*> item,
|
||||||
int untilIndex) {
|
int untilIndex) {
|
||||||
return item->getResult() != results[untilIndex].get();
|
return item->getResult().get() != results[untilIndex].get();
|
||||||
}, results.size());
|
}, results.size());
|
||||||
|
|
||||||
if (_mosaic.empty()) {
|
if (_mosaic.empty()) {
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace InlineBots {
|
||||||
namespace Layout {
|
namespace Layout {
|
||||||
|
|
||||||
class ItemBase;
|
class ItemBase;
|
||||||
using Results = std::vector<std::unique_ptr<Result>>;
|
using Results = std::vector<std::shared_ptr<Result>>;
|
||||||
|
|
||||||
struct CacheEntry {
|
struct CacheEntry {
|
||||||
QString nextOffset;
|
QString nextOffset;
|
||||||
|
@ -135,7 +135,7 @@ private:
|
||||||
void updateInlineItems();
|
void updateInlineItems();
|
||||||
void repaintItems(crl::time now = 0);
|
void repaintItems(crl::time now = 0);
|
||||||
void clearInlineRows(bool resultsDeleted);
|
void clearInlineRows(bool resultsDeleted);
|
||||||
ItemBase *layoutPrepareInlineResult(Result *result);
|
ItemBase *layoutPrepareInlineResult(std::shared_ptr<Result> result);
|
||||||
|
|
||||||
void updateRestrictedLabelGeometry();
|
void updateRestrictedLabelGeometry();
|
||||||
void deleteUnusedInlineLayouts();
|
void deleteUnusedInlineLayouts();
|
||||||
|
|
|
@ -307,7 +307,7 @@ bool ReplyArea::sendExistingPhoto(
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplyArea::sendInlineResult(
|
void ReplyArea::sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot) {
|
not_null<UserData*> bot) {
|
||||||
if (const auto error = result->getErrorOnSend(history())) {
|
if (const auto error = result->getErrorOnSend(history())) {
|
||||||
const auto show = _controller->uiShow();
|
const auto show = _controller->uiShow();
|
||||||
|
@ -318,13 +318,17 @@ void ReplyArea::sendInlineResult(
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplyArea::sendInlineResult(
|
void ReplyArea::sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
Api::SendOptions options,
|
Api::SendOptions options,
|
||||||
std::optional<MsgId> localMessageId) {
|
std::optional<MsgId> localMessageId) {
|
||||||
auto action = prepareSendAction(options);
|
auto action = prepareSendAction(options);
|
||||||
action.generateLocal = true;
|
action.generateLocal = true;
|
||||||
session().api().sendInlineResult(bot, result, action, localMessageId);
|
session().api().sendInlineResult(
|
||||||
|
bot,
|
||||||
|
result.get(),
|
||||||
|
action,
|
||||||
|
localMessageId);
|
||||||
|
|
||||||
auto &bots = cRefRecentInlineBots();
|
auto &bots = cRefRecentInlineBots();
|
||||||
const auto index = bots.indexOf(bot);
|
const auto index = bots.indexOf(bot);
|
||||||
|
|
|
@ -127,10 +127,10 @@ private:
|
||||||
not_null<PhotoData*> photo,
|
not_null<PhotoData*> photo,
|
||||||
Api::SendOptions options);
|
Api::SendOptions options);
|
||||||
void sendInlineResult(
|
void sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot);
|
not_null<UserData*> bot);
|
||||||
void sendInlineResult(
|
void sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
Api::SendOptions options,
|
Api::SendOptions options,
|
||||||
std::optional<MsgId> localMessageId);
|
std::optional<MsgId> localMessageId);
|
||||||
|
|
|
@ -223,10 +223,10 @@ private:
|
||||||
not_null<PhotoData*> photo,
|
not_null<PhotoData*> photo,
|
||||||
Api::SendOptions options);
|
Api::SendOptions options);
|
||||||
void sendInlineResult(
|
void sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot);
|
not_null<UserData*> bot);
|
||||||
void sendInlineResult(
|
void sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
Api::SendOptions options,
|
Api::SendOptions options,
|
||||||
std::optional<MsgId> localMessageId);
|
std::optional<MsgId> localMessageId);
|
||||||
|
@ -1534,7 +1534,7 @@ bool ShortcutMessages::sendExistingPhoto(
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutMessages::sendInlineResult(
|
void ShortcutMessages::sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot) {
|
not_null<UserData*> bot) {
|
||||||
if (showPremiumRequired()) {
|
if (showPremiumRequired()) {
|
||||||
return;
|
return;
|
||||||
|
@ -1542,11 +1542,11 @@ void ShortcutMessages::sendInlineResult(
|
||||||
Data::ShowSendErrorToast(_controller, _history->peer, error);
|
Data::ShowSendErrorToast(_controller, _history->peer, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendInlineResult(result, bot, {}, std::nullopt);
|
sendInlineResult(std::move(result), bot, {}, std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutMessages::sendInlineResult(
|
void ShortcutMessages::sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
std::shared_ptr<InlineBots::Result> result,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
Api::SendOptions options,
|
Api::SendOptions options,
|
||||||
std::optional<MsgId> localMessageId) {
|
std::optional<MsgId> localMessageId) {
|
||||||
|
@ -1555,7 +1555,11 @@ void ShortcutMessages::sendInlineResult(
|
||||||
}
|
}
|
||||||
auto action = prepareSendAction(options);
|
auto action = prepareSendAction(options);
|
||||||
action.generateLocal = true;
|
action.generateLocal = true;
|
||||||
_session->api().sendInlineResult(bot, result, action, localMessageId);
|
_session->api().sendInlineResult(
|
||||||
|
bot,
|
||||||
|
result.get(),
|
||||||
|
action,
|
||||||
|
localMessageId);
|
||||||
|
|
||||||
_composeControls->clear();
|
_composeControls->clear();
|
||||||
//_saveDraftText = true;
|
//_saveDraftText = true;
|
||||||
|
|
|
@ -1684,12 +1684,12 @@ void PeerMenuShareContactBox(
|
||||||
: ('\xAB' + title + '\xBB');
|
: ('\xAB' + title + '\xBB');
|
||||||
struct State {
|
struct State {
|
||||||
base::weak_ptr<Data::Thread> weak;
|
base::weak_ptr<Data::Thread> weak;
|
||||||
Fn<void(Api::SendOptions)> share;
|
FnMut<void(Api::SendOptions)> share;
|
||||||
SendPaymentHelper sendPayment;
|
SendPaymentHelper sendPayment;
|
||||||
};
|
};
|
||||||
const auto state = std::make_shared<State>();
|
auto state = std::make_shared<State>();
|
||||||
state->weak = thread;
|
state->weak = thread;
|
||||||
state->share = [=](Api::SendOptions options) {
|
state->share = [=](Api::SendOptions options) mutable {
|
||||||
const auto strong = state->weak.get();
|
const auto strong = state->weak.get();
|
||||||
if (!strong) {
|
if (!strong) {
|
||||||
return;
|
return;
|
||||||
|
@ -1715,6 +1715,7 @@ void PeerMenuShareContactBox(
|
||||||
auto action = Api::SendAction(strong, options);
|
auto action = Api::SendAction(strong, options);
|
||||||
action.clearDraft = false;
|
action.clearDraft = false;
|
||||||
strong->session().api().shareContact(user, action);
|
strong->session().api().shareContact(user, action);
|
||||||
|
state = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
navigation->parentController()->show(
|
navigation->parentController()->show(
|
||||||
|
|
Loading…
Add table
Reference in a new issue