Search in sources :

Example 1 with LogIfError

use of chat.rocket.android.helper.LogIfError in project Rocket.Chat.Android by RocketChat.

the class TokenLoginObserver method onUpdateResults.

@Override
public void onUpdateResults(List<RealmSession> results) {
    if (results.isEmpty()) {
        return;
    }
    RealmSession session = results.get(0);
    methodCall.loginWithToken(session.getToken()).continueWith(new LogIfError());
}
Also used : RealmSession(chat.rocket.persistence.realm.models.internal.RealmSession) LogIfError(chat.rocket.android.helper.LogIfError)

Example 2 with LogIfError

use of chat.rocket.android.helper.LogIfError in project Rocket.Chat.Android by RocketChat.

the class AbstractDDPDocEventSubscriber method unregister.

@Override
public final void unregister() {
    isUnsubscribed = true;
    onUnregister();
    if (rxSubscription != null) {
        rxSubscription.dispose();
    }
    if (!TextUtils.isEmpty(subscriptionId)) {
        ddpClientRef.get().unsubscribe(subscriptionId).continueWith(new LogIfError());
    }
}
Also used : LogIfError(chat.rocket.android.helper.LogIfError)

Example 3 with LogIfError

use of chat.rocket.android.helper.LogIfError in project Rocket.Chat.Android by RocketChat.

the class AbstractDDPDocEventSubscriber method register.

@Override
public final void register() {
    isUnsubscribed = false;
    JSONArray params = null;
    try {
        params = getSubscriptionParams();
    } catch (JSONException exception) {
    // just ignore.
    }
    ddpClientRef.get().subscribe(getSubscriptionName(), params).onSuccess(task -> {
        if (isUnsubscribed) {
            ddpClientRef.get().unsubscribe(task.getResult().id).continueWith(new LogIfError());
        } else {
            subscriptionId = task.getResult().id;
        }
        return null;
    }).continueWith(task -> {
        if (task.isFaulted()) {
            RCLog.w(task.getError(), "DDP subscription failed.");
        }
        return null;
    });
    if (shouldTruncateTableOnInitialize()) {
        realmHelper.executeTransaction(realm -> {
            realm.delete(getModelClass());
            return null;
        }).onSuccess(task -> {
            rxSubscription = subscribe();
            return null;
        }).continueWith(new LogIfError());
    } else {
        rxSubscription = subscribe();
    }
    onRegister();
}
Also used : RealmObject(io.realm.RealmObject) Context(android.content.Context) Realm(io.realm.Realm) Iterator(java.util.Iterator) TextUtils(android.text.TextUtils) RCLog(chat.rocket.android.log.RCLog) LogIfError(chat.rocket.android.helper.LogIfError) Disposable(io.reactivex.disposables.Disposable) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Registrable(chat.rocket.android.service.Registrable) DDPSubscription(chat.rocket.android_ddp.DDPSubscription) RealmHelper(chat.rocket.persistence.realm.RealmHelper) DDPClientRef(chat.rocket.android.service.DDPClientRef) JSONArray(org.json.JSONArray) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) LogIfError(chat.rocket.android.helper.LogIfError)

Example 4 with LogIfError

use of chat.rocket.android.helper.LogIfError in project Rocket.Chat.Android by RocketChat.

the class SessionObserver method onLogin.

@DebugLog
private void onLogin() {
    streamNotifyMessage.register();
    // update push info
    pushHelper.pushSetUser(new RocketChatCache(context).getOrCreatePushId()).continueWith(new LogIfError());
}
Also used : RocketChatCache(chat.rocket.android.RocketChatCache) LogIfError(chat.rocket.android.helper.LogIfError) DebugLog(hugo.weaving.DebugLog)

Example 5 with LogIfError

use of chat.rocket.android.helper.LogIfError in project Rocket.Chat.Android by RocketChat.

the class CurrentUserObserver method onLogin.

@DebugLog
private void onLogin(RealmUser user) {
    if (listeners != null) {
        onLogout();
    }
    listeners = new ArrayList<>();
    final String userId = user.getId();
    // get and observe Room subscriptions.
    methodCall.getRoomSubscriptions().onSuccess(task -> {
        if (listeners != null) {
            Registrable listener = new StreamNotifyUserSubscriptionsChanged(context, hostname, realmHelper, ddpClientRef, userId);
            listener.register();
            listeners.add(listener);
        }
        return null;
    }).continueWith(new LogIfError());
}
Also used : Context(android.content.Context) StreamNotifyUserSubscriptionsChanged(chat.rocket.android.service.ddp.stream.StreamNotifyUserSubscriptionsChanged) Realm(io.realm.Realm) RealmUser(chat.rocket.persistence.realm.models.ddp.RealmUser) RealmResults(io.realm.RealmResults) LogIfError(chat.rocket.android.helper.LogIfError) DebugLog(hugo.weaving.DebugLog) ArrayList(java.util.ArrayList) MethodCallHelper(chat.rocket.android.api.MethodCallHelper) List(java.util.List) Registrable(chat.rocket.android.service.Registrable) RealmHelper(chat.rocket.persistence.realm.RealmHelper) DDPClientRef(chat.rocket.android.service.DDPClientRef) Registrable(chat.rocket.android.service.Registrable) StreamNotifyUserSubscriptionsChanged(chat.rocket.android.service.ddp.stream.StreamNotifyUserSubscriptionsChanged) LogIfError(chat.rocket.android.helper.LogIfError) DebugLog(hugo.weaving.DebugLog)

Aggregations

LogIfError (chat.rocket.android.helper.LogIfError)11 Context (android.content.Context)6 DDPClientRef (chat.rocket.android.service.DDPClientRef)6 RealmHelper (chat.rocket.persistence.realm.RealmHelper)6 Realm (io.realm.Realm)5 RealmResults (io.realm.RealmResults)4 List (java.util.List)4 JSONObject (org.json.JSONObject)4 RCLog (chat.rocket.android.log.RCLog)3 DebugLog (hugo.weaving.DebugLog)3 JSONArray (org.json.JSONArray)3 RocketChatCache (chat.rocket.android.RocketChatCache)2 Registrable (chat.rocket.android.service.Registrable)2 DDPSubscription (chat.rocket.android_ddp.DDPSubscription)2 SyncState (chat.rocket.core.SyncState)2 MethodCall (chat.rocket.persistence.realm.models.internal.MethodCall)2 RealmSession (chat.rocket.persistence.realm.models.internal.RealmSession)2 Disposable (io.reactivex.disposables.Disposable)2 Uri (android.net.Uri)1 TextUtils (android.text.TextUtils)1