Search in sources :

Example 1 with Optional

use of com.fernandocejas.arrow.optional.Optional in project Rocket.Chat.Android by RocketChat.

the class RoomPresenter method getMessages.

private void getMessages() {
    final Disposable subscription = roomRepository.getById(roomId).filter(Optional::isPresent).map(Optional::get).flatMap(messageInteractor::getAllFrom).subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())).observeOn(AndroidSchedulers.mainThread()).subscribe(messages -> view.showMessages(messages), Logger::report);
    addSubscription(subscription);
}
Also used : Disposable(io.reactivex.disposables.Disposable) Optional(com.fernandocejas.arrow.optional.Optional) Logger(chat.rocket.android.helper.Logger)

Example 2 with Optional

use of com.fernandocejas.arrow.optional.Optional in project Rocket.Chat.Android by RocketChat.

the class RoomPresenter method getUserPreferences.

private void getUserPreferences() {
    final Disposable subscription = userRepository.getCurrent().filter(Optional::isPresent).map(Optional::get).filter(user -> user.getSettings() != null).map(User::getSettings).filter(settings -> settings.getPreferences() != null).map(Settings::getPreferences).distinctUntilChanged().subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())).observeOn(AndroidSchedulers.mainThread()).subscribe(preferences -> {
        if (preferences.isAutoImageLoad()) {
            view.autoloadImages();
        } else {
            view.manualLoadImages();
        }
    }, Logger::report);
    addSubscription(subscription);
}
Also used : Disposable(io.reactivex.disposables.Disposable) User(chat.rocket.core.models.User) Settings(chat.rocket.core.models.Settings) Optional(com.fernandocejas.arrow.optional.Optional) UserRepository(chat.rocket.core.repositories.UserRepository) RoomRepository(chat.rocket.core.repositories.RoomRepository) Logger(chat.rocket.android.helper.Logger) NonNull(android.support.annotation.NonNull) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) LogIfError(chat.rocket.android.helper.LogIfError) MessageInteractor(chat.rocket.core.interactors.MessageInteractor) Message(chat.rocket.core.models.Message) MethodCallHelper(chat.rocket.android.api.MethodCallHelper) Disposable(io.reactivex.disposables.Disposable) ConnectivityManagerApi(chat.rocket.android.service.ConnectivityManagerApi) Pair(android.support.v4.util.Pair) Room(chat.rocket.core.models.Room) SyncState(chat.rocket.core.SyncState) Nullable(android.support.annotation.Nullable) BackgroundLooper(chat.rocket.android.BackgroundLooper) BasePresenter(chat.rocket.android.shared.BasePresenter) AbsoluteUrlHelper(chat.rocket.android.helper.AbsoluteUrlHelper) User(chat.rocket.core.models.User) Optional(com.fernandocejas.arrow.optional.Optional) Logger(chat.rocket.android.helper.Logger) Settings(chat.rocket.core.models.Settings)

Example 3 with Optional

use of com.fernandocejas.arrow.optional.Optional in project Rocket.Chat.Android by RocketChat.

the class RoomPresenter method getRoomHistoryStateInfo.

private void getRoomHistoryStateInfo() {
    final Disposable subscription = roomRepository.getHistoryStateByRoomId(roomId).distinctUntilChanged().filter(Optional::isPresent).map(Optional::get).subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())).observeOn(AndroidSchedulers.mainThread()).subscribe(roomHistoryState -> {
        int syncState = roomHistoryState.getSyncState();
        view.updateHistoryState(!roomHistoryState.isComplete(), syncState == SyncState.SYNCED || syncState == SyncState.FAILED);
    }, Logger::report);
    addSubscription(subscription);
}
Also used : Disposable(io.reactivex.disposables.Disposable) Optional(com.fernandocejas.arrow.optional.Optional) Logger(chat.rocket.android.helper.Logger)

Example 4 with Optional

use of com.fernandocejas.arrow.optional.Optional in project Rocket.Chat.Android by RocketChat.

the class RoomPresenter method onMarkAsRead.

@Override
public void onMarkAsRead() {
    final Disposable subscription = roomRepository.getById(roomId).filter(Optional::isPresent).map(Optional::get).firstElement().filter(Room::isAlert).subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())).observeOn(AndroidSchedulers.mainThread()).subscribe(room -> methodCallHelper.readMessages(room.getRoomId()).continueWith(new LogIfError()), Logger::report);
    addSubscription(subscription);
}
Also used : Disposable(io.reactivex.disposables.Disposable) Optional(com.fernandocejas.arrow.optional.Optional) Logger(chat.rocket.android.helper.Logger) LogIfError(chat.rocket.android.helper.LogIfError)

Example 5 with Optional

use of com.fernandocejas.arrow.optional.Optional in project Rocket.Chat.Android by RocketChat.

the class RoomPresenter method getRoomInfo.

private void getRoomInfo() {
    final Disposable subscription = roomRepository.getById(roomId).distinctUntilChanged().filter(Optional::isPresent).map(Optional::get).subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())).observeOn(AndroidSchedulers.mainThread()).subscribe(room -> view.render(room), Logger::report);
    addSubscription(subscription);
}
Also used : Disposable(io.reactivex.disposables.Disposable) Optional(com.fernandocejas.arrow.optional.Optional) Logger(chat.rocket.android.helper.Logger)

Aggregations

Logger (chat.rocket.android.helper.Logger)5 Optional (com.fernandocejas.arrow.optional.Optional)5 Disposable (io.reactivex.disposables.Disposable)5 LogIfError (chat.rocket.android.helper.LogIfError)2 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 Pair (android.support.v4.util.Pair)1 BackgroundLooper (chat.rocket.android.BackgroundLooper)1 MethodCallHelper (chat.rocket.android.api.MethodCallHelper)1 AbsoluteUrlHelper (chat.rocket.android.helper.AbsoluteUrlHelper)1 ConnectivityManagerApi (chat.rocket.android.service.ConnectivityManagerApi)1 BasePresenter (chat.rocket.android.shared.BasePresenter)1 SyncState (chat.rocket.core.SyncState)1 MessageInteractor (chat.rocket.core.interactors.MessageInteractor)1 Message (chat.rocket.core.models.Message)1 Room (chat.rocket.core.models.Room)1 Settings (chat.rocket.core.models.Settings)1 User (chat.rocket.core.models.User)1 RoomRepository (chat.rocket.core.repositories.RoomRepository)1 UserRepository (chat.rocket.core.repositories.UserRepository)1