package com.helpshift.storage; import com.helpshift.log.HSLogger; import com.helpshift.util.Utils; import java.util.Map; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes3.dex */ public class HSGenericDataManager { public HSPersistentStorage persistentStorage; public HSGenericDataManager(HSPersistentStorage hSPersistentStorage) { this.persistentStorage = hSPersistentStorage; } public void saveGenericSdkData(String str) { if (Utils.isEmpty(str) || !Utils.isValidJsonString(str)) { return; } try { JSONObject jSONObject = new JSONObject(str); savePollingRoute(extractString("polling_route", jSONObject)); savePushTokenRoute(extractString("push_token_sync_route", jSONObject)); saveNetworkHeaders(extractJsonObject("network_headers", jSONObject)); saveNotificationContent(extractJsonObject("notification_content", jSONObject)); saveUserDataKeyMapping(extractJsonObject("user_data_key_mapping", jSONObject)); } catch (Exception e) { HSLogger.e("genricDataMngr", "Unable to parse the generic sdk data", e); } } public final void saveUserDataKeyMapping(JSONObject jSONObject) { if (jSONObject != null) { this.persistentStorage.storeUserDataKeyMapping(jSONObject.toString()); } } public final void saveNotificationContent(JSONObject jSONObject) { if (jSONObject != null) { this.persistentStorage.storeNotificationContent(jSONObject.toString()); } } public final void saveNetworkHeaders(JSONObject jSONObject) { if (jSONObject != null) { this.persistentStorage.storeNetworkHeaders(jSONObject.toString()); } } public final void savePushTokenRoute(String str) { if (Utils.isNotEmpty(str)) { this.persistentStorage.storePushTokenRoute(str); } } public final void savePollingRoute(String str) { if (Utils.isNotEmpty(str)) { this.persistentStorage.storePollingRoute(str); } } public final String extractString(String str, JSONObject jSONObject) { try { return jSONObject.getString(str); } catch (JSONException e) { HSLogger.e("genricDataMngr", "Error in reading the json value for key " + str, e); return ""; } } public final JSONObject extractJsonObject(String str, JSONObject jSONObject) { try { return jSONObject.getJSONObject(str); } catch (JSONException e) { HSLogger.e("genricDataMngr", "Error in reading the json value for key " + str, e); return null; } } public Map getNetworkHeaders() { return Utils.jsonStringToStringMap(this.persistentStorage.getNetworkHeaders()); } public String getPollingRoute() { return this.persistentStorage.getPollingRoute(); } public String getPushTokenSyncRoute() { return this.persistentStorage.getPushTokenSyncRoute(); } public Map getUserDataKeyMapping() { return Utils.jsonStringToStringMap(this.persistentStorage.getUserDataKeyMapping()); } public String getNotificationStringForCount(int i) { if (i > 1) { return getNotificationString(i, "plural_message"); } return getNotificationString(i, "single_message"); } public final String getNotificationString(int i, String str) { JSONObject notificationContent = getNotificationContent(); if (notificationContent == null) { return "You have new messages"; } try { return notificationContent.getString(str).replace(notificationContent.getString("placeholder"), String.valueOf(i)); } catch (Exception e) { HSLogger.e("genricDataMngr", "Error in constructing unread count string", e); return "You have new messages"; } } public final JSONObject getNotificationContent() { String notificationContent = this.persistentStorage.getNotificationContent(); if (Utils.isEmpty(notificationContent)) { return null; } try { return new JSONObject(notificationContent); } catch (Exception e) { HSLogger.e("genricDataMngr", "Error in reading unread count notification content", e); return null; } } }