Removed App::main() from file click handlers.

This commit is contained in:
23rd 2021-06-18 09:20:49 +03:00
parent 460baa54d8
commit 23c54896e5
15 changed files with 86 additions and 24 deletions

View file

@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_photo.h" #include "data/data_photo.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "mainwidget.h" // App::main
FileClickHandler::FileClickHandler( FileClickHandler::FileClickHandler(
not_null<Main::Session*> session, not_null<Main::Session*> session,
@ -111,18 +110,20 @@ void DocumentSaveClickHandler::onClickImpl() const {
Save(context(), document()); Save(context(), document());
} }
DocumentCancelClickHandler::DocumentCancelClickHandler(
not_null<DocumentData*> document,
Fn<void(FullMsgId)> &&callback,
FullMsgId context)
: DocumentClickHandler(document, context)
, _handler(std::move(callback)) {
}
void DocumentCancelClickHandler::onClickImpl() const { void DocumentCancelClickHandler::onClickImpl() const {
const auto data = document(); const auto data = document();
if (!data->date) { if (!data->date) {
return; return;
} else if (data->uploading()) { } else if (data->uploading() && _handler) {
if (const auto item = data->owner().message(context())) { _handler(context());
if (const auto m = App::main()) { // multi good
if (&m->session() == &data->session()) {
m->cancelUploadLayer(item);
}
}
}
} else { } else {
data->cancel(); data->cancel();
} }
@ -191,18 +192,20 @@ void PhotoSaveClickHandler::onClickImpl() const {
} }
} }
PhotoCancelClickHandler::PhotoCancelClickHandler(
not_null<PhotoData*> photo,
Fn<void(FullMsgId)> &&callback,
FullMsgId context)
: PhotoClickHandler(photo, context)
, _handler(std::move(callback)) {
}
void PhotoCancelClickHandler::onClickImpl() const { void PhotoCancelClickHandler::onClickImpl() const {
const auto data = photo(); const auto data = photo();
if (!data->date) { if (!data->date) {
return; return;
} else if (data->uploading()) { } else if (data->uploading() && _handler) {
if (const auto item = data->owner().message(context())) { _handler(context());
if (const auto m = App::main()) { // multi good
if (&m->session() == &data->session()) {
m->cancelUploadLayer(item);
}
}
}
} else { } else {
data->cancel(); data->cancel();
} }

View file

@ -87,11 +87,17 @@ private:
class DocumentCancelClickHandler : public DocumentClickHandler { class DocumentCancelClickHandler : public DocumentClickHandler {
public: public:
using DocumentClickHandler::DocumentClickHandler; DocumentCancelClickHandler(
not_null<DocumentData*> document,
Fn<void(FullMsgId)> &&callback,
FullMsgId context = FullMsgId());
protected: protected:
void onClickImpl() const override; void onClickImpl() const override;
private:
const Fn<void(FullMsgId)> _handler;
}; };
class DocumentOpenWithClickHandler : public DocumentClickHandler { class DocumentOpenWithClickHandler : public DocumentClickHandler {
@ -173,9 +179,15 @@ protected:
class PhotoCancelClickHandler : public PhotoClickHandler { class PhotoCancelClickHandler : public PhotoClickHandler {
public: public:
using PhotoClickHandler::PhotoClickHandler; PhotoCancelClickHandler(
not_null<PhotoData*> photo,
Fn<void(FullMsgId)> &&callback,
FullMsgId context = FullMsgId());
protected: protected:
void onClickImpl() const override; void onClickImpl() const override;
private:
const Fn<void(FullMsgId)> _handler;
}; };

View file

@ -616,6 +616,12 @@ void InnerWidget::elementOpenDocument(
_controller->openDocument(document, context, showInMediaView); _controller->openDocument(document, context, showInMediaView);
} }
void InnerWidget::elementCancelUpload(const FullMsgId &context) {
if (const auto item = session().data().message(context)) {
_controller->content()->cancelUploadLayer(item);
}
}
void InnerWidget::elementShowTooltip( void InnerWidget::elementShowTooltip(
const TextWithEntities &text, const TextWithEntities &text,
Fn<void()> hiddenCallback) { Fn<void()> hiddenCallback) {

View file

@ -115,6 +115,7 @@ public:
not_null<DocumentData*> document, not_null<DocumentData*> document,
FullMsgId context, FullMsgId context,
bool showInMediaView = false) override; bool showInMediaView = false) override;
void elementCancelUpload(const FullMsgId &context) override;
void elementShowTooltip( void elementShowTooltip(
const TextWithEntities &text, const TextWithEntities &text,
Fn<void()> hiddenCallback) override; Fn<void()> hiddenCallback) override;

View file

@ -2581,6 +2581,12 @@ void HistoryInner::elementOpenDocument(
_controller->openDocument(document, context, showInMediaView); _controller->openDocument(document, context, showInMediaView);
} }
void HistoryInner::elementCancelUpload(const FullMsgId &context) {
if (const auto item = session().data().message(context)) {
_controller->content()->cancelUploadLayer(item);
}
}
void HistoryInner::elementShowTooltip( void HistoryInner::elementShowTooltip(
const TextWithEntities &text, const TextWithEntities &text,
Fn<void()> hiddenCallback) { Fn<void()> hiddenCallback) {
@ -3477,6 +3483,11 @@ not_null<HistoryView::ElementDelegate*> HistoryInner::ElementDelegate() {
showInMediaView); showInMediaView);
} }
} }
void elementCancelUpload(const FullMsgId &context) override {
if (Instance) {
Instance->elementCancelUpload(context);
}
}
void elementShowTooltip( void elementShowTooltip(
const TextWithEntities &text, const TextWithEntities &text,
Fn<void()> hiddenCallback) override { Fn<void()> hiddenCallback) override {

View file

@ -95,6 +95,7 @@ public:
not_null<DocumentData*> document, not_null<DocumentData*> document,
FullMsgId context, FullMsgId context,
bool showInMediaView = false); bool showInMediaView = false);
void elementCancelUpload(const FullMsgId &context);
void elementShowTooltip( void elementShowTooltip(
const TextWithEntities &text, const TextWithEntities &text,
Fn<void()> hiddenCallback); Fn<void()> hiddenCallback);

View file

@ -118,6 +118,9 @@ void SimpleElementDelegate::elementOpenDocument(
bool showInMediaView) { bool showInMediaView) {
} }
void SimpleElementDelegate::elementCancelUpload(const FullMsgId &context) {
}
void SimpleElementDelegate::elementShowTooltip( void SimpleElementDelegate::elementShowTooltip(
const TextWithEntities &text, const TextWithEntities &text,
Fn<void()> hiddenCallback) { Fn<void()> hiddenCallback) {

View file

@ -67,6 +67,7 @@ public:
not_null<DocumentData*> document, not_null<DocumentData*> document,
FullMsgId context, FullMsgId context,
bool showInMediaView = false) = 0; bool showInMediaView = false) = 0;
virtual void elementCancelUpload(const FullMsgId &context) = 0;
virtual void elementShowTooltip( virtual void elementShowTooltip(
const TextWithEntities &text, const TextWithEntities &text,
Fn<void()> hiddenCallback) = 0; Fn<void()> hiddenCallback) = 0;
@ -111,6 +112,7 @@ public:
not_null<DocumentData*> document, not_null<DocumentData*> document,
FullMsgId context, FullMsgId context,
bool showInMediaView = false) override; bool showInMediaView = false) override;
void elementCancelUpload(const FullMsgId &context) override;
void elementShowTooltip( void elementShowTooltip(
const TextWithEntities &text, const TextWithEntities &text,
Fn<void()> hiddenCallback) override; Fn<void()> hiddenCallback) override;

View file

