also save form elements in disco storage

This commit is contained in:
Daniel Gultsch 2016-05-19 10:41:56 +02:00
parent 627bf18f8c
commit 0eb8d4226e
4 changed files with 64 additions and 6 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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;

View File

@ -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");