Allow sending stickers / GIFs in story replies.

This commit is contained in:
John Preston 2023-05-26 20:30:02 +04:00
parent cdd4774bb8
commit d82381881a
7 changed files with 147 additions and 16 deletions

View file

@ -1192,9 +1192,9 @@ void Show(
} // namespace } // namespace
void ShowStickerPreviewBox( void ShowStickerPreviewBox(
not_null<Window::SessionController*> controller, std::shared_ptr<ChatHelpers::Show> show,
not_null<DocumentData*> document) { not_null<DocumentData*> document) {
Show(controller->uiShow(), Descriptor{ Show(std::move(show), Descriptor{
.section = PremiumPreview::Stickers, .section = PremiumPreview::Stickers,
.requestedSticker = document, .requestedSticker = document,
}); });

View file

@ -34,7 +34,7 @@ class Session;
} // namespace Main } // namespace Main
void ShowStickerPreviewBox( void ShowStickerPreviewBox(
not_null<Window::SessionController*> controller, std::shared_ptr<ChatHelpers::Show> show,
not_null<DocumentData*> document); not_null<DocumentData*> document);
void DoubledLimitsPreviewBox( void DoubledLimitsPreviewBox(

View file

@ -345,7 +345,7 @@ std::shared_ptr<ChatHelpers::Show> Controller::uiShow() const {
} }
auto Controller::stickerOrEmojiChosen() const auto Controller::stickerOrEmojiChosen() const
->rpl::producer<ChatHelpers::FileChosen> { -> rpl::producer<ChatHelpers::FileChosen> {
return _delegate->storiesStickerOrEmojiChosen(); return _delegate->storiesStickerOrEmojiChosen();
} }

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "media/stories/media_stories_reply.h" #include "media/stories/media_stories_reply.h"
#include "api/api_common.h" #include "api/api_common.h"
#include "api/api_sending.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "base/call_delayed.h" #include "base/call_delayed.h"
#include "boxes/premium_limits_box.h" #include "boxes/premium_limits_box.h"
@ -28,8 +29,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "media/stories/media_stories_controller.h" #include "media/stories/media_stories_controller.h"
#include "menu/menu_send.h" #include "menu/menu_send.h"
#include "storage/localimageloader.h" #include "storage/localimageloader.h"
#include "storage/storage_account.h"
#include "storage/storage_media_prepare.h" #include "storage/storage_media_prepare.h"
#include "ui/chat/attach/attach_prepare.h" #include "ui/chat/attach/attach_prepare.h"
#include "window/section_widget.h"
#include "styles/style_boxes.h" // sendMediaPreviewSize. #include "styles/style_boxes.h" // sendMediaPreviewSize.
#include "styles/style_chat_helpers.h" #include "styles/style_chat_helpers.h"
#include "styles/style_media_view.h" #include "styles/style_media_view.h"
@ -134,6 +137,96 @@ void ReplyArea::sendVoice(VoiceToSend &&data) {
finishSending(); finishSending();
} }
bool ReplyArea::sendExistingDocument(
not_null<DocumentData*> document,
Api::SendOptions options,
std::optional<MsgId> localId) {
Expects(_data.user != nullptr);
const auto show = _controller->uiShow();
const auto error = Data::RestrictionError(
_data.user,
ChatRestriction::SendStickers);
if (error) {
show->showToast(*error);
return false;
} else if (Window::ShowSendPremiumError(show, document)) {
return false;
}
Api::SendExistingDocument(
Api::MessageToSend(prepareSendAction(options)),
document,
localId);
_controls->cancelReplyMessage();
finishSending();
return true;
}
void ReplyArea::sendExistingPhoto(not_null<PhotoData*> photo) {
sendExistingPhoto(photo, {});
}
bool ReplyArea::sendExistingPhoto(
not_null<PhotoData*> photo,
Api::SendOptions options) {
Expects(_data.user != nullptr);
const auto show = _controller->uiShow();
const auto error = Data::RestrictionError(
_data.user,
ChatRestriction::SendPhotos);
if (error) {
show->showToast(*error);
return false;
}
Api::SendExistingPhoto(
Api::MessageToSend(prepareSendAction(options)),
photo);
_controls->cancelReplyMessage();
finishSending();
return true;
}
void ReplyArea::sendInlineResult(
not_null<InlineBots::Result*> result,
not_null<UserData*> bot) {
const auto errorText = result->getErrorOnSend(history());
if (!errorText.isEmpty()) {
_controller->uiShow()->showToast(errorText);
return;
}
sendInlineResult(result, bot, {}, std::nullopt);
}
void ReplyArea::sendInlineResult(
not_null<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);
_controls->clear();
auto &bots = cRefRecentInlineBots();
const auto index = bots.indexOf(bot);
if (index) {
if (index > 0) {
bots.removeAt(index);
} else if (bots.size() >= RecentInlineBotsLimit) {
bots.resize(RecentInlineBotsLimit - 1);
}
bots.push_front(bot);
bot->session().local().writeRecentHashtagsAndBots();
}
finishSending();
}
void ReplyArea::finishSending() { void ReplyArea::finishSending() {
_controls->hidePanelsAnimated(); _controls->hidePanelsAnimated();
_controller->wrap()->setFocus(); _controller->wrap()->setFocus();
@ -188,12 +281,17 @@ bool ReplyArea::showSendingFilesError(
return true; return true;
} }
not_null<History*> ReplyArea::history() const {
Expects(_data.user != nullptr);
return _data.user->owner().history(_data.user);
}
Api::SendAction ReplyArea::prepareSendAction( Api::SendAction ReplyArea::prepareSendAction(
Api::SendOptions options) const { Api::SendOptions options) const {
Expects(_data.user != nullptr); Expects(_data.user != nullptr);
const auto history = _data.user->owner().history(_data.user); auto result = Api::SendAction(history(), options);
auto result = Api::SendAction(history, options);
result.options.sendAs = _controls->sendAsPeer(); result.options.sendAs = _controls->sendAsPeer();
result.replyTo.storyId = { .peer = _data.user->id, .story = _data.id }; result.replyTo.storyId = { .peer = _data.user->id, .story = _data.id };
return result; return result;
@ -402,23 +500,19 @@ void ReplyArea::initActions() {
_controls->fileChosen( _controls->fileChosen(
) | rpl::start_with_next([=](ChatHelpers::FileChosen data) { ) | rpl::start_with_next([=](ChatHelpers::FileChosen data) {
_controller->uiShow()->hideLayer(); _controller->uiShow()->hideLayer();
//controller()->sendingAnimation().appendSending( const auto localId = data.messageSendingFrom.localId;
// data.messageSendingFrom); sendExistingDocument(data.document, data.options, localId);
//const auto localId = data.messageSendingFrom.localId;
//sendExistingDocument(data.document, data.options, localId);
}, _lifetime); }, _lifetime);
_controls->photoChosen( _controls->photoChosen(
) | rpl::start_with_next([=](ChatHelpers::PhotoChosen chosen) { ) | rpl::start_with_next([=](ChatHelpers::PhotoChosen chosen) {
//sendExistingPhoto(chosen.photo, chosen.options); sendExistingPhoto(chosen.photo, chosen.options);
}, _lifetime); }, _lifetime);
_controls->inlineResultChosen( _controls->inlineResultChosen(
) | rpl::start_with_next([=](ChatHelpers::InlineChosen chosen) { ) | rpl::start_with_next([=](ChatHelpers::InlineChosen chosen) {
//controller()->sendingAnimation().appendSending( const auto localId = chosen.messageSendingFrom.localId;
// chosen.messageSendingFrom); sendInlineResult(chosen.result, chosen.bot, chosen.options, localId);
//const auto localId = chosen.messageSendingFrom.localId;
//sendInlineResult(chosen.result, chosen.bot, chosen.options, localId);
}, _lifetime); }, _lifetime);
_controls->setMimeDataHook([=]( _controls->setMimeDataHook([=](

View file

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/weak_ptr.h" #include "base/weak_ptr.h"
class History;
enum class SendMediaType; enum class SendMediaType;
namespace Api { namespace Api {
@ -24,6 +25,10 @@ namespace HistoryView::Controls {
struct VoiceToSend; struct VoiceToSend;
} // namespace HistoryView::Controls } // namespace HistoryView::Controls
namespace InlineBots {
class Result;
} // namespace InlineBots
namespace Main { namespace Main {
class Session; class Session;
} // namespace Main } // namespace Main
@ -58,6 +63,7 @@ private:
using VoiceToSend = HistoryView::Controls::VoiceToSend; using VoiceToSend = HistoryView::Controls::VoiceToSend;
[[nodiscard]] Main::Session &session() const; [[nodiscard]] Main::Session &session() const;
[[nodiscard]] not_null<History*> history() const;
bool confirmSendingFiles(const QStringList &files); bool confirmSendingFiles(const QStringList &files);
bool confirmSendingFiles(not_null<const QMimeData*> data); bool confirmSendingFiles(not_null<const QMimeData*> data);
@ -90,6 +96,24 @@ private:
bool ctrlShiftEnter); bool ctrlShiftEnter);
void finishSending(); void finishSending();
void sendExistingDocument(not_null<DocumentData*> document);
bool sendExistingDocument(
not_null<DocumentData*> document,
Api::SendOptions options,
std::optional<MsgId> localId);
void sendExistingPhoto(not_null<PhotoData*> photo);
bool sendExistingPhoto(
not_null<PhotoData*> photo,
Api::SendOptions options);
void sendInlineResult(
not_null<InlineBots::Result*> result,
not_null<UserData*> bot);
void sendInlineResult(
not_null<InlineBots::Result*> result,
not_null<UserData*> bot,
Api::SendOptions options,
std::optional<MsgId> localMessageId);
void initGeometry(); void initGeometry();
void initActions(); void initActions();

View file

@ -457,11 +457,17 @@ auto ChatThemeValueFromPeer(
bool ShowSendPremiumError( bool ShowSendPremiumError(
not_null<SessionController*> controller, not_null<SessionController*> controller,
not_null<DocumentData*> document) { not_null<DocumentData*> document) {
return ShowSendPremiumError(controller->uiShow(), document);
}
bool ShowSendPremiumError(
std::shared_ptr<ChatHelpers::Show> show,
not_null<DocumentData*> document) {
if (!document->isPremiumSticker() if (!document->isPremiumSticker()
|| document->session().premium()) { || document->session().premium()) {
return false; return false;
} }
ShowStickerPreviewBox(controller, document); ShowStickerPreviewBox(std::move(show), document);
return true; return true;
} }

View file

@ -16,6 +16,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class PeerData; class PeerData;
namespace ChatHelpers {
class Show;
} // namespace ChatHelpers
namespace Data { namespace Data {
struct ReactionId; struct ReactionId;
class ForumTopic; class ForumTopic;
@ -238,6 +242,9 @@ private:
[[nodiscard]] bool ShowSendPremiumError( [[nodiscard]] bool ShowSendPremiumError(
not_null<SessionController*> controller, not_null<SessionController*> controller,
not_null<DocumentData*> document); not_null<DocumentData*> document);
[[nodiscard]] bool ShowSendPremiumError(
std::shared_ptr<ChatHelpers::Show> show,
not_null<DocumentData*> document);
[[nodiscard]] bool ShowReactPremiumError( [[nodiscard]] bool ShowReactPremiumError(
not_null<SessionController*> controller, not_null<SessionController*> controller,