Commit feb65d69 authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix code style

parent ffd30513
...@@ -14,7 +14,7 @@ public class LaunchUtil { ...@@ -14,7 +14,7 @@ public class LaunchUtil {
public static void showServerConfigActivity(Context context, String serverCondigId) { public static void showServerConfigActivity(Context context, String serverCondigId) {
Intent intent = new Intent(context, ServerConfigActivity.class); Intent intent = new Intent(context, ServerConfigActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("id", serverCondigId); intent.putExtra("serverConfigId", serverCondigId);
context.startActivity(intent); context.startActivity(intent);
} }
} }
...@@ -11,7 +11,7 @@ import chat.rocket.android.fragment.chatroom.HomeFragment; ...@@ -11,7 +11,7 @@ import chat.rocket.android.fragment.chatroom.HomeFragment;
import chat.rocket.android.fragment.chatroom.RoomFragment; import chat.rocket.android.fragment.chatroom.RoomFragment;
import chat.rocket.android.helper.Avatar; import chat.rocket.android.helper.Avatar;
import chat.rocket.android.layouthelper.chatroom.RoomListManager; import chat.rocket.android.layouthelper.chatroom.RoomListManager;
import chat.rocket.android.model.RoomSubscription; import chat.rocket.android.model.ddp.RoomSubscription;
import com.jakewharton.rxbinding.view.RxView; import com.jakewharton.rxbinding.view.RxView;
import com.jakewharton.rxbinding.widget.RxCompoundButton; import com.jakewharton.rxbinding.widget.RxCompoundButton;
import io.realm.Realm; import io.realm.Realm;
......
...@@ -27,7 +27,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity { ...@@ -27,7 +27,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
private RealmObjectObserver<ServerConfig> serverConfigObserver = private RealmObjectObserver<ServerConfig> serverConfigObserver =
new RealmObjectObserver<ServerConfig>() { new RealmObjectObserver<ServerConfig>() {
@Override protected RealmQuery<ServerConfig> query(Realm realm) { @Override protected RealmQuery<ServerConfig> query(Realm realm) {
return realm.where(ServerConfig.class).equalTo("id", serverConfigId); return realm.where(ServerConfig.class).equalTo("serverConfigId", serverConfigId);
} }
@Override protected void onChange(ServerConfig config) { @Override protected void onChange(ServerConfig config) {
...@@ -69,7 +69,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity { ...@@ -69,7 +69,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
} }
private static boolean launchFor(Context context, ServerConfig config) { private static boolean launchFor(Context context, ServerConfig config) {
LaunchUtil.showServerConfigActivity(context, config.getId()); LaunchUtil.showServerConfigActivity(context, config.getServerConfigId());
return true; return true;
} }
...@@ -86,7 +86,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity { ...@@ -86,7 +86,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
return; return;
} }
serverConfigId = intent.getStringExtra("id"); serverConfigId = intent.getStringExtra("serverConfigId");
if (TextUtils.isEmpty(serverConfigId)) { if (TextUtils.isEmpty(serverConfigId)) {
finish(); finish();
return; return;
...@@ -154,7 +154,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity { ...@@ -154,7 +154,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
if (args == null) { if (args == null) {
args = new Bundle(); args = new Bundle();
} }
args.putString("id", serverConfigId); args.putString("serverConfigId", serverConfigId);
fragment.setArguments(args); fragment.setArguments(args);
} }
......
...@@ -3,7 +3,7 @@ package chat.rocket.android.fragment.chatroom; ...@@ -3,7 +3,7 @@ package chat.rocket.android.fragment.chatroom;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import chat.rocket.android.R; import chat.rocket.android.R;
import chat.rocket.android.model.RoomSubscription; import chat.rocket.android.model.ddp.RoomSubscription;
import io.realm.Realm; import io.realm.Realm;
import io.realm.RealmQuery; import io.realm.RealmQuery;
import jp.co.crowdworks.realm_java_helpers.RealmObjectObserver; import jp.co.crowdworks.realm_java_helpers.RealmObjectObserver;
......
...@@ -9,7 +9,7 @@ import android.webkit.WebView; ...@@ -9,7 +9,7 @@ import android.webkit.WebView;
import chat.rocket.android.fragment.AbstractWebViewFragment; import chat.rocket.android.fragment.AbstractWebViewFragment;
import chat.rocket.android.helper.LogcatIfError; import chat.rocket.android.helper.LogcatIfError;
import chat.rocket.android.helper.MethodCallHelper; import chat.rocket.android.helper.MethodCallHelper;
import chat.rocket.android.model.MeteorLoginServiceConfiguration; import chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration;
import chat.rocket.android.model.ServerConfig; import chat.rocket.android.model.ServerConfig;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import jp.co.crowdworks.realm_java_helpers.RealmHelper; import jp.co.crowdworks.realm_java_helpers.RealmHelper;
...@@ -51,7 +51,7 @@ public class GitHubOAuthFragment extends AbstractWebViewFragment { ...@@ -51,7 +51,7 @@ public class GitHubOAuthFragment extends AbstractWebViewFragment {
serverConfigId = args.getString("serverConfigId"); serverConfigId = args.getString("serverConfigId");
ServerConfig serverConfig = RealmHelper.executeTransactionForRead(realm -> ServerConfig serverConfig = RealmHelper.executeTransactionForRead(realm ->
realm.where(ServerConfig.class).equalTo("id", serverConfigId).findFirst()); realm.where(ServerConfig.class).equalTo("serverConfigId", serverConfigId).findFirst());
MeteorLoginServiceConfiguration oauthConfig = RealmHelper.executeTransactionForRead(realm -> MeteorLoginServiceConfiguration oauthConfig = RealmHelper.executeTransactionForRead(realm ->
realm.where(MeteorLoginServiceConfiguration.class) realm.where(MeteorLoginServiceConfiguration.class)
.equalTo("service", "github") .equalTo("service", "github")
......
...@@ -21,7 +21,7 @@ abstract class AbstractServerConfigFragment extends AbstractFragment ...@@ -21,7 +21,7 @@ abstract class AbstractServerConfigFragment extends AbstractFragment
return; return;
} }
serverConfigId = args.getString("id"); serverConfigId = args.getString("serverConfigId");
if (TextUtils.isEmpty(serverConfigId)) { if (TextUtils.isEmpty(serverConfigId)) {
finish(); finish();
return; return;
......
...@@ -25,7 +25,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment { ...@@ -25,7 +25,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
}; };
RealmObjectObserver<ServerConfig> serverConfigObserver = new RealmObjectObserver<ServerConfig>() { RealmObjectObserver<ServerConfig> serverConfigObserver = new RealmObjectObserver<ServerConfig>() {
@Override protected RealmQuery<ServerConfig> query(Realm realm) { @Override protected RealmQuery<ServerConfig> query(Realm realm) {
return realm.where(ServerConfig.class).equalTo("id", serverConfigId); return realm.where(ServerConfig.class).equalTo("serverConfigId", serverConfigId);
} }
@Override protected void onChange(ServerConfig config) { @Override protected void onChange(ServerConfig config) {
...@@ -54,7 +54,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment { ...@@ -54,7 +54,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
RealmHelperBolts.executeTransaction( RealmHelperBolts.executeTransaction(
realm -> realm.createOrUpdateObjectFromJson(ServerConfig.class, realm -> realm.createOrUpdateObjectFromJson(ServerConfig.class,
new JSONObject().put("id", serverConfigId) new JSONObject().put("serverConfigId", serverConfigId)
.put("hostname", hostname) .put("hostname", hostname)
.put("connectionError", JSONObject.NULL) .put("connectionError", JSONObject.NULL)
.put("session", JSONObject.NULL))).continueWith(new LogcatIfError()); .put("session", JSONObject.NULL))).continueWith(new LogcatIfError());
...@@ -91,7 +91,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment { ...@@ -91,7 +91,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
private void clearConnectionErrorAndHostname() { private void clearConnectionErrorAndHostname() {
RealmHelperBolts.executeTransaction( RealmHelperBolts.executeTransaction(
realm -> realm.createOrUpdateObjectFromJson(ServerConfig.class, realm -> realm.createOrUpdateObjectFromJson(ServerConfig.class,
new JSONObject().put("id", serverConfigId) new JSONObject().put("serverConfigId", serverConfigId)
.put("hostname", JSONObject.NULL) .put("hostname", JSONObject.NULL)
.put("connectionError", JSONObject.NULL))).continueWith(new LogcatIfError()); .put("connectionError", JSONObject.NULL))).continueWith(new LogcatIfError());
} }
......
...@@ -7,7 +7,7 @@ import chat.rocket.android.R; ...@@ -7,7 +7,7 @@ import chat.rocket.android.R;
import chat.rocket.android.fragment.oauth.GitHubOAuthFragment; import chat.rocket.android.fragment.oauth.GitHubOAuthFragment;
import chat.rocket.android.helper.MethodCallHelper; import chat.rocket.android.helper.MethodCallHelper;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.model.MeteorLoginServiceConfiguration; import chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration;
import io.realm.Realm; import io.realm.Realm;
import io.realm.RealmResults; import io.realm.RealmResults;
import java.util.List; import java.util.List;
......
...@@ -4,7 +4,7 @@ import android.util.Patterns; ...@@ -4,7 +4,7 @@ import android.util.Patterns;
import bolts.Continuation; import bolts.Continuation;
import bolts.Task; import bolts.Task;
import chat.rocket.android.model.MethodCall; import chat.rocket.android.model.MethodCall;
import chat.rocket.android.model.RoomSubscription; import chat.rocket.android.model.ddp.RoomSubscription;
import chat.rocket.android.model.ServerConfig; import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.ws.RocketChatWebSocketAPI; import chat.rocket.android.ws.RocketChatWebSocketAPI;
import java.util.UUID; import java.util.UUID;
...@@ -96,7 +96,7 @@ public class MethodCallHelper { ...@@ -96,7 +96,7 @@ public class MethodCallHelper {
private Task<Void> saveToken(Task<String> task) { private Task<Void> saveToken(Task<String> task) {
return RealmHelperBolts.executeTransaction(realm -> return RealmHelperBolts.executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject() realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject()
.put("id", serverConfigId) .put("serverConfigId", serverConfigId)
.put("token", task.getResult()) .put("token", task.getResult())
.put("tokenVerified", true))); .put("tokenVerified", true)));
} }
......
...@@ -3,7 +3,7 @@ package chat.rocket.android.layouthelper.chatroom; ...@@ -3,7 +3,7 @@ package chat.rocket.android.layouthelper.chatroom;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.model.RoomSubscription; import chat.rocket.android.model.ddp.RoomSubscription;
import chat.rocket.android.widget.internal.RoomListItemView; import chat.rocket.android.widget.internal.RoomListItemView;
import java.util.List; import java.util.List;
......
...@@ -14,22 +14,21 @@ import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts; ...@@ -14,22 +14,21 @@ import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@SuppressWarnings("PMD.ShortVariable")
public class MethodCall extends RealmObject { public class MethodCall extends RealmObject {
@PrimaryKey private String id; @PrimaryKey private String methodCallId;
private String serverConfigId; //not ServerConfig!(not to be notified the change of ServerConfig) private String serverConfigId; //not ServerConfig!(not to be notified the change of ServerConfig)
private int syncstate; private int syncstate;
private String name; private String name;
private String paramsJson; private String paramsJson;
private String resultJson; private String resultJson;
public String getId() { public String getMethodCallId() {
return id; return methodCallId;
} }
public void setId(String id) { public void setMethodCallId(String methodCallId) {
this.id = id; this.methodCallId = methodCallId;
} }
public String getServerConfigId() { public String getServerConfigId() {
...@@ -82,12 +81,15 @@ public class MethodCall extends RealmObject { ...@@ -82,12 +81,15 @@ public class MethodCall extends RealmObject {
} }
} }
/**
* insert a new record to request a method call.
*/
public static Task<JSONObject> execute(String serverConfigId, String name, String paramsJson) { public static Task<JSONObject> execute(String serverConfigId, String name, String paramsJson) {
final String newId = UUID.randomUUID().toString(); final String newId = UUID.randomUUID().toString();
TaskCompletionSource<JSONObject> task = new TaskCompletionSource<>(); TaskCompletionSource<JSONObject> task = new TaskCompletionSource<>();
RealmHelperBolts.executeTransaction(realm -> { RealmHelperBolts.executeTransaction(realm -> {
MethodCall call = realm.createObjectFromJson(MethodCall.class, new JSONObject() MethodCall call = realm.createObjectFromJson(MethodCall.class, new JSONObject()
.put("id", newId) .put("methodCallId", newId)
.put("serverConfigId", serverConfigId) .put("serverConfigId", serverConfigId)
.put("syncstate", SyncState.NOT_SYNCED) .put("syncstate", SyncState.NOT_SYNCED)
.put("name", name)); .put("name", name));
...@@ -99,7 +101,7 @@ public class MethodCall extends RealmObject { ...@@ -99,7 +101,7 @@ public class MethodCall extends RealmObject {
} else { } else {
new RealmObjectObserver<MethodCall>() { new RealmObjectObserver<MethodCall>() {
@Override protected RealmQuery<MethodCall> query(Realm realm) { @Override protected RealmQuery<MethodCall> query(Realm realm) {
return realm.where(MethodCall.class).equalTo("id", newId); return realm.where(MethodCall.class).equalTo("methodCallId", newId);
} }
@Override protected void onChange(MethodCall methodCall) { @Override protected void onChange(MethodCall methodCall) {
...@@ -111,10 +113,10 @@ public class MethodCall extends RealmObject { ...@@ -111,10 +113,10 @@ public class MethodCall extends RealmObject {
} catch (JSONException exception) { } catch (JSONException exception) {
task.setError(new Error(exception)); task.setError(new Error(exception));
} }
exit(methodCall.getId()); exit(methodCall.getMethodCallId());
} else if (syncstate == SyncState.FAILED) { } else if (syncstate == SyncState.FAILED) {
task.setError(new Error(methodCall.getResultJson())); task.setError(new Error(methodCall.getResultJson()));
exit(methodCall.getId()); exit(methodCall.getMethodCallId());
} }
} }
...@@ -129,8 +131,14 @@ public class MethodCall extends RealmObject { ...@@ -129,8 +131,14 @@ public class MethodCall extends RealmObject {
return task.getTask(); return task.getTask();
} }
public static final Task<Void> remove(String id) { /**
* remove the request.
*/
public static final Task<Void> remove(String methodCallId) {
return RealmHelperBolts.executeTransaction(realm -> return RealmHelperBolts.executeTransaction(realm ->
realm.where(MethodCall.class).equalTo("id", id).findAll().deleteAllFromRealm()); realm.where(MethodCall.class)
.equalTo("methodCallId", methodCallId)
.findAll()
.deleteAllFromRealm());
} }
} }
...@@ -15,9 +15,8 @@ import org.json.JSONObject; ...@@ -15,9 +15,8 @@ import org.json.JSONObject;
/** /**
* Server configuration. * Server configuration.
*/ */
@SuppressWarnings("PMD.ShortVariable")
public class ServerConfig extends RealmObject { public class ServerConfig extends RealmObject {
@PrimaryKey private String id; @PrimaryKey private String serverConfigId;
private String hostname; private String hostname;
private String connectionError; private String connectionError;
private String session; private String session;
...@@ -28,6 +27,9 @@ public class ServerConfig extends RealmObject { ...@@ -28,6 +27,9 @@ public class ServerConfig extends RealmObject {
return realm.where(ServerConfig.class).equalTo("tokenVerified", false); return realm.where(ServerConfig.class).equalTo("tokenVerified", false);
} }
/**
* Check if connection login required exists.
*/
public static boolean hasLoginRequiredConnection() { public static boolean hasLoginRequiredConnection() {
ServerConfig config = ServerConfig config =
RealmHelper.executeTransactionForRead(realm -> RealmHelper.executeTransactionForRead(realm ->
...@@ -36,6 +38,9 @@ public class ServerConfig extends RealmObject { ...@@ -36,6 +38,9 @@ public class ServerConfig extends RealmObject {
return config != null; return config != null;
} }
/**
* Request token refresh.
*/
public static Task<Void> forceInvalidateToken() { public static Task<Void> forceInvalidateToken() {
return RealmHelperBolts.executeTransaction(realm -> { return RealmHelperBolts.executeTransaction(realm -> {
RealmResults<ServerConfig> targetConfigs = realm.where(ServerConfig.class) RealmResults<ServerConfig> targetConfigs = realm.where(ServerConfig.class)
...@@ -49,21 +54,24 @@ public class ServerConfig extends RealmObject { ...@@ -49,21 +54,24 @@ public class ServerConfig extends RealmObject {
}); });
} }
@DebugLog public static void logConnectionError(String id, Exception exception) { /**
* Log the server connection is lost due to soem exception.
*/
@DebugLog public static void logConnectionError(String serverConfigId, Exception exception) {
RealmHelperBolts.executeTransaction( RealmHelperBolts.executeTransaction(
realm -> realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject() realm -> realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject()
.put("id", id) .put("serverConfigId", serverConfigId)
.put("connectionError", exception.getMessage()) .put("connectionError", exception.getMessage())
.put("session", JSONObject.NULL))) .put("session", JSONObject.NULL)))
.continueWith(new LogcatIfError()); .continueWith(new LogcatIfError());
} }
public String getId() { public String getServerConfigId() {
return id; return serverConfigId;
} }
public void setId(String id) { public void setServerConfigId(String serverConfigId) {
this.id = id; this.serverConfigId = serverConfigId;
} }
public String getHostname() { public String getHostname() {
......
package chat.rocket.android.model; package chat.rocket.android.model.ddp;
import io.realm.RealmObject; import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey; import io.realm.annotations.PrimaryKey;
/** /**
* Login-User's email * Login-User's email.
*/ */
public class Email extends RealmObject { public class Email extends RealmObject {
@PrimaryKey private String address; @PrimaryKey private String address;
......
package chat.rocket.android.model; package chat.rocket.android.model.ddp;
import io.realm.RealmObject; import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey; import io.realm.annotations.PrimaryKey;
......
package chat.rocket.android.model; package chat.rocket.android.model.ddp;
import io.realm.RealmObject; import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey; import io.realm.annotations.PrimaryKey;
......
package chat.rocket.android.model; package chat.rocket.android.model.ddp;
import io.realm.RealmList; import io.realm.RealmList;
import io.realm.RealmObject; import io.realm.RealmObject;
......
...@@ -88,7 +88,7 @@ public class RocketChatService extends Service { ...@@ -88,7 +88,7 @@ public class RocketChatService extends Service {
String serverConfigId = entry.getKey(); String serverConfigId = entry.getKey();
boolean found = false; boolean found = false;
for (ServerConfig config : configList) { for (ServerConfig config : configList) {
if (serverConfigId.equals(config.getId())) { if (serverConfigId.equals(config.getServerConfigId())) {
found = true; found = true;
break; break;
} }
...@@ -111,7 +111,7 @@ public class RocketChatService extends Service { ...@@ -111,7 +111,7 @@ public class RocketChatService extends Service {
} }
private Task<RocketChatWebSocketThread> findOrCreateWebSocketThread(final ServerConfig config) { private Task<RocketChatWebSocketThread> findOrCreateWebSocketThread(final ServerConfig config) {
final String serverConfigId = config.getId(); final String serverConfigId = config.getServerConfigId();
if (webSocketThreads.containsKey(serverConfigId)) { if (webSocketThreads.containsKey(serverConfigId)) {
return Task.forResult(webSocketThreads.get(serverConfigId)); return Task.forResult(webSocketThreads.get(serverConfigId));
} else { } else {
......
...@@ -9,8 +9,8 @@ import bolts.TaskCompletionSource; ...@@ -9,8 +9,8 @@ import bolts.TaskCompletionSource;
import chat.rocket.android.helper.LogcatIfError; import chat.rocket.android.helper.LogcatIfError;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.model.ServerConfig; import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.service.ddp_subscriber.ActiveUsersSubscriber; import chat.rocket.android.service.ddp.ActiveUsersSubscriber;
import chat.rocket.android.service.ddp_subscriber.LoginServiceConfigurationSubscriber; import chat.rocket.android.service.ddp.LoginServiceConfigurationSubscriber;
import chat.rocket.android.service.observer.MethodCallObserver; import chat.rocket.android.service.observer.MethodCallObserver;
import chat.rocket.android.service.observer.SessionObserver; import chat.rocket.android.service.observer.SessionObserver;
import chat.rocket.android.service.observer.TokenLoginObserver; import chat.rocket.android.service.observer.TokenLoginObserver;
...@@ -55,7 +55,7 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -55,7 +55,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
@DebugLog public static Task<RocketChatWebSocketThread> getStarted(Context appContext, @DebugLog public static Task<RocketChatWebSocketThread> getStarted(Context appContext,
ServerConfig config) { ServerConfig config) {
TaskCompletionSource<RocketChatWebSocketThread> task = new TaskCompletionSource<>(); TaskCompletionSource<RocketChatWebSocketThread> task = new TaskCompletionSource<>();
new RocketChatWebSocketThread(appContext, config.getId()) { new RocketChatWebSocketThread(appContext, config.getServerConfigId()) {
@Override protected void onLooperPrepared() { @Override protected void onLooperPrepared() {
try { try {
super.onLooperPrepared(); super.onLooperPrepared();
...@@ -136,14 +136,14 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -136,14 +136,14 @@ public class RocketChatWebSocketThread extends HandlerThread {
socketExists = true; socketExists = true;
final ServerConfig config = RealmHelper.executeTransactionForRead(realm -> final ServerConfig config = RealmHelper.executeTransactionForRead(realm ->
realm.where(ServerConfig.class).equalTo("id", serverConfigId).findFirst()); realm.where(ServerConfig.class).equalTo("serverConfigId", serverConfigId).findFirst());
prepareWebSocket(config); prepareWebSocket(config);
return webSocketAPI.connect(config.getSession()).onSuccessTask(task -> { return webSocketAPI.connect(config.getSession()).onSuccessTask(task -> {
final String session = task.getResult().session; final String session = task.getResult().session;
RealmHelperBolts.executeTransaction(realm -> RealmHelperBolts.executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject() realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject()
.put("id", serverConfigId) .put("serverConfigId", serverConfigId)
.put("session", session)) .put("session", session))
).continueWith(new LogcatIfError()); ).continueWith(new LogcatIfError());
return task; return task;
......
package chat.rocket.android.service.ddp_subscriber; package chat.rocket.android.service.ddp;
import android.content.Context; import android.content.Context;
import android.text.TextUtils; import android.text.TextUtils;
......
package chat.rocket.android.service.ddp_subscriber; package chat.rocket.android.service.ddp;
import android.content.Context; import android.content.Context;
import chat.rocket.android.model.User; import chat.rocket.android.model.ddp.User;
import chat.rocket.android.ws.RocketChatWebSocketAPI; import chat.rocket.android.ws.RocketChatWebSocketAPI;
import io.realm.RealmObject; import io.realm.RealmObject;
/** /**
* "activeUsers" subscriber.
*/ */
public class ActiveUsersSubscriber extends AbstractDDPDocEventSubscriber { public class ActiveUsersSubscriber extends AbstractDDPDocEventSubscriber {
public ActiveUsersSubscriber(Context context, String serverConfigId, public ActiveUsersSubscriber(Context context, String serverConfigId,
......
package chat.rocket.android.service.ddp_subscriber; package chat.rocket.android.service.ddp;
import android.content.Context; import android.content.Context;
import chat.rocket.android.model.MeteorLoginServiceConfiguration; import chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration;
import chat.rocket.android.ws.RocketChatWebSocketAPI; import chat.rocket.android.ws.RocketChatWebSocketAPI;
import io.realm.RealmObject; import io.realm.RealmObject;
......
...@@ -58,19 +58,19 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> { ...@@ -58,19 +58,19 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
} }
MethodCall call = list.get(0); MethodCall call = list.get(0);
final String methodCallId = call.getId(); final String methodCallId = call.getMethodCallId();
final String methodName = call.getName(); final String methodName = call.getName();
final String params = call.getParamsJson(); final String params = call.getParamsJson();
RealmHelperBolts.executeTransaction(realm -> RealmHelperBolts.executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(MethodCall.class, new JSONObject() realm.createOrUpdateObjectFromJson(MethodCall.class, new JSONObject()
.put("id", methodCallId) .put("methodCallId", methodCallId)
.put("syncstate", SyncState.SYNCING)) .put("syncstate", SyncState.SYNCING))
).onSuccessTask(task -> ).onSuccessTask(task ->
webSocketAPI.rpc(methodCallId, methodName, params).onSuccessTask(_task -> webSocketAPI.rpc(methodCallId, methodName, params).onSuccessTask(_task ->
RealmHelperBolts.executeTransaction(realm -> { RealmHelperBolts.executeTransaction(realm -> {
JSONObject result = _task.getResult().result; JSONObject result = _task.getResult().result;
return realm.createOrUpdateObjectFromJson(MethodCall.class, new JSONObject() return realm.createOrUpdateObjectFromJson(MethodCall.class, new JSONObject()
.put("id", methodCallId) .put("methodCallId", methodCallId)
.put("syncstate", SyncState.SYNCED) .put("syncstate", SyncState.SYNCED)
.put("resultJson", result == null ? null : result.toString())); .put("resultJson", result == null ? null : result.toString()));
}) })
...@@ -83,7 +83,7 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> { ...@@ -83,7 +83,7 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
? ((DDPClientCallback.RPC.Error) exception).error.toString() ? ((DDPClientCallback.RPC.Error) exception).error.toString()
: exception.getMessage(); : exception.getMessage();
realm.createOrUpdateObjectFromJson(MethodCall.class, new JSONObject() realm.createOrUpdateObjectFromJson(MethodCall.class, new JSONObject()
.put("id", methodCallId) .put("methodCallId", methodCallId)
.put("syncstate", SyncState.FAILED) .put("syncstate", SyncState.FAILED)
.put("resultJson", errMessage)); .put("resultJson", errMessage));
return null; return null;
......
...@@ -3,7 +3,7 @@ package chat.rocket.android.service.observer; ...@@ -3,7 +3,7 @@ package chat.rocket.android.service.observer;
import android.content.Context; import android.content.Context;
import chat.rocket.android.helper.LogcatIfError; import chat.rocket.android.helper.LogcatIfError;
import chat.rocket.android.helper.MethodCallHelper; import chat.rocket.android.helper.MethodCallHelper;
import chat.rocket.android.model.RoomSubscription; import chat.rocket.android.model.ddp.RoomSubscription;
import chat.rocket.android.model.ServerConfig; import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.ws.RocketChatWebSocketAPI; import chat.rocket.android.ws.RocketChatWebSocketAPI;
import hugo.weaving.DebugLog; import hugo.weaving.DebugLog;
...@@ -25,7 +25,7 @@ public class SessionObserver extends AbstractModelObserver<ServerConfig> { ...@@ -25,7 +25,7 @@ public class SessionObserver extends AbstractModelObserver<ServerConfig> {
@Override protected RealmResults<ServerConfig> queryItems(Realm realm) { @Override protected RealmResults<ServerConfig> queryItems(Realm realm) {
return realm.where(ServerConfig.class) return realm.where(ServerConfig.class)
.equalTo("id", serverConfigId) .equalTo("serverConfigId", serverConfigId)
.isNotNull("hostname") .isNotNull("hostname")
.isNull("connectionError") .isNull("connectionError")
.isNotNull("session") .isNotNull("session")
......
...@@ -6,5 +6,5 @@ ...@@ -6,5 +6,5 @@
<!-- suppress some checks for classes extending RealmObject --> <!-- suppress some checks for classes extending RealmObject -->
<suppress <suppress
checks="JavadocMethod|MemberName|ParameterName" checks="JavadocMethod|MemberName|ParameterName"
files="chat[\\/]rocket[\\/]android[\\/]model"/> files="chat[\\/]rocket[\\/]android[\\/]model[\\/]ddp"/>
</suppressions> </suppressions>
\ No newline at end of file
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