Commit ffaa0baf authored by Tiago Cunha's avatar Tiago Cunha Committed by GitHub

Merge pull request #227 from RocketChat/fix/server-registering

Fixes server incorret register
parents cff73c9b 7f52279f
......@@ -74,8 +74,7 @@ import rx.subjects.PublishSubject;
@Override
public void addOrUpdateServer(String hostname, @Nullable String name, boolean insecure) {
RealmBasedServerInfo.addOrUpdate(hostname, name);
RealmBasedServerInfo.setInsecure(hostname, insecure);
RealmBasedServerInfo.addOrUpdate(hostname, name, insecure);
if (!serverConnectivityList.containsKey(hostname)) {
serverConnectivityList.put(hostname, ServerConnectivity.STATE_DISCONNECTED);
}
......
......@@ -44,11 +44,12 @@ public class RealmBasedServerInfo extends RealmObject {
return RealmStore.getOrCreateForServerScope(DB_NAME);
}
public static void addOrUpdate(String hostname, String name) {
public static void addOrUpdate(String hostname, String name, boolean insecure) {
getRealm().executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(RealmBasedServerInfo.class, new JSONObject()
.put(ColumnName.HOSTNAME, hostname)
.put(ColumnName.NAME, TextUtils.isEmpty(name) ? JSONObject.NULL : name)));
.put(ColumnName.NAME, TextUtils.isEmpty(name) ? JSONObject.NULL : name)
.put(ColumnName.INSECURE, insecure)));
}
public static void remove(String hostname) {
......@@ -80,19 +81,6 @@ public class RealmBasedServerInfo extends RealmObject {
return impl == null ? null : impl.getServerInfo();
}
public static void setInsecure(String hostname, boolean insecure) {
RealmBasedServerInfo impl = getRealm().executeTransactionForRead(realm ->
realm.where(RealmBasedServerInfo.class).equalTo(ColumnName.HOSTNAME, hostname).findFirst());
if (impl != null) {
impl.insecure = insecure;
getRealm().executeTransaction(realm -> {
realm.copyToRealmOrUpdate(impl);
return null;
});
}
}
public static List<ServerInfo> getServerInfoList() {
List<RealmBasedServerInfo> results = getRealm().executeTransactionForReadResults(realm ->
realm.where(RealmBasedServerInfo.class).findAll());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment