Pass Main::Session to click handler creators.

This commit is contained in:
John Preston 2020-06-09 13:36:40 +04:00
parent fc174f742a
commit 03dec15e8e
21 changed files with 117 additions and 93 deletions

View file

@ -120,7 +120,7 @@ auto MentionClickHandler::getTextEntity() const -> TextEntity {
void MentionNameClickHandler::onClick(ClickContext context) const { void MentionNameClickHandler::onClick(ClickContext context) const {
const auto button = context.button; const auto button = context.button;
if (button == Qt::LeftButton || button == Qt::MiddleButton) { if (button == Qt::LeftButton || button == Qt::MiddleButton) {
if (auto user = Auth().data().userLoaded(_userId)) { if (auto user = _session->data().userLoaded(_userId)) {
Ui::showPeerProfile(user); Ui::showPeerProfile(user);
} }
} }
@ -132,7 +132,7 @@ auto MentionNameClickHandler::getTextEntity() const -> TextEntity {
} }
QString MentionNameClickHandler::tooltip() const { QString MentionNameClickHandler::tooltip() const {
if (const auto user = Auth().data().userLoaded(_userId)) { if (const auto user = _session->data().userLoaded(_userId)) {
const auto name = user->name; const auto name = user->name;
if (name != _text) { if (name != _text) {
return name; return name;

View file

@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/basic_click_handlers.h" #include "ui/basic_click_handlers.h"
namespace Main {
class Session;
} // namespace Main
class HiddenUrlClickHandler : public UrlClickHandler { class HiddenUrlClickHandler : public UrlClickHandler {
public: public:
HiddenUrlClickHandler(QString url) : UrlClickHandler(url, false) { HiddenUrlClickHandler(QString url) : UrlClickHandler(url, false) {
@ -72,8 +76,13 @@ private:
class MentionNameClickHandler : public ClickHandler { class MentionNameClickHandler : public ClickHandler {
public: public:
MentionNameClickHandler(QString text, UserId userId, uint64 accessHash) MentionNameClickHandler(
: _text(text) not_null<Main::Session*> session,
QString text,
UserId userId,
uint64 accessHash)
: _session(session)
, _text(text)
, _userId(userId) , _userId(userId)
, _accessHash(accessHash) { , _accessHash(accessHash) {
} }
@ -85,6 +94,7 @@ public:
QString tooltip() const override; QString tooltip() const override;
private: private:
const not_null<Main::Session*> _session;
QString _text; QString _text;
UserId _userId; UserId _userId;
uint64 _accessHash; uint64 _accessHash;

View file

@ -112,8 +112,11 @@ std::shared_ptr<ClickHandler> UiIntegration::createLinkHandler(
case EntityType::MentionName: { case EntityType::MentionName: {
auto fields = TextUtilities::MentionNameDataToFields(data.data); auto fields = TextUtilities::MentionNameDataToFields(data.data);
if (fields.userId) { if (!my || !my->session) {
LOG(("Mention name without a session: %1").arg(data.data));
} else if (fields.userId) {
return std::make_shared<MentionNameClickHandler>( return std::make_shared<MentionNameClickHandler>(
my->session,
data.text, data.text,
fields.userId, fields.userId,
fields.accessHash); fields.accessHash);

View file

@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/integration.h" #include "ui/integration.h"
namespace Main {
class Session;
} // namespace Main
namespace Core { namespace Core {
class UiIntegration : public Ui::Integration { class UiIntegration : public Ui::Integration {
@ -19,6 +23,7 @@ public:
Instagram, Instagram,
}; };
struct Context { struct Context {
Main::Session *session = nullptr;
HashtagMentionType type = HashtagMentionType::Telegram; HashtagMentionType type = HashtagMentionType::Telegram;
}; };

View file

@ -301,8 +301,7 @@ QString DocumentFileNameForSave(
DocumentClickHandler::DocumentClickHandler( DocumentClickHandler::DocumentClickHandler(
not_null<DocumentData*> document, not_null<DocumentData*> document,
FullMsgId context) FullMsgId context)
: FileClickHandler(context) : FileClickHandler(&document->session(), context)
, _session(&document->session())
, _document(document) { , _document(document) {
} }
@ -353,9 +352,7 @@ void DocumentOpenClickHandler::Open(
} }
void DocumentOpenClickHandler::onClickImpl() const { void DocumentOpenClickHandler::onClickImpl() const {
if (valid()) { Open(context(), document(), getActionItem());
Open(context(), document(), getActionItem());
}
} }
void DocumentSaveClickHandler::Save( void DocumentSaveClickHandler::Save(
@ -393,16 +390,10 @@ void DocumentSaveClickHandler::Save(
} }
void DocumentSaveClickHandler::onClickImpl() const { void DocumentSaveClickHandler::onClickImpl() const {
if (valid()) { Save(context(), document());
Save(context(), document());
}
} }
void DocumentCancelClickHandler::onClickImpl() const { void DocumentCancelClickHandler::onClickImpl() const {
if (!valid()) {
return;
}
const auto data = document(); const auto data = document();
if (!data->date) { if (!data->date) {
return; return;
@ -435,9 +426,7 @@ void DocumentOpenWithClickHandler::Open(
} }
void DocumentOpenWithClickHandler::onClickImpl() const { void DocumentOpenWithClickHandler::onClickImpl() const {
if (valid()) { Open(context(), document());
Open(context(), document());
}
} }
Data::FileOrigin StickerData::setOrigin() const { Data::FileOrigin StickerData::setOrigin() const {

View file

@ -335,16 +335,11 @@ public:
not_null<DocumentData*> document, not_null<DocumentData*> document,
FullMsgId context = FullMsgId()); FullMsgId context = FullMsgId());
[[nodiscard]] bool valid() const {
return !_session.empty();
}
[[nodiscard]] not_null<DocumentData*> document() const { [[nodiscard]] not_null<DocumentData*> document() const {
return _document; return _document;
} }
private: private:
const base::weak_ptr<Main::Session> _session;
const not_null<DocumentData*> _document; const not_null<DocumentData*> _document;
}; };

View file

@ -329,22 +329,16 @@ PhotoClickHandler::PhotoClickHandler(
not_null<PhotoData*> photo, not_null<PhotoData*> photo,
FullMsgId context, FullMsgId context,
PeerData *peer) PeerData *peer)
: FileClickHandler(context) : FileClickHandler(&photo->session(), context)
, _session(&photo->session())
, _photo(photo) , _photo(photo)
, _peer(peer) { , _peer(peer) {
} }
void PhotoOpenClickHandler::onClickImpl() const { void PhotoOpenClickHandler::onClickImpl() const {
if (valid()) { Core::App().showPhoto(this);
Core::App().showPhoto(this);
}
} }
void PhotoSaveClickHandler::onClickImpl() const { void PhotoSaveClickHandler::onClickImpl() const {
if (!valid()) {
return;
}
const auto data = photo(); const auto data = photo();
if (!data->date) { if (!data->date) {
return; return;
@ -354,9 +348,6 @@ void PhotoSaveClickHandler::onClickImpl() const {
} }
void PhotoCancelClickHandler::onClickImpl() const { void PhotoCancelClickHandler::onClickImpl() const {
if (!valid()) {
return;
}
const auto data = photo(); const auto data = photo();
if (!data->date) { if (!data->date) {
return; return;

View file

@ -145,10 +145,6 @@ public:
FullMsgId context = FullMsgId(), FullMsgId context = FullMsgId(),
PeerData *peer = nullptr); PeerData *peer = nullptr);
[[nodiscard]] bool valid() const {
return !_session.empty();
}
[[nodiscard]] not_null<PhotoData*> photo() const { [[nodiscard]] not_null<PhotoData*> photo() const {
return _photo; return _photo;
} }
@ -157,7 +153,6 @@ public:
} }
private: private:
const base::weak_ptr<Main::Session> _session;
const not_null<PhotoData*> _photo; const not_null<PhotoData*> _photo;
PeerData * const _peer = nullptr; PeerData * const _peer = nullptr;

View file

@ -136,7 +136,7 @@ void MessageCursor::applyTo(not_null<Ui::InputField*> field) {
} }
HistoryItem *FileClickHandler::getActionItem() const { HistoryItem *FileClickHandler::getActionItem() const {
return Auth().data().message(context()); return _session->data().message(context());
} }
PeerId PeerFromMessage(const MTPmessage &message) { PeerId PeerFromMessage(const MTPmessage &message) {

View file

@ -10,28 +10,32 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/value_ordering.h" #include "base/value_ordering.h"
#include "ui/text/text.h" // For QFIXED_MAX #include "ui/text/text.h" // For QFIXED_MAX
class HistoryItem;
using HistoryItemsList = std::vector<not_null<HistoryItem*>>;
class StorageImageLocation;
class WebFileLocation;
struct GeoPointLocation;
namespace Storage { namespace Storage {
namespace Cache { namespace Cache {
struct Key; struct Key;
} // namespace Cache } // namespace Cache
} // namespace Storage } // namespace Storage
class HistoryItem;
using HistoryItemsList = std::vector<not_null<HistoryItem*>>;
namespace Ui { namespace Ui {
class InputField; class InputField;
} // namespace Ui } // namespace Ui
namespace Main {
class Session;
} // namespace Main
namespace Images { namespace Images {
enum class Option; enum class Option;
using Options = base::flags<Option>; using Options = base::flags<Option>;
} // namespace Images } // namespace Images
class StorageImageLocation;
class WebFileLocation;
struct GeoPointLocation;
namespace Data { namespace Data {
struct UploadState { struct UploadState {
@ -449,7 +453,15 @@ struct SendAction {
class FileClickHandler : public LeftButtonClickHandler { class FileClickHandler : public LeftButtonClickHandler {
public: public:
FileClickHandler(FullMsgId context) : _context(context) { FileClickHandler(
not_null<Main::Session*> session,
FullMsgId context)
: _session(session)
, _context(context) {
}
[[nodiscard]] Main::Session &session() const {
return *_session;
} }
void setMessageId(FullMsgId context) { void setMessageId(FullMsgId context) {
@ -464,6 +476,7 @@ protected:
HistoryItem *getActionItem() const; HistoryItem *getActionItem() const;
private: private:
const not_null<Main::Session*> _session;
FullMsgId _context; FullMsgId _context;
}; };

View file

@ -1539,6 +1539,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
} }
_menu = base::make_unique_q<Ui::PopupMenu>(this); _menu = base::make_unique_q<Ui::PopupMenu>(this);
const auto session = &this->session();
const auto addItemActions = [&](HistoryItem *item) { const auto addItemActions = [&](HistoryItem *item) {
if (!item if (!item
@ -1578,7 +1579,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
}); });
if (photo->hasSticker) { if (photo->hasSticker) {
_menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] { _menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] {
session().api().requestAttachedStickerSets(photo); session->api().requestAttachedStickerSets(photo);
}); });
} }
}; };
@ -1599,7 +1600,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
return item return item
&& document->isGifv() && document->isGifv()
&& !Data::AutoDownload::ShouldAutoPlay( && !Data::AutoDownload::ShouldAutoPlay(
document->session().settings().autoDownload(), session->settings().autoDownload(),
item->history()->peer, item->history()->peer,
document); document);
}(); }();
@ -1642,7 +1643,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
} }
if (item && item->hasDirectLink() && isUponSelected != 2 && isUponSelected != -2) { if (item && item->hasDirectLink() && isUponSelected != 2 && isUponSelected != -2) {
_menu->addAction(item->history()->peer->isMegagroup() ? tr::lng_context_copy_link(tr::now) : tr::lng_context_copy_post_link(tr::now), [=] { _menu->addAction(item->history()->peer->isMegagroup() ? tr::lng_context_copy_link(tr::now) : tr::lng_context_copy_post_link(tr::now), [=] {
HistoryView::CopyPostLink(itemId); HistoryView::CopyPostLink(session, itemId);
}); });
} }
if (isUponSelected > 1) { if (isUponSelected > 1) {
@ -1680,7 +1681,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
} }
if (IsServerMsgId(item->id) && !item->serviceMsg()) { if (IsServerMsgId(item->id) && !item->serviceMsg()) {
_menu->addAction(tr::lng_context_select_msg(tr::now), [=] { _menu->addAction(tr::lng_context_select_msg(tr::now), [=] {
if (const auto item = session().data().message(itemId)) { if (const auto item = session->data().message(itemId)) {
if (const auto view = item->mainView()) { if (const auto view = item->mainView()) {
changeSelection(&_selected, item, SelectAction::Select); changeSelection(&_selected, item, SelectAction::Select);
repaintItem(item); repaintItem(item);
@ -1697,7 +1698,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
: App::hoveredLinkItem() : App::hoveredLinkItem()
? App::hoveredLinkItem()->data().get() ? App::hoveredLinkItem()->data().get()
: nullptr) { : nullptr) {
if (const auto group = session().data().groups().find(result)) { if (const auto group = session->data().groups().find(result)) {
return group->items.front(); return group->items.front();
} }
return result; return result;
@ -1731,11 +1732,11 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
_menu->addAction(document->isStickerSetInstalled() ? tr::lng_context_pack_info(tr::now) : tr::lng_context_pack_add(tr::now), [=] { _menu->addAction(document->isStickerSetInstalled() ? tr::lng_context_pack_info(tr::now) : tr::lng_context_pack_add(tr::now), [=] {
showStickerPackInfo(document); showStickerPackInfo(document);
}); });
_menu->addAction(session().data().stickers().isFaved(document) ? tr::lng_faved_stickers_remove(tr::now) : tr::lng_faved_stickers_add(tr::now), [=] { _menu->addAction(session->data().stickers().isFaved(document) ? tr::lng_faved_stickers_remove(tr::now) : tr::lng_faved_stickers_add(tr::now), [=] {
session().api().toggleFavedSticker( session->api().toggleFavedSticker(
document, document,
itemId, itemId,
!session().data().stickers().isFaved(document)); !session->data().stickers().isFaved(document));
}); });
} }
_menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] { _menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] {
@ -1748,12 +1749,12 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
if (!poll->closed()) { if (!poll->closed()) {
if (poll->voted() && !poll->quiz()) { if (poll->voted() && !poll->quiz()) {
_menu->addAction(tr::lng_polls_retract(tr::now), [=] { _menu->addAction(tr::lng_polls_retract(tr::now), [=] {
session().api().sendPollVotes(itemId, {}); session->api().sendPollVotes(itemId, {});
}); });
} }
if (item->canStopPoll()) { if (item->canStopPoll()) {
_menu->addAction(tr::lng_polls_stop(tr::now), [=] { _menu->addAction(tr::lng_polls_stop(tr::now), [=] {
HistoryView::StopPoll(itemId); HistoryView::StopPoll(session, itemId);
}); });
} }
} }
@ -1783,7 +1784,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
}); });
} else if (item && item->hasDirectLink() && isUponSelected != 2 && isUponSelected != -2) { } else if (item && item->hasDirectLink() && isUponSelected != 2 && isUponSelected != -2) {
_menu->addAction(item->history()->peer->isMegagroup() ? tr::lng_context_copy_link(tr::now) : tr::lng_context_copy_post_link(tr::now), [=] { _menu->addAction(item->history()->peer->isMegagroup() ? tr::lng_context_copy_link(tr::now) : tr::lng_context_copy_post_link(tr::now), [=] {
HistoryView::CopyPostLink(itemId); HistoryView::CopyPostLink(session, itemId);
}); });
} }
if (isUponSelected > 1) { if (isUponSelected > 1) {
@ -1820,7 +1821,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
} }
if (item->id > 0 && !item->serviceMsg()) { if (item->id > 0 && !item->serviceMsg()) {
_menu->addAction(tr::lng_context_select_msg(tr::now), [=] { _menu->addAction(tr::lng_context_select_msg(tr::now), [=] {
if (const auto item = session().data().message(itemId)) { if (const auto item = session->data().message(itemId)) {
if (const auto view = item->mainView()) { if (const auto view = item->mainView()) {
changeSelectionAsGroup(&_selected, item, SelectAction::Select); changeSelectionAsGroup(&_selected, item, SelectAction::Select);
repaintItem(view); repaintItem(view);
@ -1835,7 +1836,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
&& !App::mousedItem()->data()->serviceMsg()) { && !App::mousedItem()->data()->serviceMsg()) {
const auto itemId = App::mousedItem()->data()->fullId(); const auto itemId = App::mousedItem()->data()->fullId();
_menu->addAction(tr::lng_context_select_msg(tr::now), [=] { _menu->addAction(tr::lng_context_select_msg(tr::now), [=] {
if (const auto item = session().data().message(itemId)) { if (const auto item = session->data().message(itemId)) {
if (const auto view = item->mainView()) { if (const auto view = item->mainView()) {
changeSelectionAsGroup(&_selected, item, SelectAction::Select); changeSelectionAsGroup(&_selected, item, SelectAction::Select);
repaintItem(item); repaintItem(item);

View file

@ -389,10 +389,12 @@ void HistoryMessageReply::refreshReplyToDocument() {
} }
ReplyMarkupClickHandler::ReplyMarkupClickHandler( ReplyMarkupClickHandler::ReplyMarkupClickHandler(
not_null<Data::Session*> owner,
int row, int row,
int column, int column,
FullMsgId context) FullMsgId context)
: _itemId(context) : _owner(owner)
, _itemId(context)
, _row(row) , _row(row)
, _column(column) { , _column(column) {
} }
@ -423,15 +425,11 @@ QString ReplyMarkupClickHandler::copyToClipboardContextItemText() const {
// Note: it is possible that we will point to the different button // Note: it is possible that we will point to the different button
// than the one was used when constructing the handler, but not a big deal. // than the one was used when constructing the handler, but not a big deal.
const HistoryMessageMarkupButton *ReplyMarkupClickHandler::getButton() const { const HistoryMessageMarkupButton *ReplyMarkupClickHandler::getButton() const {
return HistoryMessageMarkupButton::Get( return HistoryMessageMarkupButton::Get(_owner, _itemId, _row, _column);
&Auth().data(),
_itemId,
_row,
_column);
} }
void ReplyMarkupClickHandler::onClickImpl() const { void ReplyMarkupClickHandler::onClickImpl() const {
if (const auto item = Auth().data().message(_itemId)) { if (const auto item = _owner->message(_itemId)) {
App::activateBotCommand(item, _row, _column); App::activateBotCommand(item, _row, _column);
} }
} }
@ -459,6 +457,7 @@ ReplyKeyboard::ReplyKeyboard(
}) })
, _st(std::move(s)) { , _st(std::move(s)) {
if (const auto markup = _item->Get<HistoryMessageReplyMarkup>()) { if (const auto markup = _item->Get<HistoryMessageReplyMarkup>()) {
const auto owner = &_item->history()->owner();
const auto context = _item->fullId(); const auto context = _item->fullId();
const auto rowCount = int(markup->rows.size()); const auto rowCount = int(markup->rows.size());
_rows.reserve(rowCount); _rows.reserve(rowCount);
@ -472,6 +471,7 @@ ReplyKeyboard::ReplyKeyboard(
const auto text = row[j].text; const auto text = row[j].text;
button.type = row.at(j).type; button.type = row.at(j).type;
button.link = std::make_shared<ReplyMarkupClickHandler>( button.link = std::make_shared<ReplyMarkupClickHandler>(
owner,
i, i,
j, j,
context); context);

View file

@ -223,7 +223,11 @@ private:
class ReplyMarkupClickHandler : public LeftButtonClickHandler { class ReplyMarkupClickHandler : public LeftButtonClickHandler {
public: public:
ReplyMarkupClickHandler(int row, int column, FullMsgId context); ReplyMarkupClickHandler(
not_null<Data::Session*> owner,
int row,
int column,
FullMsgId context);
QString tooltip() const override { QString tooltip() const override {
return _fullDisplayed ? QString() : buttonText(); return _fullDisplayed ? QString() : buttonText();
@ -253,6 +257,7 @@ protected:
void onClickImpl() const override; void onClickImpl() const override;
private: private:
const not_null<Data::Session*> _owner;
FullMsgId _itemId; FullMsgId _itemId;
int _row = 0; int _row = 0;
int _column = 0; int _column = 0;

View file

@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text/text_isolated_emoji.h" #include "ui/text/text_isolated_emoji.h"
#include "ui/text_options.h" #include "ui/text_options.h"
#include "core/application.h" #include "core/application.h"
#include "core/ui_integration.h"
#include "layout.h" #include "layout.h"
#include "window/notifications_manager.h" #include "window/notifications_manager.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
@ -219,7 +220,9 @@ void FastShareMessage(not_null<HistoryItem*> item) {
auto copyCallback = [=]() { auto copyCallback = [=]() {
if (const auto item = owner->message(data->msgIds[0])) { if (const auto item = owner->message(data->msgIds[0])) {
if (item->hasDirectLink()) { if (item->hasDirectLink()) {
HistoryView::CopyPostLink(item->fullId()); HistoryView::CopyPostLink(
&item->history()->session(),
item->fullId());
} else if (const auto bot = item->getMessageBot()) { } else if (const auto bot = item->getMessageBot()) {
if (const auto media = item->media()) { if (const auto media = item->media()) {
if (const auto game = media->game()) { if (const auto game = media->game()) {
@ -1206,7 +1209,7 @@ TextWithEntities HistoryMessage::withLocalEntities(
} }
void HistoryMessage::setText(const TextWithEntities &textWithEntities) { void HistoryMessage::setText(const TextWithEntities &textWithEntities) {
for_const (auto &entity, textWithEntities.entities) { for (const auto &entity : textWithEntities.entities) {
auto type = entity.type(); auto type = entity.type();
if (type == EntityType::Url if (type == EntityType::Url
|| type == EntityType::CustomUrl || type == EntityType::CustomUrl
@ -1220,11 +1223,16 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) {
setEmptyText(); setEmptyText();
return; return;
} }
clearIsolatedEmoji(); clearIsolatedEmoji();
const auto context = Core::UiIntegration::Context{
.session = &history()->session()
};
_text.setMarkedText( _text.setMarkedText(
st::messageTextStyle, st::messageTextStyle,
withLocalEntities(textWithEntities), withLocalEntities(textWithEntities),
Ui::ItemTextOptions(this)); Ui::ItemTextOptions(this),
context);
if (!textWithEntities.text.isEmpty() && _text.isEmpty()) { if (!textWithEntities.text.isEmpty() && _text.isEmpty()) {
// If server has allowed some text that we've trim-ed entirely, // If server has allowed some text that we've trim-ed entirely,
// just replace it with something so that UI won't look buggy. // just replace it with something so that UI won't look buggy.
@ -1235,6 +1243,7 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) {
} else if (!_media) { } else if (!_media) {
checkIsolatedEmoji(); checkIsolatedEmoji();
} }
_textWidth = -1; _textWidth = -1;
_textHeight = 0; _textHeight = 0;
} }

View file

@ -407,7 +407,7 @@ HistoryService::PreparedText HistoryService::prepareGameScoreText() {
auto result = PreparedText {}; auto result = PreparedText {};
auto gamescore = Get<HistoryServiceGameScore>(); auto gamescore = Get<HistoryServiceGameScore>();
auto computeGameTitle = [gamescore, &result]() -> QString { auto computeGameTitle = [&]() -> QString {
if (gamescore && gamescore->msg) { if (gamescore && gamescore->msg) {
if (const auto media = gamescore->msg->media()) { if (const auto media = gamescore->msg->media()) {
if (const auto game = media->game()) { if (const auto game = media->game()) {
@ -415,6 +415,7 @@ HistoryService::PreparedText HistoryService::prepareGameScoreText() {
const auto column = 0; const auto column = 0;
result.links.push_back( result.links.push_back(
std::make_shared<ReplyMarkupClickHandler>( std::make_shared<ReplyMarkupClickHandler>(
&history()->owner(),
row, row,
column, column,
gamescore->msg->fullId())); gamescore->msg->fullId()));

View file

@ -128,8 +128,8 @@ void AddPhotoActions(
}); });
} }
void OpenGif(FullMsgId itemId) { void OpenGif(not_null<Main::Session*> session, FullMsgId itemId) {
if (const auto item = Auth().data().message(itemId)) { if (const auto item = session->data().message(itemId)) {
if (const auto media = item->media()) { if (const auto media = item->media()) {
if (const auto document = media->document()) { if (const auto document = media->document()) {
Core::App().showDocument(document, item); Core::App().showDocument(document, item);
@ -182,7 +182,8 @@ void AddDocumentActions(
}); });
return; return;
} }
if (const auto item = document->session().data().message(contextId)) { const auto session = &document->session();
if (const auto item = session->data().message(contextId)) {
const auto notAutoplayedGif = [&] { const auto notAutoplayedGif = [&] {
return document->isGifv() return document->isGifv()
&& !Data::AutoDownload::ShouldAutoPlay( && !Data::AutoDownload::ShouldAutoPlay(
@ -192,7 +193,7 @@ void AddDocumentActions(
}(); }();
if (notAutoplayedGif) { if (notAutoplayedGif) {
menu->addAction(tr::lng_context_open_gif(tr::now), [=] { menu->addAction(tr::lng_context_open_gif(tr::now), [=] {
OpenGif(contextId); OpenGif(session, contextId);
}); });
} }
} }
@ -231,12 +232,13 @@ void AddPostLinkAction(
&& !request.link->copyToClipboardContextItemText().isEmpty()) { && !request.link->copyToClipboardContextItemText().isEmpty()) {
return; return;
} }
const auto session = &item->history()->session();
const auto itemId = item->fullId(); const auto itemId = item->fullId();
menu->addAction( menu->addAction(
(item->history()->peer->isMegagroup() (item->history()->peer->isMegagroup()
? tr::lng_context_copy_link ? tr::lng_context_copy_link
: tr::lng_context_copy_post_link)(tr::now), : tr::lng_context_copy_post_link)(tr::now),
[=] { CopyPostLink(itemId); }); [=] { CopyPostLink(session, itemId); });
} }
MessageIdsList ExtractIdsList(const SelectedItems &items) { MessageIdsList ExtractIdsList(const SelectedItems &items) {
@ -698,8 +700,8 @@ base::unique_qptr<Ui::PopupMenu> FillContextMenu(
return result; return result;
} }
void CopyPostLink(FullMsgId itemId) { void CopyPostLink(not_null<Main::Session*> session, FullMsgId itemId) {
const auto item = Auth().data().message(itemId); const auto item = session->data().message(itemId);
if (!item || !item->hasDirectLink()) { if (!item || !item->hasDirectLink()) {
return; return;
} }
@ -714,11 +716,11 @@ void CopyPostLink(FullMsgId itemId) {
: tr::lng_context_about_private_link(tr::now)); : tr::lng_context_about_private_link(tr::now));
} }
void StopPoll(FullMsgId itemId) { void StopPoll(not_null<Main::Session*> session, FullMsgId itemId) {
const auto stop = [=] { const auto stop = [=] {
Ui::hideLayer(); Ui::hideLayer();
if (const auto item = Auth().data().message(itemId)) { if (const auto item = session->data().message(itemId)) {
item->history()->session().api().closePoll(item); session->api().closePoll(item);
} }
}; };
Ui::show(Box<ConfirmBox>( Ui::show(Box<ConfirmBox>(

View file

@ -43,7 +43,7 @@ base::unique_qptr<Ui::PopupMenu> FillContextMenu(
not_null<ListWidget*> list, not_null<ListWidget*> list,
const ContextMenuRequest &request); const ContextMenuRequest &request);
void CopyPostLink(FullMsgId itemId); void CopyPostLink(not_null<Main::Session*> session, FullMsgId itemId);
void StopPoll(FullMsgId itemId); void StopPoll(not_null<Main::Session*> session, FullMsgId itemId);
} // namespace } // namespace

View file

@ -48,6 +48,7 @@ QSize Game::countOptimalSize() {
const auto row = 0; const auto row = 0;
const auto column = 0; const auto column = 0;
_openl = std::make_shared<ReplyMarkupClickHandler>( _openl = std::make_shared<ReplyMarkupClickHandler>(
&item->history()->owner(),
row, row,
column, column,
item->fullId()); item->fullId());

View file

@ -126,14 +126,17 @@ void Gif::setPosition(int32 position) {
} }
void DeleteSavedGifClickHandler::onClickImpl() const { void DeleteSavedGifClickHandler::onClickImpl() const {
Auth().api().toggleSavedGif(_data, Data::FileOriginSavedGifs(), false); _data->session().api().toggleSavedGif(
_data,
Data::FileOriginSavedGifs(),
false);
const auto index = Auth().data().stickers().savedGifs().indexOf(_data); const auto index = _data->owner().stickers().savedGifs().indexOf(_data);
if (index >= 0) { if (index >= 0) {
Auth().data().stickers().savedGifsRef().remove(index); _data->owner().stickers().savedGifsRef().remove(index);
Local::writeSavedGifs(); Local::writeSavedGifs();
} }
Auth().data().stickers().notifySavedGifsUpdated(); _data->owner().stickers().notifySavedGifsUpdated();
} }
int Gif::resizeGetHeight(int width) { int Gif::resizeGetHeight(int width) {

View file

@ -45,14 +45,14 @@ protected:
class DeleteSavedGifClickHandler : public LeftButtonClickHandler { class DeleteSavedGifClickHandler : public LeftButtonClickHandler {
public: public:
DeleteSavedGifClickHandler(DocumentData *data) : _data(data) { DeleteSavedGifClickHandler(not_null<DocumentData*> data) : _data(data) {
} }
protected: protected:
void onClickImpl() const override; void onClickImpl() const override;
private: private:
DocumentData *_data; const not_null<DocumentData*> _data;
}; };

View file

@ -91,6 +91,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <unordered_set> #include <unordered_set>
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <any>
#include <optional> #include <optional>
#include <range/v3/all.hpp> #include <range/v3/all.hpp>