Commit 590f0271 authored by Paweł Wegner's avatar Paweł Wegner

MegaNz: implemented getGeneralData.

parent 6ba3429a
......@@ -128,6 +128,10 @@ class RequestListener : public mega::MegaRequestListener, public Listener {
error_ = {e->getErrorCode(), e->getErrorString()};
}
if (r->getLink()) link_ = r->getLink();
if (r->getMegaAccountDetails()) {
space_total_ = r->getMegaAccountDetails()->getStorageMax();
space_used_ = r->getMegaAccountDetails()->getStorageUsed();
}
node_ = r->getNodeHandle();
auto callback = util::exchange(callback_, nullptr);
lock.unlock();
......@@ -140,6 +144,8 @@ class RequestListener : public mega::MegaRequestListener, public Listener {
condition_.notify_all();
}
uint64_t space_total_ = 0;
uint64_t space_used_ = 0;
std::string link_;
MegaHandle node_ = 0;
};
......@@ -803,6 +809,32 @@ MegaNz::listDirectoryPageAsync(IItem::Pointer item, const std::string&,
->run();
}
ICloudProvider::GeneralDataRequest::Pointer MegaNz::getGeneralDataAsync(
GeneralDataCallback callback) {
auto resolver = [=](Request<EitherError<GeneralData>>::Pointer r) {
ensureAuthorized<EitherError<GeneralData>>(r, [=] {
auto listener = Listener::make<RequestListener>(
[=](EitherError<void> e, Listener* listener) {
if (e.left()) return r->done(e.left());
GeneralData result;
result.username_ =
credentialsFromString(token())["username"].asString();
result.space_total_ =
static_cast<RequestListener*>(listener)->space_total_;
result.space_used_ =
static_cast<RequestListener*>(listener)->space_used_;
r->done(result);
},
this);
r->subrequest(listener);
mega()->getAccountDetails(listener.get());
});
};
return std::make_shared<Request<EitherError<GeneralData>>>(shared_from_this(),
callback, resolver)
->run();
}
std::function<void(Request<EitherError<void>>::Pointer)>
MegaNz::downloadResolver(IItem::Pointer item, IDownloadFileCallback* callback,
Range range) {
......
......@@ -93,6 +93,7 @@ class MegaNz : public CloudProvider {
RenameItemCallback) override;
ListDirectoryPageRequest::Pointer listDirectoryPageAsync(
IItem::Pointer, const std::string&, ListDirectoryPageCallback) override;
GeneralDataRequest::Pointer getGeneralDataAsync(GeneralDataCallback) override;
std::function<void(Request<EitherError<void>>::Pointer)> downloadResolver(
IItem::Pointer item, IDownloadFileCallback*, Range);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment