mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-24 01:06:59 +00:00
Close StickerSetBox on error.
This commit is contained in:
parent
b6e77537e2
commit
e0159e15b2
@ -63,12 +63,14 @@ public:
|
||||
bool loaded() const;
|
||||
bool notInstalled() const;
|
||||
bool official() const;
|
||||
rpl::producer<TextWithEntities> title() const;
|
||||
QString shortName() const;
|
||||
[[nodiscard]] rpl::producer<TextWithEntities> title() const;
|
||||
[[nodiscard]] QString shortName() const;
|
||||
|
||||
void install();
|
||||
rpl::producer<uint64> setInstalled() const;
|
||||
rpl::producer<> updateControls() const;
|
||||
[[nodiscard]] rpl::producer<uint64> setInstalled() const;
|
||||
[[nodiscard]] rpl::producer<> updateControls() const;
|
||||
|
||||
[[nodiscard]] rpl::producer<Error> errors() const;
|
||||
|
||||
~Inner();
|
||||
|
||||
@ -137,6 +139,7 @@ private:
|
||||
|
||||
rpl::event_stream<uint64> _setInstalled;
|
||||
rpl::event_stream<> _updateControls;
|
||||
rpl::event_stream<Error> _errors;
|
||||
|
||||
};
|
||||
|
||||
@ -186,6 +189,11 @@ void StickerSetBox::prepare() {
|
||||
_controller->session().api().stickerSetInstalled(setId);
|
||||
closeBox();
|
||||
}, lifetime());
|
||||
|
||||
_inner->errors(
|
||||
) | rpl::start_with_next([=](Error error) {
|
||||
handleError(error);
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void StickerSetBox::addStickers() {
|
||||
@ -198,6 +206,20 @@ void StickerSetBox::copyStickersLink() {
|
||||
QGuiApplication::clipboard()->setText(url);
|
||||
}
|
||||
|
||||
void StickerSetBox::handleError(Error error) {
|
||||
const auto guard = gsl::finally(crl::guard(this, [=] {
|
||||
closeBox();
|
||||
}));
|
||||
|
||||
switch (error) {
|
||||
case Error::NotFound:
|
||||
_controller->show(
|
||||
Box<InformBox>(tr::lng_stickers_not_found(tr::now)));
|
||||
break;
|
||||
default: Unexpected("Error in StickerSetBox::handleError.");
|
||||
}
|
||||
}
|
||||
|
||||
void StickerSetBox::archiveStickers() {
|
||||
const auto weak = base::make_weak(_controller.get());
|
||||
const auto setId = _set.c_inputStickerSetID().vid().v;
|
||||
@ -211,7 +233,7 @@ void StickerSetBox::archiveStickers() {
|
||||
}
|
||||
if (result.type() == mtpc_messages_stickerSetInstallResultSuccess) {
|
||||
Ui::Toast::Show(tr::lng_stickers_has_been_archived(tr::now));
|
||||
|
||||
|
||||
const auto &session = controller->session();
|
||||
auto &order = session.data().stickers().setsOrderRef();
|
||||
const auto index = order.indexOf(setId);
|
||||
@ -219,10 +241,10 @@ void StickerSetBox::archiveStickers() {
|
||||
return;
|
||||
}
|
||||
order.removeAt(index);
|
||||
|
||||
|
||||
session.local().writeInstalledStickers();
|
||||
session.local().writeArchivedStickers();
|
||||
|
||||
|
||||
session.data().stickers().notifyUpdated();
|
||||
}
|
||||
}).fail([](const MTP::Error &error) {
|
||||
@ -324,7 +346,7 @@ StickerSetBox::Inner::Inner(
|
||||
gotSet(result);
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
_loaded = true;
|
||||
controller->show(Box<InformBox>(tr::lng_stickers_not_found(tr::now)));
|
||||
_errors.fire(Error::NotFound);
|
||||
}).send();
|
||||
|
||||
_controller->session().api().updateStickers();
|
||||
@ -419,8 +441,7 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) {
|
||||
});
|
||||
|
||||
if (_pack.isEmpty()) {
|
||||
_controller->show(
|
||||
Box<InformBox>(tr::lng_stickers_not_found(tr::now)));
|
||||
_errors.fire(Error::NotFound);
|
||||
return;
|
||||
} else {
|
||||
int32 rows = _pack.size() / kStickersPanelPerRow + ((_pack.size() % kStickersPanelPerRow) ? 1 : 0);
|
||||
@ -440,6 +461,10 @@ rpl::producer<> StickerSetBox::Inner::updateControls() const {
|
||||
return _updateControls.events();
|
||||
}
|
||||
|
||||
rpl::producer<StickerSetBox::Error> StickerSetBox::Inner::errors() const {
|
||||
return _errors.events();
|
||||
}
|
||||
|
||||
void StickerSetBox::Inner::installDone(
|
||||
const MTPmessages_StickerSetInstallResult &result) {
|
||||
auto &sets = _controller->session().data().stickers().setsRef();
|
||||
@ -809,8 +834,7 @@ void StickerSetBox::Inner::install() {
|
||||
)).done([=](const MTPmessages_StickerSetInstallResult &result) {
|
||||
installDone(result);
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
_controller->show(
|
||||
Box<InformBox>(tr::lng_stickers_not_found(tr::now)));
|
||||
_errors.fire(Error::NotFound);
|
||||
}).send();
|
||||
}
|
||||
|
||||
|
@ -38,11 +38,16 @@ protected:
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
|
||||
private:
|
||||
enum class Error {
|
||||
NotFound,
|
||||
};
|
||||
|
||||
void updateTitleAndButtons();
|
||||
void updateButtons();
|
||||
void addStickers();
|
||||
void copyStickersLink();
|
||||
void archiveStickers();
|
||||
void handleError(Error error);
|
||||
|
||||
const not_null<Window::SessionController*> _controller;
|
||||
MTPInputStickerSet _set;
|
||||
|
Loading…
Reference in New Issue
Block a user