Skip to content

Commit

Permalink
merge the entities JsonNode instead of replacing it when processing e…
Browse files Browse the repository at this point in the history
…dits
  • Loading branch information
c99koder committed Jun 4, 2019
1 parent 0ffe7ca commit 031083f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
8 changes: 6 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions irccloud-android.iml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/legacy_multidex_aapt_derived_proguard_rules" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint_jar" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint_publish_jar" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifest_merge_blame_file" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_java_res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_jni_libs" />
Expand Down
28 changes: 27 additions & 1 deletion src/com/irccloud/android/NetworkConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -3026,6 +3026,28 @@ public void parse(IRCCloudJSONObject object) throws JSONException {
});
}};

//https://stackoverflow.com/a/11459962
private static JsonNode mergeJsonNode(JsonNode mainNode, JsonNode updateNode) {
Iterator<String> fieldNames = updateNode.fieldNames();
while (fieldNames.hasNext()) {
String fieldName = fieldNames.next();
JsonNode jsonNode = mainNode.get(fieldName);
// if field exists and is an embedded object
if (jsonNode != null && jsonNode.isObject()) {
mergeJsonNode(jsonNode, updateNode.get(fieldName));
}
else {
if (mainNode instanceof ObjectNode) {
// Overwrite field
JsonNode value = updateNode.get(fieldName);
((ObjectNode) mainNode).put(fieldName, value);
}
}
}

return mainNode;
}

private synchronized void process_pending_edits() {
ArrayList<IRCCloudJSONObject> edits = pendingEdits;
pendingEdits = new ArrayList<>();
Expand Down Expand Up @@ -3067,7 +3089,11 @@ private synchronized void process_pending_edits() {
e.msg = "&nbsp;" + e.msg.substring(1);
e.edited = true;
}
e.entities = entities;
if(e.entities != null) {
mergeJsonNode(e.entities, entities);
} else {
e.entities = entities;
}
e.lastEditEID = o.eid();
e.formatted = null;
e.html = null;
Expand Down

0 comments on commit 031083f

Please sign in to comment.