use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.
the class AccountRemovalJob method onRunJob.
@NonNull
@Override
protected Result onRunJob(Params params) {
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
PushConfigurationState pushConfigurationState;
for (Object userEntityObject : userUtils.getUsersScheduledForDeletion()) {
UserEntity userEntity = (UserEntity) userEntityObject;
try {
if (!TextUtils.isEmpty(userEntity.getPushConfigurationState())) {
pushConfigurationState = LoganSquare.parse(userEntity.getPushConfigurationState(), PushConfigurationState.class);
PushConfigurationState finalPushConfigurationState = pushConfigurationState;
ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class);
ncApi.unregisterDeviceForNotificationsWithNextcloud(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlNextcloudPush(userEntity.getBaseUrl())).subscribe(new Observer<GenericOverall>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(GenericOverall genericOverall) {
if (genericOverall.getOcs().getMeta().getStatusCode() == 200 || genericOverall.getOcs().getMeta().getStatusCode() == 202) {
HashMap<String, String> queryMap = new HashMap<>();
queryMap.put("deviceIdentifier", finalPushConfigurationState.deviceIdentifier);
queryMap.put("userPublicKey", finalPushConfigurationState.getUserPublicKey());
queryMap.put("deviceIdentifierSignature", finalPushConfigurationState.getDeviceIdentifierSignature());
ncApi.unregisterDeviceForNotificationsWithProxy(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlPushProxy(), queryMap).subscribe(new Observer<Void>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Void aVoid) {
userUtils.deleteUser(userEntity.getUsername(), userEntity.getBaseUrl()).subscribe(new CompletableObserver() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onComplete() {
}
@Override
public void onError(Throwable e) {
}
});
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
} else {
userUtils.deleteUser(userEntity.getUsername(), userEntity.getBaseUrl()).subscribe(new CompletableObserver() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onComplete() {
}
@Override
public void onError(Throwable e) {
}
});
}
} catch (IOException e) {
Log.d(TAG, "Something went wrong while removing job at parsing PushConfigurationState");
userUtils.deleteUser(userEntity.getUsername(), userEntity.getBaseUrl()).subscribe(new CompletableObserver() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onComplete() {
}
@Override
public void onError(Throwable e) {
}
});
}
}
return Result.SUCCESS;
}
use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.
the class CapabilitiesJob method onRunJob.
@NonNull
@Override
protected Result onRunJob(Params params) {
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
long internalUserId = getParams().getExtras().getLong(BundleKeys.KEY_INTERNAL_USER_ID, -1);
UserEntity userEntity;
List userEntityObjectList = new ArrayList();
if (internalUserId == -1 || (userEntity = userUtils.getUserWithInternalId(internalUserId)) == null) {
userEntityObjectList = userUtils.getUsers();
} else {
userEntityObjectList.add(userEntity);
}
for (Object userEntityObject : userEntityObjectList) {
UserEntity internalUserEntity = (UserEntity) userEntityObject;
ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new JavaNetCookieJar(new java.net.CookieManager())).build()).build().create(NcApi.class);
ncApi.getCapabilities(ApiUtils.getCredentials(internalUserEntity.getUsername(), internalUserEntity.getToken()), ApiUtils.getUrlForCapabilities(internalUserEntity.getBaseUrl())).subscribeOn(Schedulers.newThread()).subscribe(new Observer<CapabilitiesOverall>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(CapabilitiesOverall capabilitiesOverall) {
updateUser(capabilitiesOverall, internalUserEntity);
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
return Result.SUCCESS;
}
use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.
the class CallsListController method fetchData.
private void fetchData(boolean fromBottomSheet) {
dispose(null);
callItems = new ArrayList<>();
roomsQueryDisposable = ncApi.getRooms(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlForGetRooms(userEntity.getBaseUrl())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(roomsOverall -> {
if (roomsOverall != null) {
for (int i = 0; i < roomsOverall.getOcs().getData().size(); i++) {
callItems.add(new CallItem(roomsOverall.getOcs().getData().get(i), userEntity));
}
adapter.updateDataSet(callItems, true);
Collections.sort(callItems, (callItem, t1) -> Long.compare(t1.getModel().getLastPing(), callItem.getModel().getLastPing()));
if (searchItem != null) {
searchItem.setVisible(callItems.size() > 0);
}
}
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
}, throwable -> {
if (searchItem != null) {
searchItem.setVisible(false);
}
if (throwable instanceof HttpException) {
HttpException exception = (HttpException) throwable;
switch(exception.code()) {
case 401:
if (getParentController() != null && getParentController().getRouter() != null) {
getParentController().getRouter().pushController((RouterTransaction.with(new WebViewLoginController(userEntity.getBaseUrl(), true)).pushChangeHandler(new VerticalChangeHandler()).popChangeHandler(new VerticalChangeHandler())));
}
break;
default:
break;
}
}
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
dispose(roomsQueryDisposable);
}, () -> {
dispose(roomsQueryDisposable);
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
if (fromBottomSheet) {
new Handler().postDelayed(() -> {
bottomSheet.setCancelable(true);
if (bottomSheet.isShowing()) {
bottomSheet.cancel();
}
}, 2500);
}
});
}
use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.
the class SwitchAccountController method onViewBound.
@Override
protected void onViewBound(@NonNull View view) {
super.onViewBound(view);
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
swipeRefreshLayout.setEnabled(false);
if (adapter == null) {
adapter = new FlexibleAdapter<>(userItems, getActivity(), false);
UserEntity userEntity;
Participant participant;
if (!isAccountImport) {
for (Object userEntityObject : userUtils.getUsers()) {
userEntity = (UserEntity) userEntityObject;
if (!userEntity.getCurrent()) {
participant = new Participant();
participant.setName(userEntity.getDisplayName());
String userId;
if (userEntity.getUserId() != null) {
userId = userEntity.getUserId();
} else {
userId = userEntity.getUsername();
}
participant.setUserId(userId);
userItems.add(new AdvancedUserItem(participant, userEntity, null));
}
}
adapter.addListener(onSwitchItemClickListener);
adapter.updateDataSet(userItems, false);
} else {
if (getActionBar() != null) {
getActionBar().show();
}
Account account;
ImportAccount importAccount;
for (Object accountObject : AccountUtils.findAccounts(userUtils.getUsers())) {
account = (Account) accountObject;
importAccount = AccountUtils.getInformationFromAccount(account);
participant = new Participant();
participant.setName(importAccount.getUsername());
participant.setUserId(importAccount.getUsername());
userEntity = new UserEntity();
userEntity.setBaseUrl(importAccount.getBaseUrl());
userItems.add(new AdvancedUserItem(participant, userEntity, account));
}
adapter.addListener(onImportItemClickListener);
adapter.updateDataSet(userItems, false);
}
}
prepareViews();
}
use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.
the class PushUtils method pushRegistrationToServer.
public void pushRegistrationToServer() {
String token = appPreferences.getPushToken();
if (!TextUtils.isEmpty(token)) {
String pushTokenHash = generateSHA512Hash(token).toLowerCase();
PublicKey devicePublicKey = (PublicKey) readKeyFromFile(true);
if (devicePublicKey != null) {
byte[] publicKeyBytes = Base64.encode(devicePublicKey.getEncoded(), Base64.NO_WRAP);
String publicKey = new String(publicKeyBytes);
publicKey = publicKey.replaceAll("(.{64})", "$1\n");
publicKey = "-----BEGIN PUBLIC KEY-----\n" + publicKey + "\n-----END PUBLIC KEY-----\n";
if (userUtils.anyUserExists()) {
String providerValue;
PushConfigurationState accountPushData = null;
for (Object userEntityObject : userUtils.getUsers()) {
UserEntity userEntity = (UserEntity) userEntityObject;
providerValue = userEntity.getPushConfigurationState();
if (!TextUtils.isEmpty(providerValue)) {
try {
accountPushData = LoganSquare.parse(providerValue, PushConfigurationState.class);
} catch (IOException e) {
Log.d(TAG, "Failed to parse account push data");
accountPushData = null;
}
} else {
accountPushData = null;
}
if (accountPushData != null && !accountPushData.getPushToken().equals(token) && !userEntity.getScheduledForDeletion() || TextUtils.isEmpty(providerValue) && !userEntity.getScheduledForDeletion()) {
Map<String, String> queryMap = new HashMap<>();
queryMap.put("format", "json");
queryMap.put("pushTokenHash", pushTokenHash);
queryMap.put("devicePublicKey", publicKey);
queryMap.put("proxyServer", proxyServer);
ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class);
ncApi.registerDeviceForNotificationsWithNextcloud(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlNextcloudPush(userEntity.getBaseUrl()), queryMap).subscribeOn(Schedulers.newThread()).subscribe(new Observer<PushRegistrationOverall>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(PushRegistrationOverall pushRegistrationOverall) {
Map<String, String> proxyMap = new HashMap<>();
proxyMap.put("pushToken", token);
proxyMap.put("deviceIdentifier", pushRegistrationOverall.getOcs().getData().getDeviceIdentifier());
proxyMap.put("deviceIdentifierSignature", pushRegistrationOverall.getOcs().getData().getSignature());
proxyMap.put("userPublicKey", pushRegistrationOverall.getOcs().getData().getPublicKey());
ncApi.registerDeviceForNotificationsWithProxy(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlPushProxy(), proxyMap).subscribeOn(Schedulers.newThread()).subscribe(new Observer<Void>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Void aVoid) {
PushConfigurationState pushConfigurationState = new PushConfigurationState();
pushConfigurationState.setPushToken(token);
pushConfigurationState.setDeviceIdentifier(pushRegistrationOverall.getOcs().getData().getDeviceIdentifier());
pushConfigurationState.setDeviceIdentifierSignature(pushRegistrationOverall.getOcs().getData().getSignature());
pushConfigurationState.setUserPublicKey(pushRegistrationOverall.getOcs().getData().getPublicKey());
pushConfigurationState.setUsesRegularPass(false);
try {
userUtils.createOrUpdateUser(null, null, null, userEntity.getDisplayName(), LoganSquare.serialize(pushConfigurationState), null, null, userEntity.getId(), null).subscribe(new Observer<UserEntity>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(UserEntity userEntity) {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
} catch (IOException e) {
Log.e(TAG, "IOException while updating user");
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
}
}
}
}
}
Aggregations