aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-05-19 10:41:56 +0200
committerDaniel Gultsch <daniel@gultsch.de>2016-05-19 10:41:56 +0200
commit0eb8d4226ea8639b6a1e9a568863146423d4f0f8 (patch)
treea322f300c40f9a5db09ce504d35bc034429afe5a /src/main/java
parent627bf18f8cfa72aee3f410f22245403ff6a98ed0 (diff)
also save form elements in disco storage
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java58
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java6
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java4
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/forms/Data.java2
4 files changed, 64 insertions, 6 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java
index 9accec95d..9ee1d180e 100644
--- a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java
+++ b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java
@@ -146,7 +146,7 @@ public class ServiceDiscoveryResult {
this.hash = hash;
this.ver = ver;
- JSONArray identities = o.optJSONArray("identites");
+ JSONArray identities = o.optJSONArray("identities");
if (identities != null) {
for (int i = 0; i < identities.length(); i++) {
this.identities.add(new Identity(identities.getJSONObject(i)));
@@ -158,6 +158,54 @@ public class ServiceDiscoveryResult {
this.features.add(features.getString(i));
}
}
+ JSONArray forms = o.optJSONArray("forms");
+ if (forms != null) {
+ for(int i = 0; i < forms.length(); i++) {
+ this.forms.add(createFormFromJSONObject(forms.getJSONObject(i)));
+ }
+ }
+ }
+
+ private static Data createFormFromJSONObject(JSONObject o) {
+ Data data = new Data();
+ JSONArray names = o.names();
+ for(int i = 0; i < names.length(); ++i) {
+ try {
+ String name = names.getString(i);
+ JSONArray jsonValues = o.getJSONArray(name);
+ ArrayList<String> values = new ArrayList<>(jsonValues.length());
+ for(int j = 0; j < jsonValues.length(); ++j) {
+ values.add(jsonValues.getString(j));
+ }
+ data.put(name, values);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return data;
+ }
+
+ private static JSONObject createJSONFromForm(Data data) {
+ JSONObject object = new JSONObject();
+ for(Field field : data.getFields()) {
+ try {
+ JSONArray jsonValues = new JSONArray();
+ for(String value : field.getValues()) {
+ jsonValues.put(value);
+ }
+ object.put(field.getFieldName(), jsonValues);
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+ try {
+ JSONArray jsonValues = new JSONArray();
+ jsonValues.put(data.getFormType());
+ object.put(Data.FORM_TYPE, jsonValues);
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ return object;
}
public String getVer() {
@@ -274,10 +322,16 @@ public class ServiceDiscoveryResult {
for(Identity id : this.getIdentities()) {
ids.put(id.toJSON());
}
- o.put("identites", ids);
+ o.put("identities", ids);
o.put("features", new JSONArray(this.getFeatures()));
+ JSONArray forms = new JSONArray();
+ for(Data data : this.forms) {
+ forms.put(createJSONFromForm(data));
+ }
+ o.put("forms", forms);
+
return o;
} catch(JSONException e) {
return null;
diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
index dde385bd9..f1155b07d 100644
--- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
@@ -52,7 +52,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static DatabaseBackend instance = null;
private static final String DATABASE_NAME = "history";
- private static final int DATABASE_VERSION = 26;
+ private static final int DATABASE_VERSION = 27;
private static String CREATE_CONTATCS_STATEMENT = "create table "
+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, "
@@ -402,6 +402,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
if (oldVersion < 26 && newVersion >= 26) {
db.execSQL(CREATE_PRESENCE_TEMPLATES_STATEMENT);
}
+
+ if (oldVersion < 27 && newVersion >= 27) {
+ db.execSQL("DELETE FROM "+ServiceDiscoveryResult.TABLENAME);
+ }
}
public static synchronized DatabaseBackend getInstance(Context context) {
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index e8a98cdaf..c3340486a 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -1768,7 +1768,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
- private boolean checkListeners() {
+ public boolean checkListeners() {
return (this.mOnAccountUpdate == null
&& this.mOnConversationUpdate == null
&& this.mOnRosterUpdate == null
@@ -3181,7 +3181,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
- private ServiceDiscoveryResult getCachedServiceDiscoveryResult(Pair<String,String> key) {
+ public ServiceDiscoveryResult getCachedServiceDiscoveryResult(Pair<String, String> key) {
ServiceDiscoveryResult result = discoCache.get(key);
if (result != null) {
return result;
diff --git a/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java b/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java
index 8dabcb5be..c81c5a1f3 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java
@@ -9,7 +9,7 @@ import eu.siacs.conversations.xml.Element;
public class Data extends Element {
- private static final String FORM_TYPE = "FORM_TYPE";
+ public static final String FORM_TYPE = "FORM_TYPE";
public Data() {
super("x");