From 03113520edd78ed83cec4adea8e9b04ac90ddfd2 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Thu, 7 Dec 2023 12:08:55 +0300 Subject: [PATCH] fix: perform flow --- .../sdk/java/internal/ModuleUserProfile.java | 20 +++++++------------ .../sdk/java/internal/UserEditorTests.java | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleUserProfile.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleUserProfile.java index 6ed7d352..cd3e6ccd 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleUserProfile.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleUserProfile.java @@ -14,6 +14,7 @@ public class ModuleUserProfile extends ModuleBase { static final String CUSTOM_KEY = "custom"; boolean isSynced = true; + static final String PICTURE_BYTES = "[CLY]_picture_bytes"; UserProfile userProfileInterface; private final Map sets; private final List ops; @@ -92,9 +93,10 @@ private Object optString(String key, Object value) { * Transforming changes in "sets" into a json contained in "changes" * * @param changes JSONObject to store changes + * @param params Params to store changes * @throws JSONException if something goes wrong */ - void perform(JSONObject changes) throws JSONException { + void perform(JSONObject changes, Params params) throws JSONException { for (String key : sets.keySet()) { Object value = sets.get(key); switch (key) { @@ -113,7 +115,7 @@ void perform(JSONObject changes) throws JSONException { } else if (value instanceof byte[]) { internalConfig.sdk.user().picture = (byte[]) value; //set a special value to indicate that the picture information is already stored in memory - changes.put(PredefinedUserPropertyKeys.PICTURE_PATH, Utils.Base64.encode((byte[]) value)); + params.add(PICTURE_BYTES, Utils.Base64.encode((byte[]) value)); } break; case PredefinedUserPropertyKeys.PICTURE_PATH: @@ -127,7 +129,7 @@ void perform(JSONObject changes) throws JSONException { changes.put(PredefinedUserPropertyKeys.PICTURE, value); } else { //if we get here then that means it is a local file path which we would send over as bytes to the server - changes.put(PredefinedUserPropertyKeys.PICTURE_PATH, value); + params.add(PredefinedUserPropertyKeys.PICTURE_PATH, value); } internalConfig.sdk.user().picturePath = value.toString(); } else { @@ -210,16 +212,8 @@ private Params prepareRequestParamsForUserProfile() { isSynced = true; Params params = new Params(); final JSONObject json = new JSONObject(); - perform(json); - if (json.has(PredefinedUserPropertyKeys.PICTURE_PATH)) { - try { - params.add(PredefinedUserPropertyKeys.PICTURE_PATH, json.getString(PredefinedUserPropertyKeys.PICTURE_PATH)); - json.remove(PredefinedUserPropertyKeys.PICTURE_PATH); - } catch (JSONException e) { - L.w("Won't send picturePath" + e); - } - } - if (!json.isEmpty() || params.has(PredefinedUserPropertyKeys.PICTURE_PATH)) { + perform(json, params); + if (!json.isEmpty() || params.has(PredefinedUserPropertyKeys.PICTURE_PATH) || params.has(PICTURE_BYTES)) { params.add("user_details", json.toString()); return params; } else { diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/UserEditorTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/UserEditorTests.java index e4278c6b..b4086032 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/UserEditorTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/UserEditorTests.java @@ -112,7 +112,7 @@ public void setPicture_binaryData() { sessionHandler(() -> Countly.instance().user().edit().setPicture(imgData).commit()); validatePictureAndPath(null, imgData); Countly.session().end(); - validateUserDetailsRequestInRQ(map("user_details", "{}", "picturePath", Utils.Base64.encode(imgData))); + validateUserDetailsRequestInRQ(map("user_details", "{}", ModuleUserProfile.PICTURE_BYTES, Utils.Base64.encode(imgData))); } /**