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

Merge pull request #196 from RocketChat/fix/firebase-crash-reports-20170207

Fix/firebase crash reports 20170207
parents abcedb84 e9f583aa
......@@ -7,9 +7,10 @@ import okhttp3.Request;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import rx.Emitter;
import rx.Observable;
import rx.Subscriber;
import rx.exceptions.OnErrorNotImplementedException;
import rx.functions.Action1;
import rx.observables.ConnectableObservable;
public class RxWebSocket {
......@@ -23,38 +24,41 @@ public class RxWebSocket {
public ConnectableObservable<RxWebSocketCallback.Base> connect(String url) {
final Request request = new Request.Builder().url(url).build();
return Observable.create(new Observable.OnSubscribe<RxWebSocketCallback.Base>() {
@Override
public void call(Subscriber<? super RxWebSocketCallback.Base> subscriber) {
httpClient.newWebSocket(request, new WebSocketListener() {
return Observable.fromEmitter(
new Action1<Emitter<RxWebSocketCallback.Base>>() {
@Override
public void onOpen(WebSocket webSocket, Response response) {
RxWebSocket.this.webSocket = webSocket;
subscriber.onNext(new RxWebSocketCallback.Open(RxWebSocket.this.webSocket, response));
}
public void call(Emitter<RxWebSocketCallback.Base> emitter) {
httpClient.newWebSocket(request, new WebSocketListener() {
@Override
public void onOpen(WebSocket webSocket, Response response) {
RxWebSocket.this.webSocket = webSocket;
emitter.onNext(new RxWebSocketCallback.Open(RxWebSocket.this.webSocket, response));
}
@Override
public void onFailure(WebSocket webSocket, Throwable err, Response response) {
try {
subscriber.onError(new RxWebSocketCallback.Failure(webSocket, err, response));
} catch (OnErrorNotImplementedException ex) {
RCLog.w(ex, "OnErrorNotImplementedException ignored");
}
}
@Override
public void onFailure(WebSocket webSocket, Throwable err, Response response) {
try {
emitter.onError(new RxWebSocketCallback.Failure(webSocket, err, response));
} catch (OnErrorNotImplementedException ex) {
RCLog.w(ex, "OnErrorNotImplementedException ignored");
}
}
@Override
public void onMessage(WebSocket webSocket, String text) {
subscriber.onNext(new RxWebSocketCallback.Message(webSocket, text));
}
@Override
public void onMessage(WebSocket webSocket, String text) {
emitter.onNext(new RxWebSocketCallback.Message(webSocket, text));
}
@Override
public void onClosed(WebSocket webSocket, int code, String reason) {
subscriber.onNext(new RxWebSocketCallback.Close(webSocket, code, reason));
subscriber.onCompleted();
@Override
public void onClosed(WebSocket webSocket, int code, String reason) {
emitter.onNext(new RxWebSocketCallback.Close(webSocket, code, reason));
emitter.onCompleted();
}
});
}
});
}
}).publish();
},
Emitter.BackpressureMode.BUFFER
).publish();
}
public boolean sendText(String message) throws IOException {
......
......@@ -74,7 +74,12 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
recoverFromHostnameError(prefs);
}
} else {
if (!hostname.equals(newHostname) && assertServerRealmStoreExists(newHostname)) {
if (hostname.equals(newHostname)) {
// we are good
return;
}
if (assertServerRealmStoreExists(newHostname)) {
updateHostname(newHostname);
} else {
recoverFromHostnameError(prefs);
......
......@@ -33,12 +33,16 @@ public class DefaultCookieProvider implements CookieProvider {
return "";
}
final String userId = realmHelper.executeTransactionForRead(realm ->
User.queryCurrentUser(realm).findFirst()).getId();
final String token = realmHelper.executeTransactionForRead(realm ->
Session.queryDefaultSession(realm).findFirst()).getToken();
final User user = realmHelper.executeTransactionForRead(realm ->
User.queryCurrentUser(realm).findFirst());
final Session session = realmHelper.executeTransactionForRead(realm ->
Session.queryDefaultSession(realm).findFirst());
return "rc_uid=" + userId + ";rc_token=" + token;
if (user == null || session == null) {
return "";
}
return "rc_uid=" + user.getId() + ";rc_token=" + session.getToken();
}
private String getHostnameFromCache() {
......
......@@ -14,9 +14,8 @@ import com.trello.rxlifecycle.components.support.RxFragment;
public abstract class AbstractFragment extends RxFragment {
protected View rootView;
protected abstract
@LayoutRes
int getLayout();
protected abstract int getLayout();
protected abstract void onSetupView();
......
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