mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +01:00
Migrate DeleteConversationWorker from requery to room
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
5b8c352947
commit
2dfd4731af
@ -21,30 +21,35 @@
|
|||||||
package com.nextcloud.talk.jobs;
|
package com.nextcloud.talk.jobs;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
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 DeleteConversationWorker extends Worker {
|
public class DeleteConversationWorker extends Worker {
|
||||||
@Inject
|
@Inject
|
||||||
@ -54,7 +59,7 @@ public class DeleteConversationWorker extends Worker {
|
|||||||
OkHttpClient okHttpClient;
|
OkHttpClient okHttpClient;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
UserUtils userUtils;
|
UserManager userManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
EventBus eventBus;
|
EventBus eventBus;
|
||||||
@ -72,17 +77,21 @@ public class DeleteConversationWorker 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) {
|
||||||
int apiVersion = ApiUtils.getConversationApiVersion(operationUser, new int[] {ApiUtils.APIv4, 1});
|
int apiVersion = ApiUtils.getConversationApiVersion(operationUser, new int[]{ApiUtils.APIv4, 1});
|
||||||
|
|
||||||
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
|
||||||
JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class);
|
.newBuilder()
|
||||||
|
.client(okHttpClient.newBuilder().cookieJar(new 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);
|
||||||
|
|
||||||
ncApi.deleteRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, operationUser.getBaseUrl(),
|
ncApi.deleteRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, operationUser.getBaseUrl(),
|
||||||
conversationToken))
|
conversationToken))
|
||||||
@ -93,18 +102,16 @@ public class DeleteConversationWorker 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
|
||||||
public void onError(Throwable e) {
|
public void onError(Throwable e) {
|
||||||
|
// unused atm
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user