From 6082d48f70719b2bd69243d4ce2b71d0e9dbcf56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Thu, 26 Apr 2018 18:50:08 +0200 Subject: [PATCH 01/13] Convenience method to check if generation of rich previews is enabled --- include/megaapi.h | 28 +++++++++++++++++++++-- include/megaapi_impl.h | 2 ++ src/megaapi.cpp | 7 +++++- src/megaapi_impl.cpp | 52 ++++++++++++++++++++++++++++++++++-------- 4 files changed, 77 insertions(+), 12 deletions(-) diff --git a/include/megaapi.h b/include/megaapi.h index 7dde1ef273..2dbb89e41d 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -7277,11 +7277,12 @@ class MegaApi void enableRichPreviews(bool enable, MegaRequestListener *listener = NULL); /** - * @brief Check if the app should show the rich link warning dialog to the user + * @brief Check if rich previews are automatically generated * * The associated request type with this request is MegaRequest::TYPE_GET_ATTR_USER * Valid data in the MegaRequest object received on callbacks: * - MegaRequest::getParamType - Returns the attribute type MegaApi::USER_ATTR_RICH_PREVIEWS + * - MegaRequest::getNumDetails - Returns zero * * Valid data in the MegaRequest object received in onRequestFinish when the error code * is MegaError::API_OK: @@ -7295,12 +7296,35 @@ class MegaApi * error code MegaError::API_ENOENT, but the value of MegaRequest::getFlag will still be valid. * * @param listener MegaRequestListener to track this request + */ + void isRichPreviewsEnabled(MegaRequestListener *listener = NULL); + + /** + * @brief Check if the app should show the rich link warning dialog to the user + * + * The associated request type with this request is MegaRequest::TYPE_GET_ATTR_USER + * Valid data in the MegaRequest object received on callbacks: + * - MegaRequest::getParamType - Returns the attribute type MegaApi::USER_ATTR_RICH_PREVIEWS + * - MegaRequest::getNumDetails - Returns one + * + * Valid data in the MegaRequest object received in onRequestFinish when the error code + * is MegaError::API_OK: + * - MegaRequest::getFlag - Returns true if generation of rich previews is enabled + * - MegaRequest::getMegaStringMap - Returns the raw content of the atribute: []* + * + * If the corresponding user attribute is not set yet, the request will fail with the + * error code MegaError::API_ENOENT, but the value of MegaRequest::getFlag will still be valid (false). * + * @param listener MegaRequestListener to track this request */ void shouldShowRichLinkWarning(MegaRequestListener *listener = NULL); /** - * @brief Set the number of times "Not now" option has been selected + * @brief Set the number of times "Not now" option has been selected in the rich link warning dialog + * + * The associated request type with this request is MegaRequest::TYPE_SET_ATTR_USER + * Valid data in the MegaRequest object received on callbacks: + * - MegaRequest::getParamType - Returns the attribute type MegaApi::USER_ATTR_RICH_PREVIEWS * * @param value Number of times "Not now" option has been selected * @param listener MegaRequestListener to track this request diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index 6b787994cf..cb30b59e4b 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -1586,6 +1586,8 @@ class MegaApiImpl : public MegaApp void setUserAttribute(int type, const char* value, MegaRequestListener *listener = NULL); void setUserAttribute(int type, const MegaStringMap* value, MegaRequestListener *listener = NULL); void enableRichPreviews(bool enable, MegaRequestListener *listener = NULL); + void isRichPreviewsEnabled(MegaRequestListener *listener = NULL); + void shouldShowRichLinkWarning(MegaRequestListener *listener = NULL); void setRichLinkWarningCounterValue(int value, MegaRequestListener *listener = NULL); void getUserEmail(MegaHandle handle, MegaRequestListener *listener = NULL); void setCustomNodeAttribute(MegaNode *node, const char *attrName, const char *value, MegaRequestListener *listener = NULL); diff --git a/src/megaapi.cpp b/src/megaapi.cpp index adf387be56..1f9188d001 100644 --- a/src/megaapi.cpp +++ b/src/megaapi.cpp @@ -1951,9 +1951,14 @@ void MegaApi::enableRichPreviews(bool enable, MegaRequestListener *listener) pImpl->enableRichPreviews(enable, listener); } +void MegaApi::isRichPreviewsEnabled(MegaRequestListener *listener) +{ + pImpl->isRichPreviewsEnabled(listener); +} + void MegaApi::shouldShowRichLinkWarning(MegaRequestListener *listener) { - pImpl->getUserAttr((const char*)NULL, MegaApi::USER_ATTR_RICH_PREVIEWS, NULL, 0, listener); + pImpl->shouldShowRichLinkWarning(listener); } void MegaApi::setRichLinkWarningCounterValue(int value, MegaRequestListener *listener) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index f91afd8e0c..5aee684cb5 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -5120,6 +5120,24 @@ void MegaApiImpl::enableRichPreviews(bool enable, MegaRequestListener *listener) delete stringMap; } +void MegaApiImpl::isRichPreviewsEnabled(MegaRequestListener *listener) +{ + MegaRequestPrivate *request = new MegaRequestPrivate(MegaRequest::TYPE_GET_ATTR_USER, listener); + request->setParamType(MegaApi::USER_ATTR_RICH_PREVIEWS); + request->setNumDetails(0); // 0 --> flag should indicate whether rich-links are enabled or not + requestQueue.push(request); + waiter->notify(); +} + +void MegaApiImpl::shouldShowRichLinkWarning(MegaRequestListener *listener) +{ + MegaRequestPrivate *request = new MegaRequestPrivate(MegaRequest::TYPE_GET_ATTR_USER, listener); + request->setParamType(MegaApi::USER_ATTR_RICH_PREVIEWS); + request->setNumDetails(1); // 1 --> flag should indicate whether to show the warning or not + requestQueue.push(request); + waiter->notify(); +} + void MegaApiImpl::setRichLinkWarningCounterValue(int value, MegaRequestListener *listener) { MegaStringMap *stringMap = new MegaStringMapPrivate(); @@ -11505,7 +11523,14 @@ void MegaApiImpl::getua_result(error e) else if (request->getParamType() == MegaApi::USER_ATTR_RICH_PREVIEWS && request->getType() == MegaRequest::TYPE_GET_ATTR_USER) { - request->setFlag(true); + if (request->getNumDetails() == 0) // used to check if rich-links are enabled + { + request->setFlag(false); + } + else if (request->getNumDetails() == 1) // used to check if should show warning + { + request->setFlag(true); + } } } @@ -11648,16 +11673,25 @@ void MegaApiImpl::getua_result(TLVstore *tlv) // prepare request params to know if a warning should show or not if (request->getParamType() == MegaApi::USER_ATTR_RICH_PREVIEWS) { - request->setFlag(!stringMap->get("num")); - // it doesn't matter the value, just if it exists + const char *num = stringMap->get("num"); - const char *value = stringMap->get("c"); - if (value) + if (request->getNumDetails() == 0) // used to check if rich-links are enabled { - string sValue = value; - string bValue; - Base64::atob(sValue, bValue); - request->setNumber(atoi(bValue.c_str())); + request->setFlag(num ? (*num == '1') : false); + } + else if (request->getNumDetails() == 1) // used to check if should show warning + { + request->setFlag(!num); + // it doesn't matter the value, just if it exists + + const char *value = stringMap->get("c"); + if (value) + { + string sValue = value; + string bValue; + Base64::atob(sValue, bValue); + request->setNumber(atoi(bValue.c_str())); + } } } From 4b0d4ba214494b6b84d044e6bb5fa9e585d47859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Thu, 26 Apr 2018 19:19:19 +0200 Subject: [PATCH 02/13] Fix value from b64url to binary before check --- src/megaapi_impl.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 5aee684cb5..58dcf15165 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -11677,7 +11677,17 @@ void MegaApiImpl::getua_result(TLVstore *tlv) if (request->getNumDetails() == 0) // used to check if rich-links are enabled { - request->setFlag(num ? (*num == '1') : false); + if (num) + { + string sValue = num; + string bValue; + Base64::atob(sValue, bValue); + request->setFlag(bValue == "1"); + } + else + { + request->setFlag(false); + } } else if (request->getNumDetails() == 1) // used to check if should show warning { From 94145ba8b49548ffea103d265c4d388835e5561d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Fri, 27 Apr 2018 17:58:32 +0200 Subject: [PATCH 03/13] Update doc --- include/megaapi.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/megaapi.h b/include/megaapi.h index 2dbb89e41d..490ae7db42 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -7287,13 +7287,10 @@ class MegaApi * Valid data in the MegaRequest object received in onRequestFinish when the error code * is MegaError::API_OK: * - MegaRequest::getFlag - Returns true if it is necessary to show the rich link warning - * - MegaRequest::getNumber - Returns the number of times that user has indicated that doesn't want - * modify the message with a rich link. If number is bigger than three, the extra option "Never" - * must be added to the warning dialog. * - MegaRequest::getMegaStringMap - Returns the raw content of the atribute: []* * * If the corresponding user attribute is not set yet, the request will fail with the - * error code MegaError::API_ENOENT, but the value of MegaRequest::getFlag will still be valid. + * error code MegaError::API_ENOENT, but the value of MegaRequest::getFlag will still be valid (false). * * @param listener MegaRequestListener to track this request */ @@ -7310,10 +7307,13 @@ class MegaApi * Valid data in the MegaRequest object received in onRequestFinish when the error code * is MegaError::API_OK: * - MegaRequest::getFlag - Returns true if generation of rich previews is enabled + * - MegaRequest::getNumber - Returns the number of times that user has indicated that doesn't want + * modify the message with a rich link. If number is bigger than three, the extra option "Never" + * must be added to the warning dialog. * - MegaRequest::getMegaStringMap - Returns the raw content of the atribute: []* * * If the corresponding user attribute is not set yet, the request will fail with the - * error code MegaError::API_ENOENT, but the value of MegaRequest::getFlag will still be valid (false). + * error code MegaError::API_ENOENT, but the value of MegaRequest::getFlag will still be valid (true). * * @param listener MegaRequestListener to track this request */ From 412b12df8b8d4c9e6e68d6ee1d51cc3500200886 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Mon, 30 Apr 2018 13:09:43 +0200 Subject: [PATCH 04/13] set default ffmpeg log level to AV_LOG_PANIC in freeimage --- src/gfx/freeimage.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gfx/freeimage.cpp b/src/gfx/freeimage.cpp index 8b61188385..c5806edbaa 100644 --- a/src/gfx/freeimage.cpp +++ b/src/gfx/freeimage.cpp @@ -96,6 +96,10 @@ const char *GfxProcFreeImage::supportedformatsFfmpeg() bool GfxProcFreeImage::readbitmapFfmpeg(FileAccess* fa, string* imagePath, int size) { +#ifndef DEBUG + av_log_set_level(AV_LOG_PANIC); +#endif + // Open video file AVFormatContext* formatContext = avformat_alloc_context(); if (avformat_open_input(&formatContext, imagePath->data(), NULL, NULL)) From 02d78f780bf9d6d50622ecc8454e54c50d30d790 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 30 Apr 2018 14:01:15 +0200 Subject: [PATCH 05/13] New function to know if an outgoing shared folder is pending --- include/megaapi.h | 10 ++++++++++ include/megaapi_impl.h | 8 +++++--- src/megaapi.cpp | 5 +++++ src/megaapi_impl.cpp | 23 +++++++++++++++-------- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/include/megaapi.h b/include/megaapi.h index 490ae7db42..d0d00ef2d6 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -1390,6 +1390,16 @@ class MegaShare * @return The timestamp when the sharing was created (in seconds since the epoch) */ virtual int64_t getTimestamp(); + + /** + * @brief Returns true if the sharing is pending + * + * A sharing is pending when the folder has been shared with a user (or email) that + * is not still a contact of this account. + * + * @return True if the sharing is pending, otherwise false. + */ + virtual bool isPending(); }; #ifdef ENABLE_CHAT diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index cb30b59e4b..a10ad054fc 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -397,22 +397,24 @@ class MegaHandleListPrivate : public MegaHandleList class MegaSharePrivate : public MegaShare { public: - static MegaShare *fromShare(MegaHandle nodeMegaHandle, Share *share); + static MegaShare *fromShare(MegaHandle nodeMegaHandle, Share *share, bool pending = false); virtual MegaShare *copy(); virtual ~MegaSharePrivate(); virtual const char *getUser(); virtual MegaHandle getNodeHandle(); virtual int getAccess(); virtual int64_t getTimestamp(); + virtual bool isPending(); protected: - MegaSharePrivate(MegaHandle nodehandle, Share *share); + MegaSharePrivate(MegaHandle nodehandle, Share *share, bool pending = false); MegaSharePrivate(MegaShare *share); MegaHandle nodehandle; const char *user; int access; int64_t ts; + bool pending; }; class MegaTransferPrivate : public MegaTransfer, public Cachable @@ -1243,7 +1245,7 @@ class MegaShareListPrivate : public MegaShareList { public: MegaShareListPrivate(); - MegaShareListPrivate(Share** newlist, MegaHandle *MegaHandlelist, int size); + MegaShareListPrivate(Share** newlist, MegaHandle *MegaHandlelist, int size, bool pending = false); virtual ~MegaShareListPrivate(); virtual MegaShare* get(int i); virtual int size(); diff --git a/src/megaapi.cpp b/src/megaapi.cpp index 1f9188d001..4e5ba7197d 100644 --- a/src/megaapi.cpp +++ b/src/megaapi.cpp @@ -519,6 +519,11 @@ int64_t MegaShare::getTimestamp() return 0; } +bool MegaShare::isPending() +{ + return false; +} + MegaRequest::~MegaRequest() { } MegaRequest *MegaRequest::copy() { diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 58dcf15165..8917ee6032 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -1399,6 +1399,7 @@ MegaSharePrivate::MegaSharePrivate(MegaShare *share) : MegaShare() this->user = MegaApi::strdup(share->getUser()); this->access = share->getAccess(); this->ts = share->getTimestamp(); + this->pending = share->isPending(); } MegaShare *MegaSharePrivate::copy() @@ -1406,7 +1407,7 @@ MegaShare *MegaSharePrivate::copy() return new MegaSharePrivate(this); } -MegaSharePrivate::MegaSharePrivate(uint64_t handle, Share *share) +MegaSharePrivate::MegaSharePrivate(uint64_t handle, Share *share, bool pending) { this->nodehandle = handle; this->user = share->user ? MegaApi::strdup(share->user->email.c_str()) : NULL; @@ -1417,11 +1418,12 @@ MegaSharePrivate::MegaSharePrivate(uint64_t handle, Share *share) } this->access = share->access; this->ts = share->ts; + this->pending = pending; } -MegaShare *MegaSharePrivate::fromShare(uint64_t nodeuint64_t, Share *share) +MegaShare *MegaSharePrivate::fromShare(uint64_t nodeuint64_t, Share *share, bool pending) { - return new MegaSharePrivate(nodeuint64_t, share); + return new MegaSharePrivate(nodeuint64_t, share, pending); } MegaSharePrivate::~MegaSharePrivate() @@ -1446,7 +1448,12 @@ int MegaSharePrivate::getAccess() int64_t MegaSharePrivate::getTimestamp() { - return ts; + return ts; +} + +bool MegaSharePrivate::isPending() +{ + return pending; } @@ -3290,14 +3297,14 @@ MegaShareListPrivate::MegaShareListPrivate() s = 0; } -MegaShareListPrivate::MegaShareListPrivate(Share** newlist, uint64_t *uint64_tlist, int size) +MegaShareListPrivate::MegaShareListPrivate(Share** newlist, uint64_t *uint64_tlist, int size, bool pending) { list = NULL; s = size; if(!size) return; list = new MegaShare*[size]; for(int i=0; inodebyhandle(client->rootnodes[0]), &shareProcessor, true); - MegaShareList *shareList = new MegaShareListPrivate(shareProcessor.getShares().data(), shareProcessor.getHandles().data(), shareProcessor.getShares().size()); + MegaShareList *shareList = new MegaShareListPrivate(shareProcessor.getShares().data(), shareProcessor.getHandles().data(), shareProcessor.getShares().size(), true); sdkMutex.unlock(); return shareList; @@ -7873,7 +7880,7 @@ MegaShareList *MegaApiImpl::getPendingOutShares(MegaNode *megaNode) vHandles.push_back(node->nodehandle); } - MegaShareList *shareList = new MegaShareListPrivate(vShares.data(), vHandles.data(), vShares.size()); + MegaShareList *shareList = new MegaShareListPrivate(vShares.data(), vHandles.data(), vShares.size(), true); sdkMutex.unlock(); return shareList; } From 001ca00e2eb2ee236536de27743d8a7d8cc4a8f1 Mon Sep 17 00:00:00 2001 From: Javier Trujillo Date: Mon, 30 Apr 2018 21:14:58 +0200 Subject: [PATCH 06/13] Objective-C bindings for rich links --- bindings/ios/MEGARequest.h | 1 + bindings/ios/MEGASdk.h | 92 +++++++++++++++++++++++++++++++++++++- bindings/ios/MEGASdk.mm | 24 ++++++++++ bindings/ios/MEGAUser.h | 41 ++++++++++------- 4 files changed, 140 insertions(+), 18 deletions(-) diff --git a/bindings/ios/MEGARequest.h b/bindings/ios/MEGARequest.h index ee0fa8c073..c217f95efe 100644 --- a/bindings/ios/MEGARequest.h +++ b/bindings/ios/MEGARequest.h @@ -120,6 +120,7 @@ typedef NS_ENUM (NSInteger, MEGARequestType) { MEGARequestTypeContactLinkQuery, MEGARequestTypeContactLinkDelete, MEGARequestTypeFolderInfo, + MEGARequestTypeRichLink, TotalOfRequestTypes }; diff --git a/bindings/ios/MEGASdk.h b/bindings/ios/MEGASdk.h index 2a7407c2dd..d5b7ccc86f 100644 --- a/bindings/ios/MEGASdk.h +++ b/bindings/ios/MEGASdk.h @@ -92,7 +92,8 @@ typedef NS_ENUM(NSInteger, MEGAUserAttribute) { MEGAUserAttributeSigCU255PublicKey = 9, // public - byte array MEGAUserAttributeLanguage = 14, // private - char array MEGAUserAttributePwdReminder = 15, // private - char array - MEGAUserAttributeContactLinkVerification = 17 // private - byte array + MEGAUserAttributeContactLinkVerification = 17, // private - byte array + MEGAUserAttributeRichPreviews = 18 // private - byte array }; typedef NS_ENUM(NSInteger, MEGANodeAttribute) { @@ -3038,6 +3039,95 @@ typedef NS_ENUM(NSUInteger, Retry) { */ - (void)shouldShowPasswordReminderDialogAtLogout:(BOOL)atLogout; +/** + * @brief Enable or disable the generation of rich previews + * + * The associated request type with this request is MEGARequestTypeSetAttrUser + * Valid data in the MEGARequest object received on callbacks: + * - [MEGARequest paramType] - Returns the attribute type MEGAUserAttributeRichPreviews + * + * @param enable YES to enable the generation of rich previews + * @param delegate MEGARequestDelegate to track this request + */ +- (void)enableRichPreviews:(BOOL)enable delegate:(id)delegate; + +/** + * @brief Enable or disable the generation of rich previews + * + * The associated request type with this request is MEGARequestTypeSetAttrUser + * Valid data in the MEGARequest object received on callbacks: + * - [MEGARequest paramType] - Returns the attribute type MEGAUserAttributeRichPreviews + * + * @param enable YES to enable the generation of rich previews + */ +- (void)enableRichPreviews:(BOOL)enable; + +/** + * @brief Check if the app should show the rich link warning dialog to the user + * + * The associated request type with this request is MEGARequestTypeGetAttrUser + * Valid data in the MEGARequest object received on callbacks: + * - [MEGARequest paramType] - Returns the attribute type MEGAUserAttributeRichPreviews + * - [MEGARequest numDetails] - Returns one + * + * Valid data in the MEGARequest object received in onRequestFinish when the error code + * is MEGAErrorTypeApiOk: + * - [MEGARequest flag] - Returns YES if generation of rich previews is enabled + * - [MEGARequest number] - Returns the number of times that user has indicated that doesn't want + * modify the message with a rich link. If number is bigger than three, the extra option "Never" + * must be added to the warning dialog. + * + * If the corresponding user attribute is not set yet, the request will fail with the + * error code MEGAErrorTypeApiENoent, but the value of [MEGARequest flag] will still be valid (YES). + * + * @param delegate MEGARequestDelegate to track this request + */ +- (void)shouldShowRichLinkWarningWithDelegate:(id)delegate; + +/** + * @brief Check if the app should show the rich link warning dialog to the user + * + * The associated request type with this request is MEGARequestTypeGetAttrUser + * Valid data in the MEGARequest object received on callbacks: + * - [MEGARequest paramType] - Returns the attribute type MEGAUserAttributeRichPreviews + * - [MEGARequest numDetails] - Returns one + * + * Valid data in the MEGARequest object received in onRequestFinish when the error code + * is MEGAErrorTypeApiOk: + * - [MEGARequest flag] - Returns YES if generation of rich previews is enabled + * - [MEGARequest number] - Returns the number of times that user has indicated that doesn't want + * modify the message with a rich link. If number is bigger than three, the extra option "Never" + * must be added to the warning dialog. + * + * If the corresponding user attribute is not set yet, the request will fail with the + * error code MEGAErrorTypeApiENoent, but the value of [MEGARequest flag] will still be valid (YES). + * + */ +- (void)shouldShowRichLinkWarning; + +/** + * @brief Set the number of times "Not now" option has been selected in the rich link warning dialog + * + * The associated request type with this request is MEGARequestTypeSetAttrUser + * Valid data in the MEGARequest object received on callbacks: + * - [MEGARequest paramType] - Returns the attribute type MEGAUserAttributeRichPreviews + * + * @param value Number of times "Not now" option has been selected + * @param delegate MEGARequestDelegate to track this request + */ +- (void)setRichLinkWarningCounterValue:(NSUInteger)value delegate:(id)delegate; + +/** + * @brief Set the number of times "Not now" option has been selected in the rich link warning dialog + * + * The associated request type with this request is MEGARequestTypeSetAttrUser + * Valid data in the MEGARequest object received on callbacks: + * - [MEGARequest paramType] - Returns the attribute type MEGAUserAttributeRichPreviews + * + * @param value Number of times "Not now" option has been selected + */ +- (void)setRichLinkWarningCounterValue:(NSUInteger)value; + /** * @brief Use HTTPS communications only * diff --git a/bindings/ios/MEGASdk.mm b/bindings/ios/MEGASdk.mm index 120c8247fa..2414cf2923 100644 --- a/bindings/ios/MEGASdk.mm +++ b/bindings/ios/MEGASdk.mm @@ -1023,6 +1023,30 @@ - (void)shouldShowPasswordReminderDialogAtLogout:(BOOL)atLogout { self.megaApi->shouldShowPasswordReminderDialog(atLogout); } +- (void)enableRichPreviews:(BOOL)enable delegate:(id)delegate { + self.megaApi->enableRichPreviews(enable, [self createDelegateMEGARequestListener:delegate singleListener:YES]); +} + +- (void)enableRichPreviews:(BOOL)enable { + self.megaApi->enableRichPreviews(enable); +} + +- (void)shouldShowRichLinkWarningWithDelegate:(id)delegate { + self.megaApi->shouldShowRichLinkWarning([self createDelegateMEGARequestListener:delegate singleListener:YES]); +} + +- (void)shouldShowRichLinkWarning { + self.megaApi->shouldShowRichLinkWarning(); +} + +- (void)setRichLinkWarningCounterValue:(NSUInteger)value delegate:(id)delegate { + self.megaApi->setRichLinkWarningCounterValue((int)value, [self createDelegateMEGARequestListener:delegate singleListener:YES]); +} + +- (void)setRichLinkWarningCounterValue:(NSUInteger)value { + self.megaApi->setRichLinkWarningCounterValue((int)value); +} + - (void)useHttpsOnly:(BOOL)httpsOnly delegate:(id)delegate { self.megaApi->useHttpsOnly(httpsOnly, [self createDelegateMEGARequestListener:delegate singleListener:YES]); } diff --git a/bindings/ios/MEGAUser.h b/bindings/ios/MEGAUser.h index 044e608bcd..1b820b951c 100644 --- a/bindings/ios/MEGAUser.h +++ b/bindings/ios/MEGAUser.h @@ -29,23 +29,24 @@ typedef NS_ENUM (NSInteger, MEGAUserVisibility) { }; typedef NS_ENUM(NSInteger, MEGAUserChangeType) { - MEGAUserChangeTypeAuth = 0x01, - MEGAUserChangeTypeLstint = 0x02, - MEGAUserChangeTypeAvatar = 0x04, - MEGAUserChangeTypeFirstname = 0x08, - MEGAUserChangeTypeLastname = 0x10, - MEGAUserChangeTypeEmail = 0x20, - MEGAUserChangeTypeKeyring = 0x40, - MEGAUserChangeTypeCountry = 0x80, - MEGAUserChangeTypeBirthday = 0x100, - MEGAUserChangeTypePubKeyCu255 = 0x200, - MEGAUserChangeTypePubKeyEd255 = 0x400, - MEGAUserChangeTypeSigPubKeyRsa = 0x800, - MEGAUserChangeTypeSigPubKeyCu255 = 0x1000, - MEGAUserChangeTypeLanguage = 0x2000, - MEGAUserChangeTypePwdReminder = 0x4000, - MEGAUserChangeTypeDisableVersions = 0x8000, - MEGAUserChangeTypeContactLinkVerification = 0x10000 + MEGAUserChangeTypeAuth = 0x01, + MEGAUserChangeTypeLstint = 0x02, + MEGAUserChangeTypeAvatar = 0x04, + MEGAUserChangeTypeFirstname = 0x08, + MEGAUserChangeTypeLastname = 0x10, + MEGAUserChangeTypeEmail = 0x20, + MEGAUserChangeTypeKeyring = 0x40, + MEGAUserChangeTypeCountry = 0x80, + MEGAUserChangeTypeBirthday = 0x100, + MEGAUserChangeTypePubKeyCu255 = 0x200, + MEGAUserChangeTypePubKeyEd255 = 0x400, + MEGAUserChangeTypeSigPubKeyRsa = 0x800, + MEGAUserChangeTypeSigPubKeyCu255 = 0x1000, + MEGAUserChangeTypeLanguage = 0x2000, + MEGAUserChangeTypePwdReminder = 0x4000, + MEGAUserChangeTypeDisableVersions = 0x8000, + MEGAUserChangeTypeContactLinkVerification = 0x10000, + MEGAUserChangeTypeRichPreviews = 0x20000 }; /** @@ -161,6 +162,9 @@ typedef NS_ENUM(NSInteger, MEGAUserChangeType) { * - MEGAUserChangeTypeContactLinkVerification = 0x10000 * Check if option for automatic contact-link verification has changed * + * - MEGAUserChangeTypeRichPreviews = 0x20000 + * Check if option for rich links has changed + * */ @property (readonly, nonatomic) MEGAUserChangeType changes; @@ -242,6 +246,9 @@ typedef NS_ENUM(NSInteger, MEGAUserChangeType) { * - MEGAUserChangeTypeContactLinkVerification = 0x10000 * Check if option for automatic contact-link verification has changed * + * - MEGAUserChangeTypeRichPreviews = 0x20000 + * Check if option for rich links has changed + * * @return YES if this user has an specific change */ - (BOOL)hasChangedType:(MEGAUserChangeType)changeType; From 6f3cfc2e5625d703331b19216f825e84263241da Mon Sep 17 00:00:00 2001 From: Victor Teniente Date: Wed, 2 May 2018 14:36:20 +0200 Subject: [PATCH 07/13] Support to check if MegaTransfer is finished --- include/megaapi.h | 6 ++++++ include/megaapi_impl.h | 1 + src/megaapi.cpp | 5 +++++ src/megaapi_impl.cpp | 5 +++++ 4 files changed, 17 insertions(+) diff --git a/include/megaapi.h b/include/megaapi.h index d0d00ef2d6..2d0aa8a10c 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -3012,6 +3012,12 @@ class MegaTransfer */ virtual bool isStreamingTransfer() const; + /** + * @brief Returns true is the transfer is at finished state (COMPLETED, CANCELLED OR FAILED) + * @return true if this transfer is finished, false otherwise + */ + virtual bool isFinished() const; + /** * @brief Returns the received bytes since the last callback * diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index a10ad054fc..6853deb913 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -485,6 +485,7 @@ class MegaTransferPrivate : public MegaTransfer, public Cachable virtual MegaNode *getPublicMegaNode() const; virtual bool isSyncTransfer() const; virtual bool isStreamingTransfer() const; + virtual bool isFinished() const; virtual bool isSourceFileTemporary() const; virtual char *getLastBytes() const; virtual MegaError getLastError() const; diff --git a/src/megaapi.cpp b/src/megaapi.cpp index 4e5ba7197d..9d68908c33 100644 --- a/src/megaapi.cpp +++ b/src/megaapi.cpp @@ -849,6 +849,11 @@ bool MegaTransfer::isStreamingTransfer() const return false; } +bool MegaTransfer::isFinished() const +{ + return false; +} + char *MegaTransfer::getLastBytes() const { return NULL; diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 8917ee6032..e008a857dd 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -1601,6 +1601,11 @@ bool MegaTransferPrivate::isStreamingTransfer() const return streamingTransfer; } +bool MegaTransferPrivate::isFinished() const +{ + return state == STATE_COMPLETED || state == STATE_CANCELLED || state == STATE_FAILED; +} + bool MegaTransferPrivate::isSourceFileTemporary() const { return temporarySourceFile; From e78881be828c9316eb2c6428e9972a0267be009f Mon Sep 17 00:00:00 2001 From: Javier Navarro Date: Wed, 2 May 2018 17:23:23 +0200 Subject: [PATCH 08/13] Add retrySSLErros, setPublicKeyPinning and localLogout methods --- bindings/ios/MEGASdk.h | 44 +++++++++++++++++++++++++++++++++++++++++ bindings/ios/MEGASdk.mm | 16 +++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/bindings/ios/MEGASdk.h b/bindings/ios/MEGASdk.h index 2a7407c2dd..178abc02e7 100644 --- a/bindings/ios/MEGASdk.h +++ b/bindings/ios/MEGASdk.h @@ -710,6 +710,23 @@ typedef NS_ENUM(NSUInteger, Retry) { */ - (void)logout; +/** + * @brief Logout of the MEGA account without invalidating the session + * + * The associated request type with this request is MEGARequestTypeLogout + * + * @param delegate Delegate to track this request. + */ +- (void)localLogoutWithDelegate:(id)delegate; + +/** + * @brief Logout of the MEGA account without invalidating the session + * + * The associated request type with this request is MEGARequestTypeLogout + * + */ +- (void)localLogout; + /** * @brief Invalidate the existing cache and create a fresh one */ @@ -4753,6 +4770,33 @@ typedef NS_ENUM(NSUInteger, Retry) { */ - (void)getContactLinksOption; +/** + * @brief Keep retrying when public key pinning fails + * + * By default, when the check of the MEGA public key fails, it causes an automatic + * logout. Pass NO to this function to disable that automatic logout and + * keep the SDK retrying the request. + * + * Even if the automatic logout is disabled, a request of the type MEGARequestTypeLogout + * will be automatically created and callbacks (onRequestStart, onRequestFinish) will + * be sent. However, logout won't be really executed and in onRequestFinish the error code + * for the request will be MEGAErrorTypeApiEIncomplete + * + * @param enable YES to keep retrying failed requests due to a fail checking the MEGA public key + * or NO to perform an automatic logout in that case + */ +- (void)retrySSLErrors:(BOOL)enable; + +/** + * @brief Enable / disable the public key pinning + * + * Public key pinning is enabled by default for all sensible communications. + * It is strongly discouraged to disable this feature. + * + * @param enable YES to keep public key pinning enabled, NO to disable it + */ +- (void)setPublicKeyPinning:(BOOL)enable; + /** * @brief Create a thumbnail for an image * @param imagePath Image path diff --git a/bindings/ios/MEGASdk.mm b/bindings/ios/MEGASdk.mm index 120c8247fa..a4b90e4381 100644 --- a/bindings/ios/MEGASdk.mm +++ b/bindings/ios/MEGASdk.mm @@ -455,6 +455,14 @@ - (void)logout { self.megaApi->logout(); } +- (void)localLogoutWithDelegate:(id)delegate { + self.megaApi->localLogout([self createDelegateMEGARequestListener:delegate singleListener:self]); +} + +- (void)localLogout { + self.megaApi->localLogout(); +} + - (void)invalidateCache { self.megaApi->invalidateCache(); } @@ -1630,6 +1638,14 @@ - (void)getContactLinksOption { self.megaApi->getContactLinksOption(); } +- (void)retrySSLErrors:(BOOL)enable { + self.megaApi->retrySSLerrors(enable); +} + +- (void)setPublicKeyPinning:(BOOL)enable { + self.megaApi->setPublicKeyPinning(enable); +} + - (BOOL)createThumbnail:(NSString *)imagePath destinatioPath:(NSString *)destinationPath { if (imagePath == nil || destinationPath == nil) return NO; From 25bc3fa93aa7759f1acf0f01cecd7fac78ec6aa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Wed, 2 May 2018 19:26:04 +0200 Subject: [PATCH 09/13] Adjust condition for assertion on creation of empty PCRs --- src/megaclient.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/megaclient.cpp b/src/megaclient.cpp index 29fed1fa93..b69d4e5afb 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -7496,7 +7496,8 @@ PendingContactRequest* MegaClient::findpcr(handle p) { pcr = new PendingContactRequest(p); pcrindex[p] = pcr; - assert(false); + assert(fetchingnodes); + // while fetchingnodes, outgoing shares reference an "empty" PCR that is completed when `opc` is parsed } return pcrindex[p]; From 4f7eade35252aa6f215412d42132ff22cf75d17c Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Thu, 3 May 2018 14:51:37 +0200 Subject: [PATCH 10/13] Update prebuilt libraries for the Android example --- examples/android/ExampleApp/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/android/ExampleApp/README.md b/examples/android/ExampleApp/README.md index 04d7e83872..5353054207 100644 --- a/examples/android/ExampleApp/README.md +++ b/examples/android/ExampleApp/README.md @@ -20,7 +20,7 @@ You have two options, using a prebuilt native library or building it by yourself ``` git clone --recursive https://github.com/meganz/sdk.git ``` -* Download the prebuilt libraries (`libmega.so`) along with its corresponding Java classes from [here](https://mega.nz/#!AkMXUBiL!CXiHUPCo2EV6TllFr-k1fMHnZM5_VfgDAzTmoAoNRoo). Generated with commit: 84a546f81e04ca2845fbfceae5634ed57eeef957 +* Download the prebuilt libraries (`libmega.so`) along with its corresponding Java classes from [here](https://mega.nz/#!F9MDiIYR!Udguz_byyIttpjaa2twcWZGqcqWCfalhGO-_jg7kNCo). Generated with commit: 08adf46ca80dd8aa9f54916b998c2efe1f7a444d * Extract the content into `app/src/main`, keeping the folder structure. * Open the project with Android Studio, let it build the project and hit _*Run*_ From 8c06fba275521fdb5c22b7723c7647bfcb041778 Mon Sep 17 00:00:00 2001 From: Javier Trujillo Date: Fri, 4 May 2018 10:10:34 +0200 Subject: [PATCH 11/13] Updated Objective-C bindings for rich links - Fixed typo in megaapi.h --- bindings/ios/MEGASdk.h | 41 +++++++++++++++++++++++++++++++++++++++-- bindings/ios/MEGASdk.mm | 8 ++++++++ include/megaapi.h | 4 ++-- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/bindings/ios/MEGASdk.h b/bindings/ios/MEGASdk.h index f85064495b..3a1362ce7f 100644 --- a/bindings/ios/MEGASdk.h +++ b/bindings/ios/MEGASdk.h @@ -3079,6 +3079,43 @@ typedef NS_ENUM(NSUInteger, Retry) { */ - (void)enableRichPreviews:(BOOL)enable; +/** + * @brief Check if rich previews are automatically generated + * + * The associated request type with this request is MEGARequestTypeGetAttrUser + * Valid data in the MEGARequest object received on callbacks: + * - [MEGARequest paramType] - Returns the attribute type MEGAUserAttributeRichPreviews + * - [MEGARequest numDetails] - Returns zero + * + * Valid data in the MEGARequest object received in onRequestFinish when the error code + * is MEGAErrorTypeApiOk: + * - [MEGARequest flag] - Returns YES if generation of rich previews is enabled + * + * If the corresponding user attribute is not set yet, the request will fail with the + * error code MEGAErrorTypeApiENoent, but the value of [MEGARequest flag] will still be valid (NO). + * + * @param delegate MEGARequestDelegate to track this request + */ +- (void)isRichPreviewsEnabledWithDelegate:(id)delegate; + +/** + * @brief Check if rich previews are automatically generated + * + * The associated request type with this request is MEGARequestTypeGetAttrUser + * Valid data in the MEGARequest object received on callbacks: + * - [MEGARequest paramType] - Returns the attribute type MEGAUserAttributeRichPreviews + * - [MEGARequest numDetails] - Returns zero + * + * Valid data in the MEGARequest object received in onRequestFinish when the error code + * is MEGAErrorTypeApiOk: + * - [MEGARequest flag] - Returns YES if generation of rich previews is enabled + * + * If the corresponding user attribute is not set yet, the request will fail with the + * error code MEGAErrorTypeApiENoent, but the value of [MEGARequest flag] will still be valid (NO). + * + */ +- (void)isRichPreviewsEnabled; + /** * @brief Check if the app should show the rich link warning dialog to the user * @@ -3089,7 +3126,7 @@ typedef NS_ENUM(NSUInteger, Retry) { * * Valid data in the MEGARequest object received in onRequestFinish when the error code * is MEGAErrorTypeApiOk: - * - [MEGARequest flag] - Returns YES if generation of rich previews is enabled + * - [MEGARequest flag] - Returns YES if it is necessary to show the rich link warning * - [MEGARequest number] - Returns the number of times that user has indicated that doesn't want * modify the message with a rich link. If number is bigger than three, the extra option "Never" * must be added to the warning dialog. @@ -3111,7 +3148,7 @@ typedef NS_ENUM(NSUInteger, Retry) { * * Valid data in the MEGARequest object received in onRequestFinish when the error code * is MEGAErrorTypeApiOk: - * - [MEGARequest flag] - Returns YES if generation of rich previews is enabled + * - [MEGARequest flag] - Returns YES if it is necessary to show the rich link warning * - [MEGARequest number] - Returns the number of times that user has indicated that doesn't want * modify the message with a rich link. If number is bigger than three, the extra option "Never" * must be added to the warning dialog. diff --git a/bindings/ios/MEGASdk.mm b/bindings/ios/MEGASdk.mm index f7f834d6ae..58a46d1162 100644 --- a/bindings/ios/MEGASdk.mm +++ b/bindings/ios/MEGASdk.mm @@ -1039,6 +1039,14 @@ - (void)enableRichPreviews:(BOOL)enable { self.megaApi->enableRichPreviews(enable); } +- (void)isRichPreviewsEnabledWithDelegate:(id)delegate { + self.megaApi->isRichPreviewsEnabled([self createDelegateMEGARequestListener:delegate singleListener:YES]); +} + +- (void)isRichPreviewsEnabled { + self.megaApi->isRichPreviewsEnabled(); +} + - (void)shouldShowRichLinkWarningWithDelegate:(id)delegate { self.megaApi->shouldShowRichLinkWarning([self createDelegateMEGARequestListener:delegate singleListener:YES]); } diff --git a/include/megaapi.h b/include/megaapi.h index 2d0aa8a10c..f64be49f03 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -7302,7 +7302,7 @@ class MegaApi * * Valid data in the MegaRequest object received in onRequestFinish when the error code * is MegaError::API_OK: - * - MegaRequest::getFlag - Returns true if it is necessary to show the rich link warning + * - MegaRequest::getFlag - Returns true if generation of rich previews is enabled * - MegaRequest::getMegaStringMap - Returns the raw content of the atribute: []* * * If the corresponding user attribute is not set yet, the request will fail with the @@ -7322,7 +7322,7 @@ class MegaApi * * Valid data in the MegaRequest object received in onRequestFinish when the error code * is MegaError::API_OK: - * - MegaRequest::getFlag - Returns true if generation of rich previews is enabled + * - MegaRequest::getFlag - Returns true if it is necessary to show the rich link warning * - MegaRequest::getNumber - Returns the number of times that user has indicated that doesn't want * modify the message with a rich link. If number is bigger than three, the extra option "Never" * must be added to the warning dialog. From ed6bf03051bb387f2c0d0c8c847fd97ff0f2dca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Mon, 7 May 2018 18:37:40 +0200 Subject: [PATCH 12/13] Update version number --- include/mega/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mega/version.h b/include/mega/version.h index 4ee24dcc5b..6fb3a8e9ea 100644 --- a/include/mega/version.h +++ b/include/mega/version.h @@ -5,5 +5,5 @@ #define MEGA_MINOR_VERSION 3 #endif #ifndef MEGA_MICRO_VERSION -#define MEGA_MICRO_VERSION 6 +#define MEGA_MICRO_VERSION 7 #endif From 0c1959373d5b570ed08e638a559b6b376cf262c4 Mon Sep 17 00:00:00 2001 From: Javier Navarro Date: Fri, 11 May 2018 14:41:32 +0200 Subject: [PATCH 13/13] Fix iOS compilation --- bindings/ios/MEGASdk.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/ios/MEGASdk.mm b/bindings/ios/MEGASdk.mm index 58a46d1162..708e756dcd 100644 --- a/bindings/ios/MEGASdk.mm +++ b/bindings/ios/MEGASdk.mm @@ -456,7 +456,7 @@ - (void)logout { } - (void)localLogoutWithDelegate:(id)delegate { - self.megaApi->localLogout([self createDelegateMEGARequestListener:delegate singleListener:self]); + self.megaApi->localLogout([self createDelegateMEGARequestListener:delegate singleListener:YES]); } - (void)localLogout {