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_session.h"
#include "main/main_session.h"
#include "mainwidget.h" // App::main
FileClickHandler::FileClickHandler(
not_null<Main::Session*> session,
@ -111,18 +110,20 @@ void DocumentSaveClickHandler::onClickImpl() const {
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 {
const auto data = document();
if (!data->date) {
return;
} else if (data->uploading()) {
if (const auto item = data->owner().message(context())) {
if (const auto m = App::main()) { // multi good
if (&m->session() == &data->session()) {
m->cancelUploadLayer(item);
}
}
}
} else if (data->uploading() && _handler) {
_handler(context());
} else {
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 {
const auto data = photo();
if (!data->date) {
return;
} else if (data->uploading()) {
if (const auto item = data->owner().message(context())) {
if (const auto m = App::main()) { // multi good
if (&m->session() == &data->session()) {
m->cancelUploadLayer(item);
}
}
}
} else if (data->uploading() && _handler) {
_handler(context());
} else {
data->cancel();
}

View file

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

View file

@ -616,6 +616,12 @@ void InnerWidget::elementOpenDocument(
_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(
const TextWithEntities &text,
Fn<void()> hiddenCallback) {

View file

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

View file

@ -2581,6 +2581,12 @@ void HistoryInner::elementOpenDocument(
_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(
const TextWithEntities &text,
Fn<void()> hiddenCallback) {
@ -3477,6 +3483,11 @@ not_null<HistoryView::ElementDelegate*> HistoryInner::ElementDelegate() {
showInMediaView);
}
}
void elementCancelUpload(const FullMsgId &context) override {
if (Instance) {
Instance->elementCancelUpload(context);
}
}
void elementShowTooltip(
const TextWithEntities &text,
Fn<void()> hiddenCallback) override {

View file

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

View file

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

View file

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

View file

@ -1314,6 +1314,12 @@ void ListWidget::elementOpenDocument(
_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(
const TextWithEntities &text,
Fn<void()> hiddenCallback) {

View file

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

View file

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

View file

@ -120,7 +120,12 @@ void File::setDocumentLinks(
}),
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;

View file

@ -92,7 +92,12 @@ void Photo::create(FullMsgId contextId, PeerData *chat) {
crl::guard(this, [=](FullMsgId id) { showPhoto(id); }),
contextId),
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())) {
dataMediaCreated();
} else if (_data->inlineThumbnailBytes().isEmpty()

View file

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

View file

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