Initial code of attaching effect selector.

This commit is contained in:
John Preston 2024-05-09 21:01:01 +04:00
parent 92133e7f50
commit 396ba9a984
30 changed files with 163 additions and 83 deletions

View File

@ -561,6 +561,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_reaction_invoice" = "{reaction} to your invoice"; "lng_reaction_invoice" = "{reaction} to your invoice";
"lng_reaction_gif" = "{reaction} to your GIF"; "lng_reaction_gif" = "{reaction} to your GIF";
"lng_effect_add_title" = "Add an animated effect";
"lng_effect_stickers_title" = "Message Effects";
"lng_languages" = "Languages"; "lng_languages" = "Languages";
"lng_languages_none" = "No languages found."; "lng_languages_none" = "No languages found.";
"lng_languages_count#one" = "{count} language"; "lng_languages_count#one" = "{count} language";

View File

@ -1295,6 +1295,7 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
_controller->show( _controller->show(
HistoryView::PrepareScheduleBox( HistoryView::PrepareScheduleBox(
this, this,
_controller->uiShow(),
SendMenu::Type::Scheduled, SendMenu::Type::Scheduled,
send)); send));
}; };
@ -1327,6 +1328,7 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
}; };
SendMenu::SetupMenuAndShortcuts( SendMenu::SetupMenuAndShortcuts(
submit.data(), submit.data(),
_controller->uiShow(),
sendMenuType, sendMenuType,
sendSilent, sendSilent,
sendScheduled, sendScheduled,

View File

@ -529,6 +529,7 @@ void SendFilesBox::refreshButtons() {
if (_sendType == Api::SendType::Normal) { if (_sendType == Api::SendType::Normal) {
SendMenu::SetupMenuAndShortcuts( SendMenu::SetupMenuAndShortcuts(
_send, _send,
_show,
[=] { return _sendMenuType; }, [=] { return _sendMenuType; },
[=] { sendSilent(); }, [=] { sendSilent(); },
[=] { sendScheduled(); }, [=] { sendScheduled(); },
@ -1472,7 +1473,7 @@ void SendFilesBox::sendScheduled() {
? SendMenu::Type::ScheduledToUser ? SendMenu::Type::ScheduledToUser
: _sendMenuType; : _sendMenuType;
const auto callback = [=](Api::SendOptions options) { send(options); }; const auto callback = [=](Api::SendOptions options) { send(options); };
auto box = HistoryView::PrepareScheduleBox(this, type, callback); auto box = HistoryView::PrepareScheduleBox(this, _show, type, callback);
const auto weak = Ui::MakeWeak(box.data()); const auto weak = Ui::MakeWeak(box.data());
_show->showBox(std::move(box)); _show->showBox(std::move(box));
if (const auto strong = weak.data()) { if (const auto strong = weak.data()) {

View File

@ -616,6 +616,7 @@ void ShareBox::submitScheduled() {
uiShow()->showBox( uiShow()->showBox(
HistoryView::PrepareScheduleBox( HistoryView::PrepareScheduleBox(
this, this,
nullptr, // ChatHelpers::Show for effect attachment.
sendMenuType(), sendMenuType(),
callback, callback,
HistoryView::DefaultScheduleTime(), HistoryView::DefaultScheduleTime(),

View File

@ -351,8 +351,7 @@ HistoryInner::HistoryInner(
, _reactionsManager( , _reactionsManager(
std::make_unique<HistoryView::Reactions::Manager>( std::make_unique<HistoryView::Reactions::Manager>(
this, this,
[=](QRect updated) { update(updated); }, [=](QRect updated) { update(updated); }))
controller->cachedReactionIconFactory().createMethod()))
, _touchSelectTimer([=] { onTouchSelect(); }) , _touchSelectTimer([=] { onTouchSelect(); })
, _touchScrollTimer([=] { onTouchScrollTimer(); }) , _touchScrollTimer([=] { onTouchScrollTimer(); })
, _scrollDateCheck([this] { scrollDateCheck(); }) , _scrollDateCheck([this] { scrollDateCheck(); })
@ -2778,8 +2777,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
desiredPosition, desiredPosition,
reactItem, reactItem,
[=](ChosenReaction reaction) { reactionChosen(reaction); }, [=](ChosenReaction reaction) { reactionChosen(reaction); },
ItemReactionsAbout(reactItem), ItemReactionsAbout(reactItem))
_controller->cachedReactionIconFactory().createMethod())
: AttachSelectorResult::Skipped; : AttachSelectorResult::Skipped;
if (attached == AttachSelectorResult::Failed) { if (attached == AttachSelectorResult::Failed) {
_menu = nullptr; _menu = nullptr;

View File

@ -323,6 +323,7 @@ HistoryWidget::HistoryWidget(
SendMenu::SetupMenuAndShortcuts( SendMenu::SetupMenuAndShortcuts(
_send.get(), _send.get(),
controller->uiShow(),
[=] { return sendButtonMenuType(); }, [=] { return sendButtonMenuType(); },
[=] { sendSilent(); }, [=] { sendSilent(); },
[=] { sendScheduled(); }, [=] { sendScheduled(); },
@ -4192,7 +4193,11 @@ void HistoryWidget::sendScheduled() {
} }
const auto callback = [=](Api::SendOptions options) { send(options); }; const auto callback = [=](Api::SendOptions options) { send(options); };
controller()->show( controller()->show(
HistoryView::PrepareScheduleBox(_list, sendMenuType(), callback)); HistoryView::PrepareScheduleBox(
_list,
controller()->uiShow(),
sendMenuType(),
callback));
} }
void HistoryWidget::sendWhenOnline() { void HistoryWidget::sendWhenOnline() {

View File

@ -2197,6 +2197,7 @@ void ComposeControls::initSendButton() {
SendMenu::SetupMenuAndShortcuts( SendMenu::SetupMenuAndShortcuts(
_send.get(), _send.get(),
_show,
[=] { return sendButtonMenuType(); }, [=] { return sendButtonMenuType(); },
SendMenu::DefaultSilentCallback(send), SendMenu::DefaultSilentCallback(send),
SendMenu::DefaultScheduleCallback(_show, sendMenuType(), send), SendMenu::DefaultScheduleCallback(_show, sendMenuType(), send),

View File

@ -589,6 +589,7 @@ bool AddRescheduleAction(
const auto box = request.navigation->parentController()->show( const auto box = request.navigation->parentController()->show(
HistoryView::PrepareScheduleBox( HistoryView::PrepareScheduleBox(
&request.navigation->session(), &request.navigation->session(),
request.navigation->uiShow(),
sendMenuType, sendMenuType,
callback, callback,
date)); date));

View File

@ -115,8 +115,7 @@ auto WindowListDelegate::listMakeReactionsManager(
-> std::unique_ptr<Reactions::Manager> { -> std::unique_ptr<Reactions::Manager> {
return std::make_unique<Reactions::Manager>( return std::make_unique<Reactions::Manager>(
wheelEventsTarget, wheelEventsTarget,
std::move(update), std::move(update));
_window->cachedReactionIconFactory().createMethod());
} }
void WindowListDelegate::listVisibleAreaUpdated() { void WindowListDelegate::listVisibleAreaUpdated() {
@ -2780,8 +2779,7 @@ void ListWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
desiredPosition, desiredPosition,
reactItem, reactItem,
[=](ChosenReaction reaction) { reactionChosen(reaction); }, [=](ChosenReaction reaction) { reactionChosen(reaction); },
ItemReactionsAbout(reactItem), ItemReactionsAbout(reactItem))
controller()->cachedReactionIconFactory().createMethod())
: AttachSelectorResult::Skipped; : AttachSelectorResult::Skipped;
if (attached == AttachSelectorResult::Failed) { if (attached == AttachSelectorResult::Failed) {
_menu = nullptr; _menu = nullptr;

View File

@ -69,6 +69,7 @@ bool CanScheduleUntilOnline(not_null<PeerData*> peer) {
void ScheduleBox( void ScheduleBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
std::shared_ptr<ChatHelpers::Show> show,
SendMenu::Type type, SendMenu::Type type,
Fn<void(Api::SendOptions)> done, Fn<void(Api::SendOptions)> done,
TimeId time, TimeId time,
@ -98,6 +99,7 @@ void ScheduleBox(
using T = SendMenu::Type; using T = SendMenu::Type;
SendMenu::SetupMenuAndShortcuts( SendMenu::SetupMenuAndShortcuts(
descriptor.submit.data(), descriptor.submit.data(),
show,
[t = type == T::Disabled ? T::Disabled : T::SilentOnly] { return t; }, [t = type == T::Disabled ? T::Disabled : T::SilentOnly] { return t; },
[=] { save(true, descriptor.collect()); }, [=] { save(true, descriptor.collect()); },
nullptr, nullptr,

View File

@ -18,6 +18,10 @@ namespace Api {
struct SendOptions; struct SendOptions;
} // namespace Api } // namespace Api
namespace ChatHelpers {
class Show;
} // namespace ChatHelpers
namespace SendMenu { namespace SendMenu {
enum class Type; enum class Type;
} // namespace SendMenu } // namespace SendMenu
@ -36,6 +40,7 @@ struct ScheduleBoxStyleArgs {
void ScheduleBox( void ScheduleBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
std::shared_ptr<ChatHelpers::Show> show,
SendMenu::Type type, SendMenu::Type type,
Fn<void(Api::SendOptions)> done, Fn<void(Api::SendOptions)> done,
TimeId time, TimeId time,
@ -44,12 +49,14 @@ void ScheduleBox(
template <typename Guard, typename Submit> template <typename Guard, typename Submit>
[[nodiscard]] object_ptr<Ui::GenericBox> PrepareScheduleBox( [[nodiscard]] object_ptr<Ui::GenericBox> PrepareScheduleBox(
Guard &&guard, Guard &&guard,
std::shared_ptr<ChatHelpers::Show> show,
SendMenu::Type type, SendMenu::Type type,
Submit &&submit, Submit &&submit,
TimeId scheduleTime = DefaultScheduleTime(), TimeId scheduleTime = DefaultScheduleTime(),
ScheduleBoxStyleArgs style = ScheduleBoxStyleArgs()) { ScheduleBoxStyleArgs style = ScheduleBoxStyleArgs()) {
return Box( return Box(
ScheduleBox, ScheduleBox,
std::move(show),
type, type,
crl::guard(std::forward<Guard>(guard), std::forward<Submit>(submit)), crl::guard(std::forward<Guard>(guard), std::forward<Submit>(submit)),
scheduleTime, scheduleTime,

View File

@ -98,6 +98,7 @@ ScheduledWidget::ScheduledWidget(
const Data::ForumTopic *forumTopic) const Data::ForumTopic *forumTopic)
: Window::SectionWidget(parent, controller, history->peer) : Window::SectionWidget(parent, controller, history->peer)
, WindowListDelegate(controller) , WindowListDelegate(controller)
, _show(controller->uiShow())
, _history(history) , _history(history)
, _forumTopic(forumTopic) , _forumTopic(forumTopic)
, _scroll( , _scroll(
@ -600,7 +601,8 @@ void ScheduledWidget::uploadFile(
type, type,
prepareSendAction(options)); prepareSendAction(options));
}; };
controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); controller()->show(
PrepareScheduleBox(this, _show, sendMenuType(), callback));
} }
bool ScheduledWidget::showSendingFilesError( bool ScheduledWidget::showSendingFilesError(
@ -678,7 +680,8 @@ void ScheduledWidget::send() {
return; return;
} }
const auto callback = [=](Api::SendOptions options) { send(options); }; const auto callback = [=](Api::SendOptions options) { send(options); };
controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); controller()->show(
PrepareScheduleBox(this, _show, sendMenuType(), callback));
} }
void ScheduledWidget::send(Api::SendOptions options) { void ScheduledWidget::send(Api::SendOptions options) {
@ -709,7 +712,8 @@ void ScheduledWidget::sendVoice(
const auto callback = [=](Api::SendOptions options) { const auto callback = [=](Api::SendOptions options) {
sendVoice(bytes, waveform, duration, options); sendVoice(bytes, waveform, duration, options);
}; };
controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); controller()->show(
PrepareScheduleBox(this, _show, sendMenuType(), callback));
} }
void ScheduledWidget::sendVoice( void ScheduledWidget::sendVoice(
@ -809,7 +813,8 @@ void ScheduledWidget::sendExistingDocument(
const auto callback = [=](Api::SendOptions options) { const auto callback = [=](Api::SendOptions options) {
sendExistingDocument(document, options); sendExistingDocument(document, options);
}; };
controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); controller()->show(
PrepareScheduleBox(this, _show, sendMenuType(), callback));
} }
bool ScheduledWidget::sendExistingDocument( bool ScheduledWidget::sendExistingDocument(
@ -838,7 +843,8 @@ void ScheduledWidget::sendExistingPhoto(not_null<PhotoData*> photo) {
const auto callback = [=](Api::SendOptions options) { const auto callback = [=](Api::SendOptions options) {
sendExistingPhoto(photo, options); sendExistingPhoto(photo, options);
}; };
controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); controller()->show(
PrepareScheduleBox(this, _show, sendMenuType(), callback));
} }
bool ScheduledWidget::sendExistingPhoto( bool ScheduledWidget::sendExistingPhoto(
@ -872,7 +878,8 @@ void ScheduledWidget::sendInlineResult(
const auto callback = [=](Api::SendOptions options) { const auto callback = [=](Api::SendOptions options) {
sendInlineResult(result, bot, options); sendInlineResult(result, bot, options);
}; };
controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); controller()->show(
PrepareScheduleBox(this, _show, sendMenuType(), callback));
} }
void ScheduledWidget::sendInlineResult( void ScheduledWidget::sendInlineResult(
@ -1360,7 +1367,8 @@ void ScheduledWidget::listSendBotCommand(
message.textWithTags = { text }; message.textWithTags = { text };
session().api().sendMessage(std::move(message)); session().api().sendMessage(std::move(message));
}; };
controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); controller()->show(
PrepareScheduleBox(this, _show, sendMenuType(), callback));
} }
void ScheduledWidget::listSearch( void ScheduledWidget::listSearch(

View File

@ -17,6 +17,10 @@ class History;
enum class SendMediaType; enum class SendMediaType;
struct SendingAlbum; struct SendingAlbum;
namespace ChatHelpers {
class Show;
} // namespace ChatHelpers
namespace SendMenu { namespace SendMenu {
enum class Type; enum class Type;
} // namespace SendMenu } // namespace SendMenu
@ -262,6 +266,7 @@ private:
not_null<UserData*> bot, not_null<UserData*> bot,
Api::SendOptions options); Api::SendOptions options);
const std::shared_ptr<ChatHelpers::Show> _show;
const not_null<History*> _history; const not_null<History*> _history;
const Data::ForumTopic *_forumTopic; const Data::ForumTopic *_forumTopic;
std::shared_ptr<Ui::ChatTheme> _theme; std::shared_ptr<Ui::ChatTheme> _theme;

View File

@ -138,7 +138,7 @@ public:
Manager( Manager(
QWidget *wheelEventsTarget, QWidget *wheelEventsTarget,
Fn<void(QRect)> buttonUpdate, Fn<void(QRect)> buttonUpdate,
IconFactory iconFactory); IconFactory iconFactory = nullptr);
~Manager(); ~Manager();
using ReactionId = ::Data::ReactionId; using ReactionId = ::Data::ReactionId;

View File

@ -200,8 +200,8 @@ Selector::Selector(
std::shared_ptr<ChatHelpers::Show> show, std::shared_ptr<ChatHelpers::Show> show,
const Data::PossibleItemReactionsRef &reactions, const Data::PossibleItemReactionsRef &reactions,
TextWithEntities about, TextWithEntities about,
IconFactory iconFactory,
Fn<void(bool fast)> close, Fn<void(bool fast)> close,
IconFactory iconFactory,
bool child) bool child)
: Selector( : Selector(
parent, parent,
@ -261,14 +261,12 @@ Selector::Selector(
QSize(2 * st::reactStripSkip + st::reactStripSize, st::reactStripHeight), QSize(2 * st::reactStripSkip + st::reactStripSize, st::reactStripHeight),
st::reactionCornerShadow, st::reactionCornerShadow,
st::reactStripHeight) st::reactStripHeight)
, _strip(iconFactory , _strip(std::make_unique<Strip>(
? std::make_unique<Strip>( _st,
_st, QRect(0, 0, st::reactStripSize, st::reactStripSize),
QRect(0, 0, st::reactStripSize, st::reactStripSize), st::reactStripImage,
st::reactStripImage, crl::guard(this, [=] { update(_inner); }),
crl::guard(this, [=] { update(_inner); }), std::move(iconFactory)))
std::move(iconFactory))
: nullptr)
, _about(about.empty() , _about(about.empty()
? nullptr ? nullptr
: std::make_unique<Ui::FlatLabel>( : std::make_unique<Ui::FlatLabel>(
@ -1221,8 +1219,8 @@ auto AttachSelectorToMenu(
std::move(show), std::move(show),
std::move(reactions), std::move(reactions),
std::move(about), std::move(about),
std::move(iconFactory),
[=](bool fast) { menu->hideMenu(fast); }, [=](bool fast) { menu->hideMenu(fast); },
std::move(iconFactory),
false); // child false); // child
if (!AdjustMenuGeometryForSelector(menu, desiredPosition, selector)) { if (!AdjustMenuGeometryForSelector(menu, desiredPosition, selector)) {
return base::make_unexpected(AttachSelectorResult::Failed); return base::make_unexpected(AttachSelectorResult::Failed);

View File

@ -82,8 +82,8 @@ public:
std::shared_ptr<ChatHelpers::Show> show, std::shared_ptr<ChatHelpers::Show> show,
const Data::PossibleItemReactionsRef &reactions, const Data::PossibleItemReactionsRef &reactions,
TextWithEntities about, TextWithEntities about,
IconFactory iconFactory,
Fn<void(bool fast)> close, Fn<void(bool fast)> close,
IconFactory iconFactory = nullptr,
bool child = false); bool child = false);
Selector( Selector(
not_null<QWidget*> parent, not_null<QWidget*> parent,
@ -253,7 +253,7 @@ AttachSelectorResult AttachSelectorToMenu(
not_null<HistoryItem*> item, not_null<HistoryItem*> item,
Fn<void(ChosenReaction)> chosen, Fn<void(ChosenReaction)> chosen,
TextWithEntities about, TextWithEntities about,
IconFactory iconFactory); IconFactory iconFactory = nullptr);
[[nodiscard]] auto AttachSelectorToMenu( [[nodiscard]] auto AttachSelectorToMenu(
not_null<Ui::PopupMenu*> menu, not_null<Ui::PopupMenu*> menu,
@ -262,7 +262,7 @@ AttachSelectorResult AttachSelectorToMenu(
std::shared_ptr<ChatHelpers::Show> show, std::shared_ptr<ChatHelpers::Show> show,
const Data::PossibleItemReactionsRef &reactions, const Data::PossibleItemReactionsRef &reactions,
TextWithEntities about, TextWithEntities about,
IconFactory iconFactory IconFactory iconFactory = nullptr
) -> base::expected<not_null<Selector*>, AttachSelectorResult>; ) -> base::expected<not_null<Selector*>, AttachSelectorResult>;
[[nodiscard]] TextWithEntities ItemReactionsAbout( [[nodiscard]] TextWithEntities ItemReactionsAbout(

View File

@ -51,7 +51,9 @@ Strip::Strip(
Fn<void()> update, Fn<void()> update,
IconFactory iconFactory) IconFactory iconFactory)
: _st(st) : _st(st)
, _iconFactory(std::move(iconFactory)) , _iconFactory(iconFactory
? std::move(iconFactory)
: DefaultCachingIconFactory)
, _inner(inner) , _inner(inner)
, _finalSize(size) , _finalSize(size)
, _update(std::move(update)) { , _update(std::move(update)) {
@ -558,4 +560,11 @@ std::shared_ptr<Ui::AnimatedIcon> DefaultIconFactory(
return CreateIcon(media, size); return CreateIcon(media, size);
} }
std::shared_ptr<Ui::AnimatedIcon> DefaultCachingIconFactory(
not_null<Data::DocumentMedia*> media,
int size) {
auto &factory = media->owner()->session().cachedReactionIconFactory();
return factory.createMethod()(media, size);
}
} // namespace HistoryView::Reactions } // namespace HistoryView::Reactions

View File

@ -53,7 +53,7 @@ public:
QRect inner, QRect inner,
int size, int size,
Fn<void()> update, Fn<void()> update,
IconFactory iconFactory); IconFactory iconFactory = nullptr);
enum class AddedButton : uchar { enum class AddedButton : uchar {
None, None,
@ -173,4 +173,8 @@ private:
not_null<Data::DocumentMedia*> media, not_null<Data::DocumentMedia*> media,
int size); int size);
[[nodiscard]] std::shared_ptr<Ui::AnimatedIcon> DefaultCachingIconFactory(
not_null<Data::DocumentMedia*> media,
int size);
} // namespace HistoryView } // namespace HistoryView

View File

@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "chat_helpers/stickers_emoji_pack.h" #include "chat_helpers/stickers_emoji_pack.h"
#include "chat_helpers/stickers_dice_pack.h" #include "chat_helpers/stickers_dice_pack.h"
#include "chat_helpers/stickers_gift_box_pack.h" #include "chat_helpers/stickers_gift_box_pack.h"
#include "history/view/reactions/history_view_reactions_strip.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "inline_bots/bot_attach_web_view.h" #include "inline_bots/bot_attach_web_view.h"
@ -104,6 +105,7 @@ Session::Session(
, _scheduledMessages(std::make_unique<Data::ScheduledMessages>(this)) , _scheduledMessages(std::make_unique<Data::ScheduledMessages>(this))
, _sponsoredMessages(std::make_unique<Data::SponsoredMessages>(this)) , _sponsoredMessages(std::make_unique<Data::SponsoredMessages>(this))
, _topPeers(std::make_unique<Data::TopPeers>(this)) , _topPeers(std::make_unique<Data::TopPeers>(this))
, _cachedReactionIconFactory(std::make_unique<ReactionIconFactory>())
, _supportHelper(Support::Helper::Create(this)) , _supportHelper(Support::Helper::Create(this))
, _saveSettingsTimer([=] { saveSettings(); }) { , _saveSettingsTimer([=] { saveSettings(); }) {
Expects(_settings != nullptr); Expects(_settings != nullptr);

View File

@ -37,6 +37,10 @@ class SponsoredMessages;
class TopPeers; class TopPeers;
} // namespace Data } // namespace Data
namespace HistoryView::Reactions {
class CachedIconFactory;
} // namespace HistoryView::Reactions
namespace Storage { namespace Storage {
class DownloadManagerMtproto; class DownloadManagerMtproto;
class Uploader; class Uploader;
@ -156,6 +160,10 @@ public:
[[nodiscard]] InlineBots::AttachWebView &attachWebView() const { [[nodiscard]] InlineBots::AttachWebView &attachWebView() const {
return *_attachWebView; return *_attachWebView;
} }
[[nodiscard]] auto cachedReactionIconFactory() const
-> HistoryView::Reactions::CachedIconFactory & {
return *_cachedReactionIconFactory;
}
void saveSettings(); void saveSettings();
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay); void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
@ -217,8 +225,6 @@ public:
private: private:
static constexpr auto kDefaultSaveDelay = crl::time(1000); static constexpr auto kDefaultSaveDelay = crl::time(1000);
void parseColorIndices(const MTPDhelp_peerColors &data);
const UserId _userId; const UserId _userId;
const not_null<Account*> _account; const not_null<Account*> _account;
@ -246,6 +252,9 @@ private:
const std::unique_ptr<Data::SponsoredMessages> _sponsoredMessages; const std::unique_ptr<Data::SponsoredMessages> _sponsoredMessages;
const std::unique_ptr<Data::TopPeers> _topPeers; const std::unique_ptr<Data::TopPeers> _topPeers;
using ReactionIconFactory = HistoryView::Reactions::CachedIconFactory;
const std::unique_ptr<ReactionIconFactory> _cachedReactionIconFactory;
const std::unique_ptr<Support::Helper> _supportHelper; const std::unique_ptr<Support::Helper> _supportHelper;
std::shared_ptr<QImage> _selfUserpicView; std::shared_ptr<QImage> _selfUserpicView;

View File

@ -679,11 +679,6 @@ auto Controller::stickerOrEmojiChosen() const
return _delegate->storiesStickerOrEmojiChosen(); return _delegate->storiesStickerOrEmojiChosen();
} }
auto Controller::cachedReactionIconFactory() const
-> HistoryView::Reactions::CachedIconFactory & {
return _delegate->storiesCachedReactionIconFactory();
}
void Controller::rebuildFromContext( void Controller::rebuildFromContext(
not_null<PeerData*> peer, not_null<PeerData*> peer,
FullStoryId storyId) { FullStoryId storyId) {

View File

@ -30,7 +30,6 @@ class DocumentMedia;
} // namespace Data } // namespace Data
namespace HistoryView::Reactions { namespace HistoryView::Reactions {
class CachedIconFactory;
struct ChosenReaction; struct ChosenReaction;
enum class AttachSelectorResult; enum class AttachSelectorResult;
} // namespace HistoryView::Reactions } // namespace HistoryView::Reactions
@ -137,8 +136,6 @@ public:
[[nodiscard]] std::shared_ptr<ChatHelpers::Show> uiShow() const; [[nodiscard]] std::shared_ptr<ChatHelpers::Show> uiShow() const;
[[nodiscard]] auto stickerOrEmojiChosen() const [[nodiscard]] auto stickerOrEmojiChosen() const
-> rpl::producer<ChatHelpers::FileChosen>; -> rpl::producer<ChatHelpers::FileChosen>;
[[nodiscard]] auto cachedReactionIconFactory() const
-> HistoryView::Reactions::CachedIconFactory &;
void show(not_null<Data::Story*> story, Data::StoriesContext context); void show(not_null<Data::Story*> story, Data::StoriesContext context);
void jumpTo(not_null<Data::Story*> story, Data::StoriesContext context); void jumpTo(not_null<Data::Story*> story, Data::StoriesContext context);

View File

@ -17,10 +17,6 @@ class Story;
struct StoriesContext; struct StoriesContext;
} // namespace Data } // namespace Data
namespace HistoryView::Reactions {
class CachedIconFactory;
} // namespace HistoryView::Reactions
namespace Main { namespace Main {
class Session; class Session;
} // namespace Main } // namespace Main
@ -48,8 +44,6 @@ public:
-> std::shared_ptr<ChatHelpers::Show> = 0; -> std::shared_ptr<ChatHelpers::Show> = 0;
[[nodiscard]] virtual auto storiesStickerOrEmojiChosen() [[nodiscard]] virtual auto storiesStickerOrEmojiChosen()
-> rpl::producer<ChatHelpers::FileChosen> = 0; -> rpl::producer<ChatHelpers::FileChosen> = 0;
[[nodiscard]] virtual auto storiesCachedReactionIconFactory()
-> HistoryView::Reactions::CachedIconFactory & = 0;
virtual void storiesRedisplay(not_null<Data::Story*> story) = 0; virtual void storiesRedisplay(not_null<Data::Story*> story) = 0;
virtual void storiesJumpTo( virtual void storiesJumpTo(
not_null<Main::Session*> session, not_null<Main::Session*> session,

View File

@ -667,7 +667,6 @@ void Reactions::Panel::create() {
TextWithEntities{ (mode == Mode::Message TextWithEntities{ (mode == Mode::Message
? tr::lng_stories_reaction_as_message(tr::now) ? tr::lng_stories_reaction_as_message(tr::now)
: QString()) }, : QString()) },
_controller->cachedReactionIconFactory().createMethod(),
[=](bool fast) { hide(mode); }); [=](bool fast) { hide(mode); });
_selector->chosen( _selector->chosen(
@ -867,8 +866,7 @@ auto Reactions::attachToMenu(
st::storiesReactionsPan, st::storiesReactionsPan,
show, show,
LookupPossibleReactions(&show->session()), LookupPossibleReactions(&show->session()),
TextWithEntities(), TextWithEntities());
_controller->cachedReactionIconFactory().createMethod());
if (!result) { if (!result) {
return result.error(); return result.error();
} }

View File

@ -415,7 +415,6 @@ OverlayWidget::OverlayWidget()
, _widget(_surface->rpWidget()) , _widget(_surface->rpWidget())
, _fullscreen(Core::App().settings().mediaViewPosition().maximized == 2) , _fullscreen(Core::App().settings().mediaViewPosition().maximized == 2)
, _windowed(Core::App().settings().mediaViewPosition().maximized == 0) , _windowed(Core::App().settings().mediaViewPosition().maximized == 0)
, _cachedReactionIconFactory(std::make_unique<ReactionIconFactory>())
, _layerBg(std::make_unique<Ui::LayerManager>(_body)) , _layerBg(std::make_unique<Ui::LayerManager>(_body))
, _docDownload(_body, tr::lng_media_download(tr::now), st::mediaviewFileLink) , _docDownload(_body, tr::lng_media_download(tr::now), st::mediaviewFileLink)
, _docSaveAs(_body, tr::lng_mediaview_save_as(tr::now), st::mediaviewFileLink) , _docSaveAs(_body, tr::lng_mediaview_save_as(tr::now), st::mediaviewFileLink)
@ -4295,11 +4294,6 @@ auto OverlayWidget::storiesStickerOrEmojiChosen()
return _storiesStickerOrEmojiChosen.events(); return _storiesStickerOrEmojiChosen.events();
} }
auto OverlayWidget::storiesCachedReactionIconFactory()
-> HistoryView::Reactions::CachedIconFactory & {
return *_cachedReactionIconFactory;
}
void OverlayWidget::storiesJumpTo( void OverlayWidget::storiesJumpTo(
not_null<Main::Session*> session, not_null<Main::Session*> session,
FullStoryId id, FullStoryId id,

View File

@ -55,10 +55,6 @@ namespace Window::Theme {
struct Preview; struct Preview;
} // namespace Window::Theme } // namespace Window::Theme
namespace HistoryView::Reactions {
class CachedIconFactory;
} // namespace HistoryView::Reactions
namespace Media::Player { namespace Media::Player {
struct TrackState; struct TrackState;
} // namespace Media::Player } // namespace Media::Player
@ -251,8 +247,6 @@ private:
std::shared_ptr<ChatHelpers::Show> storiesShow() override; std::shared_ptr<ChatHelpers::Show> storiesShow() override;
auto storiesStickerOrEmojiChosen() auto storiesStickerOrEmojiChosen()
-> rpl::producer<ChatHelpers::FileChosen> override; -> rpl::producer<ChatHelpers::FileChosen> override;
auto storiesCachedReactionIconFactory()
-> HistoryView::Reactions::CachedIconFactory & override;
void storiesRedisplay(not_null<Data::Story*> story) override; void storiesRedisplay(not_null<Data::Story*> story) override;
void storiesJumpTo( void storiesJumpTo(
not_null<Main::Session*> session, not_null<Main::Session*> session,
@ -629,8 +623,6 @@ private:
bool _showAsPip = false; bool _showAsPip = false;
std::unique_ptr<Stories::View> _stories; std::unique_ptr<Stories::View> _stories;
using ReactionIconFactory = HistoryView::Reactions::CachedIconFactory;
std::unique_ptr<ReactionIconFactory> _cachedReactionIconFactory;
std::shared_ptr<Show> _cachedShow; std::shared_ptr<Show> _cachedShow;
rpl::event_stream<> _storiesChanged; rpl::event_stream<> _storiesChanged;
Main::Session *_storiesSession = nullptr; Main::Session *_storiesSession = nullptr;

View File

@ -10,13 +10,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_common.h" #include "api/api_common.h"
#include "base/event_filter.h" #include "base/event_filter.h"
#include "boxes/abstract_box.h" #include "boxes/abstract_box.h"
#include "chat_helpers/compose/compose_show.h"
#include "core/shortcuts.h" #include "core/shortcuts.h"
#include "history/view/reactions/history_view_reactions_selector.h"
#include "history/view/history_view_schedule_box.h" #include "history/view/history_view_schedule_box.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "ui/widgets/popup_menu.h" #include "ui/widgets/popup_menu.h"
#include "data/data_peer.h" #include "data/data_peer.h"
#include "data/data_forum.h" #include "data/data_forum.h"
#include "data/data_forum_topic.h" #include "data/data_forum_topic.h"
#include "data/data_message_reactions.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "history/history.h" #include "history/history.h"
@ -28,19 +31,51 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
namespace SendMenu { namespace SendMenu {
namespace {
[[nodiscard]] Data::PossibleItemReactionsRef LookupPossibleEffects(
not_null<Main::Session*> session) {
auto result = Data::PossibleItemReactionsRef();
const auto reactions = &session->data().reactions();
const auto &full = reactions->list(Data::Reactions::Type::Active);
const auto &top = reactions->list(Data::Reactions::Type::Top);
const auto &recent = reactions->list(Data::Reactions::Type::Recent);
const auto premiumPossible = session->premiumPossible();
auto added = base::flat_set<Data::ReactionId>();
result.recent.reserve(full.size());
for (const auto &reaction : ranges::views::concat(top, recent, full)) {
if (premiumPossible || !reaction.id.custom()) {
if (added.emplace(reaction.id).second) {
result.recent.push_back(&reaction);
}
}
}
result.customAllowed = premiumPossible;
const auto i = ranges::find(
result.recent,
reactions->favoriteId(),
&Data::Reaction::id);
if (i != end(result.recent) && i != begin(result.recent)) {
std::rotate(begin(result.recent), i, i + 1);
}
return result;
}
} // namespace
Fn<void()> DefaultSilentCallback(Fn<void(Api::SendOptions)> send) { Fn<void()> DefaultSilentCallback(Fn<void(Api::SendOptions)> send) {
return [=] { send({ .silent = true }); }; return [=] { send({ .silent = true }); };
} }
Fn<void()> DefaultScheduleCallback( Fn<void()> DefaultScheduleCallback(
std::shared_ptr<Ui::Show> show, std::shared_ptr<ChatHelpers::Show> show,
Type type, Type type,
Fn<void(Api::SendOptions)> send) { Fn<void(Api::SendOptions)> send) {
return [=, weak = Ui::MakeWeak(show->toastParent())] { return [=, weak = Ui::MakeWeak(show->toastParent())] {
show->showBox( show->showBox(
HistoryView::PrepareScheduleBox( HistoryView::PrepareScheduleBox(
weak, weak,
show,
type, type,
[=](Api::SendOptions options) { send(options); }), [=](Api::SendOptions options) { send(options); }),
Ui::LayerOption::KeepOther); Ui::LayerOption::KeepOther);
@ -95,6 +130,7 @@ FillMenuResult FillSendMenu(
void SetupMenuAndShortcuts( void SetupMenuAndShortcuts(
not_null<Ui::RpWidget*> button, not_null<Ui::RpWidget*> button,
std::shared_ptr<ChatHelpers::Show> show,
Fn<Type()> type, Fn<Type()> type,
Fn<void()> silent, Fn<void()> silent,
Fn<void()> schedule, Fn<void()> schedule,
@ -107,12 +143,35 @@ void SetupMenuAndShortcuts(
*menu = base::make_unique_q<Ui::PopupMenu>( *menu = base::make_unique_q<Ui::PopupMenu>(
button, button,
st::popupMenuWithIcons); st::popupMenuWithIcons);
const auto result = FillSendMenu(*menu, type(), silent, schedule, whenOnline); const auto result = FillSendMenu(
const auto success = (result == FillMenuResult::Success); *menu,
if (success) { type(),
(*menu)->popup(QCursor::pos()); silent,
schedule,
whenOnline);
if (result != FillMenuResult::Success) {
return false;
} }
return success; const auto desiredPosition = QCursor::pos();
using namespace HistoryView::Reactions;
const auto selector = show
? AttachSelectorToMenu(
menu->get(),
desiredPosition,
st::reactPanelEmojiPan,
show,
LookupPossibleEffects(&show->session()),
{ tr::lng_effect_add_title(tr::now) })
: base::make_unexpected(AttachSelectorResult::Skipped);
if (selector) {
//(*selector)->chosen();
(*menu)->popupPrepared();
} else if (selector.error() == AttachSelectorResult::Failed) {
return false;
} else {
(*menu)->popup(desiredPosition);
}
return true;
}; };
base::install_event_filter(button, [=](not_null<QEvent*> e) { base::install_event_filter(button, [=](not_null<QEvent*> e) {
if (e->type() == QEvent::ContextMenu && showMenu()) { if (e->type() == QEvent::ContextMenu && showMenu()) {

View File

@ -15,6 +15,10 @@ namespace Api {
struct SendOptions; struct SendOptions;
} // namespace Api } // namespace Api
namespace ChatHelpers {
class Show;
} // namespace ChatHelpers
namespace Ui { namespace Ui {
class PopupMenu; class PopupMenu;
class RpWidget; class RpWidget;
@ -42,7 +46,7 @@ enum class FillMenuResult {
Fn<void()> DefaultSilentCallback(Fn<void(Api::SendOptions)> send); Fn<void()> DefaultSilentCallback(Fn<void(Api::SendOptions)> send);
Fn<void()> DefaultScheduleCallback( Fn<void()> DefaultScheduleCallback(
std::shared_ptr<Ui::Show> show, std::shared_ptr<ChatHelpers::Show> show,
Type type, Type type,
Fn<void(Api::SendOptions)> send); Fn<void(Api::SendOptions)> send);
Fn<void()> DefaultWhenOnlineCallback(Fn<void(Api::SendOptions)> send); Fn<void()> DefaultWhenOnlineCallback(Fn<void(Api::SendOptions)> send);
@ -57,6 +61,7 @@ FillMenuResult FillSendMenu(
void SetupMenuAndShortcuts( void SetupMenuAndShortcuts(
not_null<Ui::RpWidget*> button, not_null<Ui::RpWidget*> button,
std::shared_ptr<ChatHelpers::Show> show,
Fn<Type()> type, Fn<Type()> type,
Fn<void()> silent, Fn<void()> silent,
Fn<void()> schedule, Fn<void()> schedule,

View File

@ -22,7 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/view/reactions/history_view_reactions.h" #include "history/view/reactions/history_view_reactions.h"
#include "history/view/reactions/history_view_reactions_button.h" //#include "history/view/reactions/history_view_reactions_button.h"
#include "history/view/history_view_replies_section.h" #include "history/view/history_view_replies_section.h"
#include "history/view/history_view_scheduled_section.h" #include "history/view/history_view_scheduled_section.h"
#include "media/player/media_player_instance.h" #include "media/player/media_player_instance.h"
@ -58,6 +58,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text/format_values.h" // Ui::FormatPhone. #include "ui/text/format_values.h" // Ui::FormatPhone.
#include "ui/delayed_activation.h" #include "ui/delayed_activation.h"
#include "ui/boxes/boost_box.h" #include "ui/boxes/boost_box.h"
#include "ui/chat/chat_style.h"
#include "ui/chat/chat_theme.h" #include "ui/chat/chat_theme.h"
#include "ui/effects/message_sending_animation_controller.h" #include "ui/effects/message_sending_animation_controller.h"
#include "ui/style/style_palette_colorizer.h" #include "ui/style/style_palette_colorizer.h"
@ -1190,7 +1191,6 @@ SessionController::SessionController(
, _activeChatsFilter(session->data().chatsFilters().defaultId()) , _activeChatsFilter(session->data().chatsFilters().defaultId())
, _defaultChatTheme(std::make_shared<Ui::ChatTheme>()) , _defaultChatTheme(std::make_shared<Ui::ChatTheme>())
, _chatStyle(std::make_unique<Ui::ChatStyle>(session->colorIndicesValue())) , _chatStyle(std::make_unique<Ui::ChatStyle>(session->colorIndicesValue()))
, _cachedReactionIconFactory(std::make_unique<ReactionIconFactory>())
, _giftPremiumValidator(this) { , _giftPremiumValidator(this) {
init(); init();

View File

@ -593,11 +593,6 @@ public:
return _chatStyle.get(); return _chatStyle.get();
} }
[[nodiscard]] auto cachedReactionIconFactory() const
-> HistoryView::Reactions::CachedIconFactory & {
return *_cachedReactionIconFactory;
}
[[nodiscard]] QString authedName() const { [[nodiscard]] QString authedName() const {
return _authedName; return _authedName;
} }
@ -713,9 +708,6 @@ private:
std::deque<std::shared_ptr<Ui::ChatTheme>> _lastUsedCustomChatThemes; std::deque<std::shared_ptr<Ui::ChatTheme>> _lastUsedCustomChatThemes;
rpl::variable<PeerThemeOverride> _peerThemeOverride; rpl::variable<PeerThemeOverride> _peerThemeOverride;
using ReactionIconFactory = HistoryView::Reactions::CachedIconFactory;
std::unique_ptr<ReactionIconFactory> _cachedReactionIconFactory;
base::has_weak_ptr _storyOpenGuard; base::has_weak_ptr _storyOpenGuard;
GiftPremiumValidator _giftPremiumValidator; GiftPremiumValidator _giftPremiumValidator;