Repository navigation
Expand file tree
/
Copy pathpaste_presenter.cpp
More file actions
55 lines (44 loc) · 2.03 KB
/
Copy pathpaste_presenter.cpp
File metadata and controls
55 lines (44 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: Apache-2.0
#include "paste_presenter.hpp"
#include "gui/error_text.hpp"
namespace pastebin::gui {
PastePresenter::PastePresenter(::morph::bridge::Bridge& bridge, ::morph::exec::IExecutor* executor, QObject* parent)
: Presenter{parent}, _executor{executor}, _handler{bridge, executor} {}
void PastePresenter::reportError(const std::exception_ptr& err) { emit failed(::morph::ladder::gui::errorText(err)); }
void PastePresenter::create(CreatePaste action) {
track<CreatePasteResult>(
_handler.execute(std::move(action)), [this](CreatePasteResult result) { emit created(std::move(result)); },
[this](const std::exception_ptr& err) { reportError(err); });
}
void PastePresenter::get(GetPaste action) {
track<PasteView>(
_handler.execute(std::move(action)), [this](PasteView view) { emit loaded(std::move(view)); },
[this](const std::exception_ptr& err) { reportError(err); });
}
void PastePresenter::edit(EditPaste action) {
track<PasteView>(
_handler.execute(std::move(action)), [this](PasteView view) { emit edited(std::move(view)); },
[this](const std::exception_ptr& err) { reportError(err); });
}
void PastePresenter::remove(DeletePaste action) {
track<Ack>(
_handler.execute(std::move(action)), [this](Ack) { emit removed(); },
[this](const std::exception_ptr& err) { reportError(err); });
}
void PastePresenter::list(ListPastes action) {
trackFlow(*_executor, listFlow(QPointer<PastePresenter>{this}, _handler.execute(std::move(action))));
}
core::async::Task<void> PastePresenter::listFlow(QPointer<PastePresenter> self,
::morph::async::Completion<ListPastesResult> pending) {
try {
ListPastesResult result = co_await std::move(pending);
if (!self.isNull()) {
emit self->listed(std::move(result));
}
} catch (...) {
if (!self.isNull()) {
self->reportError(std::current_exception());
}
}
}
} // namespace pastebin::gui