mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +01:00
Migrate LeaveConversationWorker from requery to room
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
24ddaf4ec4
commit
22ef1457ee
@ -23,34 +23,38 @@ package com.nextcloud.talk.jobs;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.nextcloud.talk.api.NcApi;
|
||||||
|
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||||
|
import com.nextcloud.talk.data.user.model.User;
|
||||||
|
import com.nextcloud.talk.events.EventStatus;
|
||||||
|
import com.nextcloud.talk.models.json.generic.GenericOverall;
|
||||||
|
import com.nextcloud.talk.users.UserManager;
|
||||||
|
import com.nextcloud.talk.utils.ApiUtils;
|
||||||
|
import com.nextcloud.talk.utils.UserIdUtils;
|
||||||
|
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
|
import java.net.CookieManager;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.work.Data;
|
import androidx.work.Data;
|
||||||
import androidx.work.Worker;
|
import androidx.work.Worker;
|
||||||
import androidx.work.WorkerParameters;
|
import androidx.work.WorkerParameters;
|
||||||
import autodagger.AutoInjector;
|
import autodagger.AutoInjector;
|
||||||
import com.nextcloud.talk.api.NcApi;
|
|
||||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
|
||||||
import com.nextcloud.talk.events.EventStatus;
|
|
||||||
import com.nextcloud.talk.models.database.UserEntity;
|
|
||||||
import com.nextcloud.talk.models.json.generic.GenericOverall;
|
|
||||||
import com.nextcloud.talk.utils.ApiUtils;
|
|
||||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
|
||||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
|
||||||
import io.reactivex.Observer;
|
import io.reactivex.Observer;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import okhttp3.JavaNetCookieJar;
|
import okhttp3.JavaNetCookieJar;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import org.greenrobot.eventbus.EventBus;
|
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import java.net.CookieManager;
|
|
||||||
|
|
||||||
@AutoInjector(NextcloudTalkApplication.class)
|
@AutoInjector(NextcloudTalkApplication.class)
|
||||||
public class LeaveConversationWorker extends Worker {
|
public class LeaveConversationWorker extends Worker {
|
||||||
|
|
||||||
private static String TAG = "LeaveConversationWorker";
|
private static final String TAG = "LeaveConversationWorker";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Retrofit retrofit;
|
Retrofit retrofit;
|
||||||
@ -59,7 +63,7 @@ public class LeaveConversationWorker extends Worker {
|
|||||||
OkHttpClient okHttpClient;
|
OkHttpClient okHttpClient;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
UserUtils userUtils;
|
UserManager userManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
EventBus eventBus;
|
EventBus eventBus;
|
||||||
@ -77,15 +81,16 @@ public class LeaveConversationWorker extends Worker {
|
|||||||
Data data = getInputData();
|
Data data = getInputData();
|
||||||
long operationUserId = data.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), -1);
|
long operationUserId = data.getLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), -1);
|
||||||
String conversationToken = data.getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN());
|
String conversationToken = data.getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN());
|
||||||
UserEntity operationUser = userUtils.getUserWithId(operationUserId);
|
User operationUser = userManager.getUserWithId(operationUserId).blockingGet();
|
||||||
|
|
||||||
if (operationUser != null) {
|
if (operationUser != null) {
|
||||||
String credentials = ApiUtils.getCredentials(operationUser.getUsername(), operationUser.getToken());
|
String credentials = ApiUtils.getCredentials(operationUser.getUsername(), operationUser.getToken());
|
||||||
ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new
|
ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new
|
||||||
JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class);
|
JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class);
|
||||||
|
|
||||||
EventStatus eventStatus = new EventStatus(operationUser.getId(),
|
EventStatus eventStatus = new EventStatus(UserIdUtils.INSTANCE.getIdForUser(operationUser),
|
||||||
EventStatus.EventType.CONVERSATION_UPDATE, true);
|
EventStatus.EventType.CONVERSATION_UPDATE,
|
||||||
|
true);
|
||||||
|
|
||||||
int apiVersion = ApiUtils.getConversationApiVersion(operationUser, new int[] {ApiUtils.APIv4, 1});
|
int apiVersion = ApiUtils.getConversationApiVersion(operationUser, new int[] {ApiUtils.APIv4, 1});
|
||||||
|
|
||||||
@ -99,13 +104,11 @@ public class LeaveConversationWorker extends Worker {
|
|||||||
@Override
|
@Override
|
||||||
public void onSubscribe(Disposable d) {
|
public void onSubscribe(Disposable d) {
|
||||||
disposable = d;
|
disposable = d;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(GenericOverall genericOverall) {
|
public void onNext(GenericOverall genericOverall) {
|
||||||
eventBus.postSticky(eventStatus);
|
eventBus.postSticky(eventStatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user