Up the game on performance & reliability

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-04-26 12:46:33 +02:00
parent 47b5c66f8f
commit deaa761736
8 changed files with 370 additions and 168 deletions

View File

@ -134,11 +134,11 @@ public class NextcloudTalkApplication extends MultiDexApplication {
new ClosedInterfaceImpl().providerInstallerInstallIfNeededAsync(); new ClosedInterfaceImpl().providerInstallerInstallIfNeededAsync();
DeviceUtils.ignoreSpecialBatteryFeatures(); DeviceUtils.ignoreSpecialBatteryFeatures();
new JobRequest.Builder(PushRegistrationJob.TAG).setUpdateCurrent(true).startNow().build().schedule(); new JobRequest.Builder(PushRegistrationJob.TAG).setUpdateCurrent(true).startNow().build().scheduleAsync();
new JobRequest.Builder(AccountRemovalJob.TAG).setUpdateCurrent(true).startNow().build().schedule(); new JobRequest.Builder(AccountRemovalJob.TAG).setUpdateCurrent(true).startNow().build().scheduleAsync();
schedulePeriodCapabilitiesJob(); schedulePeriodCapabilitiesJob();
new JobRequest.Builder(CapabilitiesJob.TAG).setUpdateCurrent(false).startNow().build().schedule(); new JobRequest.Builder(CapabilitiesJob.TAG).setUpdateCurrent(false).startNow().build().scheduleAsync();
} }
private void schedulePeriodCapabilitiesJob() { private void schedulePeriodCapabilitiesJob() {

View File

@ -24,7 +24,6 @@ import android.content.pm.ActivityInfo;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -39,22 +38,33 @@ import com.nextcloud.talk.R;
import com.nextcloud.talk.api.NcApi; import com.nextcloud.talk.api.NcApi;
import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.controllers.base.BaseController; import com.nextcloud.talk.controllers.base.BaseController;
import com.nextcloud.talk.events.EventStatus;
import com.nextcloud.talk.jobs.CapabilitiesJob; import com.nextcloud.talk.jobs.CapabilitiesJob;
import com.nextcloud.talk.jobs.PushRegistrationJob; import com.nextcloud.talk.jobs.PushRegistrationJob;
import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.models.json.generic.Status;
import com.nextcloud.talk.models.json.rooms.RoomsOverall;
import com.nextcloud.talk.models.json.userprofile.UserProfileOverall;
import com.nextcloud.talk.utils.ApiUtils; import com.nextcloud.talk.utils.ApiUtils;
import com.nextcloud.talk.utils.ApplicationWideMessageHolder; import com.nextcloud.talk.utils.ApplicationWideMessageHolder;
import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.bundle.BundleKeys;
import com.nextcloud.talk.utils.database.user.UserUtils; import com.nextcloud.talk.utils.database.user.UserUtils;
import com.nextcloud.talk.utils.preferences.AppPreferences; import com.nextcloud.talk.utils.preferences.AppPreferences;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.net.CookieManager; import java.net.CookieManager;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import autodagger.AutoInjector; import autodagger.AutoInjector;
import butterknife.BindView; import butterknife.BindView;
import io.reactivex.CompletableObserver; import io.reactivex.CompletableObserver;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.Observer;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
@ -76,13 +86,15 @@ public class AccountVerificationController extends BaseController {
@Inject @Inject
AppPreferences appPreferences; AppPreferences appPreferences;
@Inject
EventBus eventBus;
@BindView(R.id.progress_text) @BindView(R.id.progress_text)
TextView progressText; TextView progressText;
private Disposable roomsQueryDisposable; private long internalAccountId = -1;
private Disposable profileQueryDisposable;
private Disposable dbQueryDisposable; private List<Disposable> disposables = new ArrayList<>();
private Disposable statusQueryDisposable;
private String baseUrl; private String baseUrl;
private String username; private String username;
@ -105,6 +117,18 @@ public class AccountVerificationController extends BaseController {
} }
} }
@Override
protected void onAttach(@NonNull View view) {
super.onAttach(view);
eventBus.register(this);
}
@Override
protected void onDetach(@NonNull View view) {
super.onDetach(view);
eventBus.unregister(this);
}
@Override @Override
protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) { protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
return inflater.inflate(R.layout.controller_account_verification, container, false); return inflater.inflate(R.layout.controller_account_verification, container, false);
@ -123,8 +147,6 @@ public class AccountVerificationController extends BaseController {
getActionBar().hide(); getActionBar().hide();
} }
dispose(null);
if (isAccountImport && !baseUrl.startsWith("http://") && !baseUrl.startsWith("https://") || (!TextUtils if (isAccountImport && !baseUrl.startsWith("http://") && !baseUrl.startsWith("https://") || (!TextUtils
.isEmpty(originalProtocol) && !baseUrl.startsWith(originalProtocol))) { .isEmpty(originalProtocol) && !baseUrl.startsWith(originalProtocol))) {
determineBaseUrlProtocol(true); determineBaseUrlProtocol(true);
@ -134,6 +156,13 @@ public class AccountVerificationController extends BaseController {
} }
private void checkEverything() {
String credentials = ApiUtils.getCredentials(username, token);
cookieManager.getCookieStore().removeAll();
findServerTalkApp(credentials);
}
private void determineBaseUrlProtocol(boolean checkForcedHttps) { private void determineBaseUrlProtocol(boolean checkForcedHttps) {
cookieManager.getCookieStore().removeAll(); cookieManager.getCookieStore().removeAll();
@ -147,157 +176,231 @@ public class AccountVerificationController extends BaseController {
queryUrl = "http://" + baseUrl + ApiUtils.getUrlPostfixForStatus(); queryUrl = "http://" + baseUrl + ApiUtils.getUrlPostfixForStatus();
} }
statusQueryDisposable = ncApi.getServerStatus(queryUrl) ncApi.getServerStatus(queryUrl)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<Status>() {
.subscribe(status -> { @Override
if (checkForcedHttps) { public void onSubscribe(Disposable d) {
baseUrl = "https://" + baseUrl; disposables.add(d);
} else {
baseUrl = "http://" + baseUrl;
} }
checkEverything(); @Override
}, throwable -> { public void onNext(Status status) {
if (checkForcedHttps) { if (checkForcedHttps) {
determineBaseUrlProtocol(false); baseUrl = "https://" + baseUrl;
} else { } else {
abortVerification(); baseUrl = "http://" + baseUrl;
}
checkEverything();
}
@Override
public void onError(Throwable e) {
if (checkForcedHttps) {
determineBaseUrlProtocol(false);
} else {
abortVerification();
}
}
@Override
public void onComplete() {
} }
}, () -> {
statusQueryDisposable.dispose();
}); });
} }
private void checkEverything() { private void findServerTalkApp(String credentials) {
String credentials = ApiUtils.getCredentials(username, token); ncApi.getRooms(credentials, ApiUtils.getUrlForGetRooms(baseUrl))
cookieManager.getCookieStore().removeAll();
roomsQueryDisposable = ncApi.getRooms(credentials, ApiUtils.getUrlForGetRooms(baseUrl))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<RoomsOverall>() {
.subscribe(roomsOverall -> { @Override
progressText.setText(String.format(getResources().getString( public void onSubscribe(Disposable d) {
R.string.nc_nextcloud_talk_app_installed), getResources().getString(R.string.nc_app_name))); disposables.add(d);
}
profileQueryDisposable = ncApi.getUserProfile(credentials, @Override
ApiUtils.getUrlForUserProfile(baseUrl)) public void onNext(RoomsOverall roomsOverall) {
.subscribeOn(Schedulers.newThread()) fetchProfile(credentials);
.observeOn(AndroidSchedulers.mainThread()) }
.subscribe(userProfileOverall -> {
progressText.setText(progressText.getText().toString() + "\n" +
getResources().getString(R.string.nc_display_name_fetched));
String displayName = null; @Override
if (!TextUtils.isEmpty(userProfileOverall.getOcs().getData() public void onError(Throwable e) {
.getDisplayName())) { if (getActivity() != null) {
displayName = userProfileOverall.getOcs().getData() getActivity().runOnUiThread(() -> progressText.setText(String.format(getResources().getString(
.getDisplayName(); R.string.nc_nextcloud_talk_app_not_installed), getResources().getString(R.string.nc_app_name))));
} else if (!TextUtils.isEmpty(userProfileOverall.getOcs().getData() }
.getDisplayNameAlt())) {
displayName = userProfileOverall.getOcs().getData()
.getDisplayNameAlt();
}
if (!TextUtils.isEmpty(displayName)) { ApplicationWideMessageHolder.getInstance().setMessageType(
dbQueryDisposable = userUtils.createOrUpdateUser(username, token, ApplicationWideMessageHolder.MessageType.SERVER_WITHOUT_TALK);
baseUrl, displayName, null, true,
userProfileOverall.getOcs().getData().getUserId(), null, null,
appPreferences.getTemporaryClientCertAlias())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(userEntity -> {
progressText.setText(progressText.getText().toString()
+ "\n" +
getResources().getString(
R.string.nc_display_name_stored));
new JobRequest.Builder(PushRegistrationJob.TAG). abortVerification();
setUpdateCurrent(true).startNow().build().schedule(); }
PersistableBundleCompat persistableBundleCompat = new @Override
PersistableBundleCompat(); public void onComplete() {
persistableBundleCompat.putLong(BundleKeys
.KEY_INTERNAL_USER_ID, userEntity.getId());
new JobRequest.Builder(CapabilitiesJob.TAG).setUpdateCurrent }
(false).addExtras(persistableBundleCompat).startNow() });
.build().schedule();
cookieManager.getCookieStore().removeAll();
userUtils.disableAllUsersWithoutId(userEntity.getId());
if (userUtils.getUsers().size() == 1) {
getRouter().setRoot(RouterTransaction.with(new
MagicBottomNavigationController())
.pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()));
} else {
if (isAccountImport) {
ApplicationWideMessageHolder.getInstance().setMessageType(
ApplicationWideMessageHolder.MessageType.ACCOUNT_WAS_IMPORTED);
}
getRouter().popToRoot();
}
},
throwable -> {
progressText.setText(progressText.getText().toString() +
"\n" +
getResources().getString(
R.string.nc_display_name_not_stored));
abortVerification();
}, () -> dispose(dbQueryDisposable));
} else {
progressText.setText(progressText.getText().toString() + "\n" +
getResources().getString(R.string.nc_display_name_not_fetched));
abortVerification();
}
}, throwable -> {
progressText.setText(progressText.getText().toString()
+ "\n" + getResources().getString(
R.string.nc_display_name_not_fetched));
abortVerification();
}, () -> dispose(profileQueryDisposable));
}, throwable -> {
progressText.setText(String.format(getResources().getString(
R.string.nc_nextcloud_talk_app_not_installed), getResources().getString(R.string.nc_app_name)));
ApplicationWideMessageHolder.getInstance().setMessageType(
ApplicationWideMessageHolder.MessageType.SERVER_WITHOUT_TALK);
abortVerification();
}, () -> dispose(roomsQueryDisposable));
} }
private void dispose(@Nullable Disposable disposable) { private void storeProfile(String credentials, String displayName, String userId) {
if (disposable != null && !disposable.isDisposed()) { userUtils.createOrUpdateUser(username, token,
disposable.dispose(); baseUrl, displayName, null, true,
disposable = null; userId, null, null,
} else if (disposable == null) { appPreferences.getTemporaryClientCertAlias())
if (roomsQueryDisposable != null && !roomsQueryDisposable.isDisposed()) { .subscribeOn(Schedulers.newThread())
roomsQueryDisposable.dispose(); .subscribe(new Observer<UserEntity>() {
roomsQueryDisposable = null; @Override
} public void onSubscribe(Disposable d) {
disposables.add(d);
}
if (profileQueryDisposable != null && !profileQueryDisposable.isDisposed()) { @Override
profileQueryDisposable.dispose(); public void onNext(UserEntity userEntity) {
profileQueryDisposable = null; internalAccountId = userEntity.getId();
}
if (dbQueryDisposable != null && !dbQueryDisposable.isDisposed()) { registerForPush();
dbQueryDisposable.dispose(); }
dbQueryDisposable = null;
}
if (statusQueryDisposable != null && !statusQueryDisposable.isDisposed()) { @Override
statusQueryDisposable.dispose(); public void onError(Throwable e) {
statusQueryDisposable = null; progressText.setText(progressText.getText().toString() +
"\n" +
getResources().getString(
R.string.nc_display_name_not_stored));
abortVerification();
}
@Override
public void onComplete() {
}
});
}
private void fetchProfile(String credentials) {
ncApi.getUserProfile(credentials,
ApiUtils.getUrlForUserProfile(baseUrl))
.subscribeOn(Schedulers.newThread())
.subscribe(new Observer<UserProfileOverall>() {
@Override
public void onSubscribe(Disposable d) {
disposables.add(d);
}
@Override
public void onNext(UserProfileOverall userProfileOverall) {
String displayName = null;
if (!TextUtils.isEmpty(userProfileOverall.getOcs().getData()
.getDisplayName())) {
displayName = userProfileOverall.getOcs().getData()
.getDisplayName();
} else if (!TextUtils.isEmpty(userProfileOverall.getOcs().getData()
.getDisplayNameAlt())) {
displayName = userProfileOverall.getOcs().getData()
.getDisplayNameAlt();
}
if (!TextUtils.isEmpty(displayName)) {
storeProfile(credentials, displayName, userProfileOverall.getOcs().getData().getUserId());
} else {
if (getActivity() != null) {
getActivity().runOnUiThread(() -> progressText.setText(progressText.getText().toString() + "\n" +
getResources().getString(R.string.nc_display_name_not_fetched)));
}
abortVerification();
}
}
@Override
public void onError(Throwable e) {
if (getActivity() != null) {
getActivity().runOnUiThread(() -> progressText.setText(progressText.getText().toString() + "\n" +
getResources().getString(R.string.nc_display_name_not_fetched)));
}
abortVerification();
}
@Override
public void onComplete() {
}
});
}
private void registerForPush() {
new JobRequest.Builder(PushRegistrationJob.TAG).
setUpdateCurrent(true).startNow().build().schedule();
}
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(EventStatus eventStatus) {
if (eventStatus.getEventType().equals(EventStatus.EventType.PUSH_REGISTRATION)) {
if (internalAccountId == eventStatus.getUserId() && !eventStatus.isAllGood() && getActivity() != null) {
getActivity().runOnUiThread(() -> progressText.setText(progressText.getText().toString() + "\n" +
getResources().getString(R.string.nc_push_disabled)));
}
fetchAndStoreCapabilities();
} else if (eventStatus.getEventType().equals(EventStatus.EventType.CAPABILITIES_FETCH)) {
if (internalAccountId == eventStatus.getUserId() && !eventStatus.isAllGood()) {
if (getActivity() != null) {
getActivity().runOnUiThread(() -> progressText.setText(progressText.getText().toString() + "\n" +
getResources().getString(R.string.nc_capabilities_failed)));
}
abortVerification();
} else if (internalAccountId == eventStatus.getUserId() && eventStatus.isAllGood()) {
proceedWithLogin();
} }
} }
} }
private void fetchAndStoreCapabilities() {
PersistableBundleCompat persistableBundleCompat = new
PersistableBundleCompat();
persistableBundleCompat.putLong(BundleKeys
.KEY_INTERNAL_USER_ID, internalAccountId);
new JobRequest.Builder(CapabilitiesJob.TAG).setUpdateCurrent
(false).addExtras(persistableBundleCompat).startNow()
.build().scheduleAsync();
}
private void proceedWithLogin() {
cookieManager.getCookieStore().removeAll();
userUtils.disableAllUsersWithoutId(internalAccountId);
if (getActivity() != null) {
getActivity().runOnUiThread(() -> {
if (userUtils.getUsers().size() == 1) {
getRouter().setRoot(RouterTransaction.with(new
MagicBottomNavigationController())
.pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()));
} else {
if (isAccountImport) {
ApplicationWideMessageHolder.getInstance().setMessageType(
ApplicationWideMessageHolder.MessageType.ACCOUNT_WAS_IMPORTED);
}
getRouter().popToRoot();
}
});
}
}
private void dispose() {
for (int i = 0; i < disposables.size(); i++) {
if (!disposables.get(i).isDisposed()) {
disposables.get(i).dispose();
}
}
}
@Override @Override
protected void onDestroyView(@NonNull View view) { protected void onDestroyView(@NonNull View view) {
super.onDestroyView(view); super.onDestroyView(view);
@ -308,45 +411,70 @@ public class AccountVerificationController extends BaseController {
@Override @Override
public void onDestroy() { public void onDestroy() {
dispose();
super.onDestroy(); super.onDestroy();
dispose(null);
} }
private void abortVerification() { private void abortVerification() {
dispose(null);
if (!isAccountImport) { if (!isAccountImport) {
userUtils.deleteUser(username, baseUrl).subscribe(new CompletableObserver() { if (internalAccountId != -1) {
@Override userUtils.deleteUserWithId(internalAccountId).subscribe(new CompletableObserver() {
public void onSubscribe(Disposable d) { @Override
public void onSubscribe(Disposable d) {
}
@Override
public void onComplete() {
if (getActivity() != null) {
getActivity().runOnUiThread(() -> {
new Handler().postDelayed(() -> getRouter().popToRoot(), 7500);
});
}
}
@Override
public void onError(Throwable e) {
}
});
} else {
if (getActivity() != null) {
getActivity().runOnUiThread(() -> {
new Handler().postDelayed(() -> getRouter().popToRoot(), 7500);
});
} }
}
@Override
public void onComplete() {
new Handler().postDelayed(() -> getRouter().popToRoot(), 7500);
}
@Override
public void onError(Throwable e) {
}
});
} else { } else {
ApplicationWideMessageHolder.getInstance().setMessageType( ApplicationWideMessageHolder.getInstance().setMessageType(
ApplicationWideMessageHolder.MessageType.FAILED_TO_IMPORT_ACCOUNT); ApplicationWideMessageHolder.MessageType.FAILED_TO_IMPORT_ACCOUNT);
new Handler().postDelayed(() -> { new Handler().postDelayed(() -> {
if (getRouter().hasRootController()) { if (getRouter().hasRootController()) {
getRouter().popToRoot(); if (getActivity() != null) {
getActivity().runOnUiThread(() -> {
getRouter().popToRoot();
});
}
} else { } else {
if (userUtils.anyUserExists()) { if (userUtils.anyUserExists()) {
getRouter().setRoot(RouterTransaction.with(new MagicBottomNavigationController()) if (getActivity() != null) {
.pushChangeHandler(new HorizontalChangeHandler()) getActivity().runOnUiThread(() -> {
.popChangeHandler(new HorizontalChangeHandler()));
getRouter().setRoot(RouterTransaction.with(new MagicBottomNavigationController())
.pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()));
});
}
} else { } else {
getRouter().setRoot(RouterTransaction.with(new ServerSelectionController()) if (getActivity() != null) {
.pushChangeHandler(new HorizontalChangeHandler()) getActivity().runOnUiThread(() -> {
.popChangeHandler(new HorizontalChangeHandler())); getRouter().setRoot(RouterTransaction.with(new ServerSelectionController())
.pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()));
});
}
} }
} }
}, 7500); }, 7500);

View File

@ -362,7 +362,7 @@ public class SettingsController extends BaseController {
cookieManager.getCookieStore().removeAll(); cookieManager.getCookieStore().removeAll();
boolean otherUserExists = userUtils.scheduleUserForDeletionWithId(userEntity.getId()); boolean otherUserExists = userUtils.scheduleUserForDeletionWithId(userEntity.getId());
new JobRequest.Builder(AccountRemovalJob.TAG).setUpdateCurrent(true) new JobRequest.Builder(AccountRemovalJob.TAG).setUpdateCurrent(true)
.startNow().build().schedule(); .startNow().build().scheduleAsync();
if (otherUserExists && getView() != null) { if (otherUserExists && getView() != null) {
onViewBound(getView()); onViewBound(getView());

View File

@ -0,0 +1,41 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.events;
import lombok.Data;
@Data
public class EventStatus {
private long userId;
private EventType eventType;
private boolean allGood;
public EventStatus(long userId, EventType eventType, boolean allGood) {
this.userId = userId;
this.eventType = eventType;
this.allGood = allGood;
}
public enum EventType {
PUSH_REGISTRATION, CAPABILITIES_FETCH
}
}

View File

@ -27,12 +27,15 @@ import com.bluelinelabs.logansquare.LoganSquare;
import com.evernote.android.job.Job; import com.evernote.android.job.Job;
import com.nextcloud.talk.api.NcApi; import com.nextcloud.talk.api.NcApi;
import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.events.EventStatus;
import com.nextcloud.talk.models.database.UserEntity; import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall; import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall;
import com.nextcloud.talk.utils.ApiUtils; import com.nextcloud.talk.utils.ApiUtils;
import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.bundle.BundleKeys;
import com.nextcloud.talk.utils.database.user.UserUtils; import com.nextcloud.talk.utils.database.user.UserUtils;
import org.greenrobot.eventbus.EventBus;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -57,6 +60,9 @@ public class CapabilitiesJob extends Job {
@Inject @Inject
Retrofit retrofit; Retrofit retrofit;
@Inject
EventBus eventBus;
@Inject @Inject
OkHttpClient okHttpClient; OkHttpClient okHttpClient;
@ -100,6 +106,8 @@ public class CapabilitiesJob extends Job {
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
eventBus.post(new EventStatus(internalUserEntity.getId(),
EventStatus.EventType.CAPABILITIES_FETCH, false));
} }
@ -128,12 +136,14 @@ public class CapabilitiesJob extends Job {
@Override @Override
public void onNext(UserEntity userEntity) { public void onNext(UserEntity userEntity) {
eventBus.post(new EventStatus(userEntity.getId(),
EventStatus.EventType.CAPABILITIES_FETCH, true));
} }
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
eventBus.post(new EventStatus(internalUserEntity.getId(),
EventStatus.EventType.CAPABILITIES_FETCH, false));
} }
@Override @Override

View File

@ -29,6 +29,7 @@ import com.bluelinelabs.logansquare.LoganSquare;
import com.nextcloud.talk.R; import com.nextcloud.talk.R;
import com.nextcloud.talk.api.NcApi; import com.nextcloud.talk.api.NcApi;
import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.events.EventStatus;
import com.nextcloud.talk.models.SignatureVerification; import com.nextcloud.talk.models.SignatureVerification;
import com.nextcloud.talk.models.database.UserEntity; import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.models.json.push.PushConfigurationState; import com.nextcloud.talk.models.json.push.PushConfigurationState;
@ -36,6 +37,8 @@ import com.nextcloud.talk.models.json.push.PushRegistrationOverall;
import com.nextcloud.talk.utils.database.user.UserUtils; import com.nextcloud.talk.utils.database.user.UserUtils;
import com.nextcloud.talk.utils.preferences.AppPreferences; import com.nextcloud.talk.utils.preferences.AppPreferences;
import org.greenrobot.eventbus.EventBus;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -79,6 +82,9 @@ public class PushUtils {
@Inject @Inject
AppPreferences appPreferences; AppPreferences appPreferences;
@Inject
EventBus eventBus;
@Inject @Inject
OkHttpClient okHttpClient; OkHttpClient okHttpClient;
@ -327,12 +333,15 @@ public class PushUtils {
@Override @Override
public void onNext(UserEntity userEntity) { public void onNext(UserEntity userEntity) {
eventBus.post(new EventStatus(userEntity.getId(), EventStatus.EventType.PUSH_REGISTRATION, true));
} }
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
eventBus.post(new EventStatus
(userEntity.getId(),
EventStatus.EventType
.PUSH_REGISTRATION, false));
} }
@Override @Override
@ -349,7 +358,8 @@ public class PushUtils {
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
eventBus.post(new EventStatus(userEntity.getId(),
EventStatus.EventType.PUSH_REGISTRATION, false));
} }
@Override @Override
@ -361,12 +371,13 @@ public class PushUtils {
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
eventBus.post(new EventStatus(userEntity.getId(),
EventStatus.EventType.PUSH_REGISTRATION, false));
} }
@Override @Override
public void onComplete() { public void onComplete() {
} }
}); });
} }

