Review fixes

This commit is contained in:
r.kuznetsov 2019-07-04 10:10:03 +03:00 committed by Aleksey Belousov
parent 0d04f2011a
commit be44c34cf9
4 changed files with 19 additions and 14 deletions

View file

@ -954,7 +954,7 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativePingBookmarkCatalo
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeCheckInvalidCategories(JNIEnv * env,
jobject)
jobject)
{
frm()->GetBookmarkManager().CheckInvalidCategories(Purchase::GetDeviceId(),
[env](bool hasInvalidCategories)
@ -965,14 +965,14 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeCheckInvalidCatego
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeDeleteInvalidCategories(JNIEnv * env,
jobject)
jobject)
{
frm()->GetBookmarkManager().DeleteInvalidCategories();
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeResetInvalidCategories(JNIEnv * env,
jobject)
jobject)
{
frm()->GetBookmarkManager().ResetInvalidCategories();
}

View file

@ -698,7 +698,7 @@ void BookmarkCatalog::RequestBookmarksToDelete(std::string const & accessToken,
if (request.RunHttpRequest())
{
auto const resultCode = request.ErrorCode();
if (callback && resultCode >= 200 && resultCode < 300)
if (resultCode >= 200 && resultCode < 300)
{
DeleteRequestResponseData responseData;
try
@ -708,9 +708,8 @@ void BookmarkCatalog::RequestBookmarksToDelete(std::string const & accessToken,
}
catch (coding::DeserializerJson::Exception const & ex)
{
LOG(LWARNING, ("Bookmarks-to-delete request deserialization error:", ex.Msg()));
if (callback)
callback({});
LOG(LERROR, ("Bookmarks-to-delete request deserialization error:", ex.Msg()));
callback({});
return;
}
@ -718,8 +717,7 @@ void BookmarkCatalog::RequestBookmarksToDelete(std::string const & accessToken,
return;
}
}
if (callback)
callback({});
callback({});
});
}

View file

@ -2522,10 +2522,8 @@ void BookmarkManager::CheckInvalidCategories(std::string const & deviceId,
CheckInvalidCategoriesHandler && handler)
{
CHECK_THREAD_CHECKER(m_threadChecker, ());
m_bookmarkCatalog.RequestBookmarksToDelete(m_user.GetAccessToken(), m_user.GetUserId(), deviceId,
GetAllPaidCategoriesIds(),
[this, handler = std::move(handler)](
std::vector<std::string> const & serverIds)
auto f = [this, handler = std::move(handler)](std::vector<std::string> const & serverIds)
{
CHECK_THREAD_CHECKER(m_threadChecker, ());
m_invalidCategories.clear();
@ -2539,7 +2537,10 @@ void BookmarkManager::CheckInvalidCategories(std::string const & deviceId,
}
if (handler)
handler(!m_invalidCategories.empty());
});
};
m_bookmarkCatalog.RequestBookmarksToDelete(m_user.GetAccessToken(), m_user.GetUserId(),
deviceId, GetAllPaidCategoriesIds(), f);
}
void BookmarkManager::DeleteInvalidCategories()

View file

@ -330,8 +330,14 @@ public:
bool IsMyCategory(kml::MarkGroupId categoryId) const;
// CheckInvalidCategories checks invalid categories asynchronously, it prepares a state for following
// functions calls.
using CheckInvalidCategoriesHandler = std::function<void(bool hasInvalidCategories)>;
void CheckInvalidCategories(std::string const & deviceId, CheckInvalidCategoriesHandler && handler);
// The following 2 functions allow to delete invalid categories or forget about them.
// These functions are stateful, so they must be called after finishing CheckInvalidCategoriesHandler.
// ResetInvalidCategories resets internal state.
void DeleteInvalidCategories();
void ResetInvalidCategories();