Commit 260cb6c0 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Removed repeated subscriptions to the same room when registering observers and...

Removed repeated subscriptions to the same room when registering observers and unnecessary refresh calls to the RoomFragment to update its UI
parent 96385eb0
...@@ -34,7 +34,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -34,7 +34,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
private StatusTicker statusTicker; private StatusTicker statusTicker;
private MainContract.Presenter presenter; private MainContract.Presenter presenter;
private RoomFragment roomFragment;
@Override @Override
protected int getLayoutContainerForFragment() { protected int getLayoutContainerForFragment() {
...@@ -180,8 +179,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -180,8 +179,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
@Override @Override
public void showRoom(String hostname, String roomId) { public void showRoom(String hostname, String roomId) {
roomFragment = RoomFragment.create(hostname, roomId); showFragment(RoomFragment.create(hostname, roomId));
showFragment(roomFragment);
closeSidebarIfNeeded(); closeSidebarIfNeeded();
KeyboardHelper.hideSoftKeyboard(this); KeyboardHelper.hideSoftKeyboard(this);
} }
...@@ -224,9 +222,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -224,9 +222,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
@Override @Override
public void showConnectionOk() { public void showConnectionOk() {
statusTicker.updateStatus(StatusTicker.STATUS_DISMISS, null); statusTicker.updateStatus(StatusTicker.STATUS_DISMISS, null);
if (roomFragment != null) {
roomFragment.refreshRoom();
}
} }
//TODO: consider this class to define in layouthelper for more complicated operation. //TODO: consider this class to define in layouthelper for more complicated operation.
......
...@@ -98,8 +98,10 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -98,8 +98,10 @@ public class MainPresenter extends BasePresenter<MainContract.View>
@Override @Override
public void onRetryLogin() { public void onRetryLogin() {
view.showConnecting(); final Disposable subscription = sessionInteractor.retryLogin()
connectivityManagerApi.keepAliveServer(); .subscribe();
addSubscription(subscription);
} }
private void openRoom() { private void openRoom() {
......
...@@ -602,8 +602,4 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -602,8 +602,4 @@ public class RoomFragment extends AbstractChatRoomFragment implements
edittingMessage = message; edittingMessage = message;
messageFormManager.setEditMessage(message.getMessage()); messageFormManager.setEditMessage(message.getMessage());
} }
public void refreshRoom() {
presenter.loadMessages();
}
} }
\ No newline at end of file
...@@ -338,6 +338,12 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -338,6 +338,12 @@ public class RocketChatWebSocketThread extends HandlerThread {
registrable.register(); registrable.register();
listeners.add(registrable); listeners.add(registrable);
} }
} catch (Exception exception) {
RCLog.w(exception, "Failed to register listeners!!");
}
}
// Register for room stream messages // Register for room stream messages
String roomId = rocketChatCache.getSelectedRoomId(); String roomId = rocketChatCache.getSelectedRoomId();
if (roomId != null && !roomId.isEmpty()) { if (roomId != null && !roomId.isEmpty()) {
...@@ -347,10 +353,6 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -347,10 +353,6 @@ public class RocketChatWebSocketThread extends HandlerThread {
streamRoomMessage.register(); streamRoomMessage.register();
listeners.add(streamRoomMessage); listeners.add(streamRoomMessage);
} }
} catch (Exception exception) {
RCLog.w(exception, "Failed to register listeners!!");
}
}
} }
@DebugLog @DebugLog
......
...@@ -135,13 +135,15 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe ...@@ -135,13 +135,15 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
() -> new Pair<>(RealmStore.getRealm(hostname), Looper.myLooper()), () -> new Pair<>(RealmStore.getRealm(hostname), Looper.myLooper()),
pair -> RxJavaInterop.toV2Flowable(pair.first.where(RealmMessage.class) pair -> RxJavaInterop.toV2Flowable(pair.first.where(RealmMessage.class)
.equalTo(RealmMessage.ROOM_ID, room.getRoomId()) .equalTo(RealmMessage.ROOM_ID, room.getRoomId())
.isNotNull(RealmMessage.USER)
.findAllSorted(RealmMessage.TIMESTAMP, Sort.DESCENDING) .findAllSorted(RealmMessage.TIMESTAMP, Sort.DESCENDING)
.asObservable()), .asObservable()),
pair -> close(pair.first, pair.second) pair -> close(pair.first, pair.second)
) )
.unsubscribeOn(AndroidSchedulers.from(Looper.myLooper())) .unsubscribeOn(AndroidSchedulers.from(Looper.myLooper()))
.filter(it -> it.isLoaded() && it.isValid()) .filter(it -> it.isLoaded() && it.isValid())
.map(this::toList)); .map(this::toList)
.distinctUntilChanged());
} }
@Override @Override
......
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