View File

@ -99,6 +99,16 @@ public class UserUtils {
} }
public Completable deleteUserWithId(long id) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(id)).limit(1).get();
UserEntity user = (UserEntity) findUserQueryResult.firstOrNull();
return dataStore.delete(user)
.subscribeOn(Schedulers.newThread());
}
public void disableAllUsersWithoutId(long userId) { public void disableAllUsersWithoutId(long userId) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.notEqual(userId)).get(); Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.notEqual(userId)).get();

View File

@ -20,6 +20,8 @@
<!-- Account verification --> <!-- Account verification -->
<string name="nc_display_name_fetched">Display name fetched</string> <string name="nc_display_name_fetched">Display name fetched</string>
<string name="nc_push_disabled">Push notifications disabled</string>
<string name="nc_capabilities_failed">Failed to fetch capabilities, aborting</string>
<string name="nc_display_name_not_fetched">Display name couldn\'t be fetched, aborting</string> <string name="nc_display_name_not_fetched">Display name couldn\'t be fetched, aborting</string>
<string name="nc_nextcloud_talk_app_installed">%1$s app found</string> <string name="nc_nextcloud_talk_app_installed">%1$s app found</string>
<string name="nc_nextcloud_talk_app_not_installed">%1$s app not installed on the server, aborting</string> <string name="nc_nextcloud_talk_app_not_installed">%1$s app not installed on the server, aborting</string>