2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

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

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

View File

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

View File

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

View File

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

View File

@@ -136,7 +136,7 @@ void MessageCursor::applyTo(not_null<Ui::InputField*> field) {
}
HistoryItem *FileClickHandler::getActionItem() const {
return Auth().data().message(context());
return _session->data().message(context());
}
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 "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 Cache {
struct Key;
} // namespace Cache
} // namespace Storage
class HistoryItem;
using HistoryItemsList = std::vector<not_null<HistoryItem*>>;
namespace Ui {
class InputField;
} // namespace Ui
namespace Main {
class Session;
} // namespace Main
namespace Images {
enum class Option;
using Options = base::flags<Option>;
} // namespace Images
class StorageImageLocation;
class WebFileLocation;
struct GeoPointLocation;
namespace Data {
struct UploadState {
@@ -449,7 +453,15 @@ struct SendAction {
class FileClickHandler : public LeftButtonClickHandler {
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) {
@@ -464,6 +476,7 @@ protected:
HistoryItem *getActionItem() const;
private:
const not_null<Main::Session*> _session;
FullMsgId _context;
};