@ -1314,6 +1314,12 @@ void ListWidget::elementOpenDocument(
_controller->openDocument(document, context, showInMediaView); _controller->openDocument(document, context, showInMediaView);
} }
void ListWidget::elementCancelUpload(const FullMsgId &context) {
if (const auto item = session().data().message(context)) {
_controller->content()->cancelUploadLayer(item);
}
}
void ListWidget::elementShowTooltip( void ListWidget::elementShowTooltip(
const TextWithEntities &text, const TextWithEntities &text,
Fn<void()> hiddenCallback) { Fn<void()> hiddenCallback) {

View file

@ -241,6 +241,7 @@ public:
not_null<DocumentData*> document, not_null<DocumentData*> document,
FullMsgId context, FullMsgId context,
bool showInMediaView = false) override; bool showInMediaView = false) override;
void elementCancelUpload(const FullMsgId &context) override;
void elementShowTooltip( void elementShowTooltip(
const TextWithEntities &text, const TextWithEntities &text,
Fn<void()> hiddenCallback) override; Fn<void()> hiddenCallback) override;

View file

@ -218,6 +218,9 @@ void Document::createComponents(bool caption) {
_realParent->fullId()); _realParent->fullId());
thumbed->_linkcancell = std::make_shared<DocumentCancelClickHandler>( thumbed->_linkcancell = std::make_shared<DocumentCancelClickHandler>(
_data, _data,
crl::guard(this, [=](FullMsgId id) {
_parent->delegate()->elementCancelUpload(id);
}),
_realParent->fullId()); _realParent->fullId());
} }
if (const auto voice = Get<HistoryDocumentVoice>()) { if (const auto voice = Get<HistoryDocumentVoice>()) {

View file

@ -120,7 +120,12 @@ void File::setDocumentLinks(
}), }),
context), context),
std::make_shared<DocumentSaveClickHandler>(document, context), std::make_shared<DocumentSaveClickHandler>(document, context),
std::make_shared<DocumentCancelClickHandler>(document, context)); std::make_shared<DocumentCancelClickHandler>(
document,
crl::guard(this, [=](FullMsgId id) {
_parent->delegate()->elementCancelUpload(id);
}),
context));
} }
File::~File() = default; File::~File() = default;

View file

@ -92,7 +92,12 @@ void Photo::create(FullMsgId contextId, PeerData *chat) {
crl::guard(this, [=](FullMsgId id) { showPhoto(id); }), crl::guard(this, [=](FullMsgId id) { showPhoto(id); }),
contextId), contextId),
std::make_shared<PhotoSaveClickHandler>(_data, contextId, chat), std::make_shared<PhotoSaveClickHandler>(_data, contextId, chat),
std::make_shared<PhotoCancelClickHandler>(_data, contextId, chat)); std::make_shared<PhotoCancelClickHandler>(
_data,
crl::guard(this, [=](FullMsgId id) {
_parent->delegate()->elementCancelUpload(id);
}),
contextId));
if ((_dataMedia = _data->activeMediaView())) { if ((_dataMedia = _data->activeMediaView())) {
dataMediaCreated(); dataMediaCreated();
} else if (_data->inlineThumbnailBytes().isEmpty() } else if (_data->inlineThumbnailBytes().isEmpty()

View file

@ -343,9 +343,9 @@ Media::View::OpenRequest Result::openRequest() {
void Result::cancelFile() { void Result::cancelFile() {
if (_document) { if (_document) {
DocumentCancelClickHandler(_document).onClick({}); DocumentCancelClickHandler(_document, nullptr).onClick({});
} else if (_photo) { } else if (_photo) {
PhotoCancelClickHandler(_photo).onClick({}); PhotoCancelClickHandler(_photo, nullptr).onClick({});
} }
} }

View file

@ -193,7 +193,10 @@ void RadialProgressItem::setDocumentLinks(
}), }),
context), context),
std::make_shared<DocumentSaveClickHandler>(document, context), std::make_shared<DocumentSaveClickHandler>(document, context),
std::make_shared<DocumentCancelClickHandler>(document, context)); std::make_shared<DocumentCancelClickHandler>(
document,
nullptr,
context));
} }
void RadialProgressItem::clickHandlerActiveChanged( void RadialProgressItem::clickHandlerActiveChanged(