use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.
the class UserUtils method checkIfUserIsScheduledForDeletion.
public boolean checkIfUserIsScheduledForDeletion(String username, String server) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username)).and(UserEntity.BASE_URL.eq(server)).limit(1).get();
UserEntity userEntity;
if ((userEntity = (UserEntity) findUserQueryResult.firstOrNull()) != null) {
return userEntity.getScheduledForDeletion();
}
return false;
}
use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.
the class UserUtils method createOrUpdateUser.
public Observable<UserEntity> createOrUpdateUser(@Nullable String username, @Nullable String token, @Nullable String serverUrl, @Nullable String displayName, @Nullable String pushConfigurationState, @Nullable Boolean currentUser, @Nullable String userId, @Nullable Long internalId, @Nullable String capabilities) {
Result findUserQueryResult;
if (internalId == null) {
findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username).and(UserEntity.BASE_URL.eq(serverUrl))).limit(1).get();
} else {
findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(internalId)).get();
}
UserEntity user = (UserEntity) findUserQueryResult.firstOrNull();
if (user == null) {
user = new UserEntity();
user.setBaseUrl(serverUrl);
user.setUsername(username);
user.setToken(token);
if (!TextUtils.isEmpty(displayName)) {
user.setDisplayName(displayName);
}
if (pushConfigurationState != null) {
user.setPushConfigurationState(pushConfigurationState);
}
if (!TextUtils.isEmpty(userId)) {
user.setUserId(userId);
}
if (!TextUtils.isEmpty(capabilities)) {
user.setCapabilities(capabilities);
}
user.setCurrent(true);
} else {
if (userId != null && (user.getUserId() == null || !user.getUserId().equals(userId))) {
user.setUserId(userId);
}
if (token != null && !token.equals(user.getToken())) {
user.setToken(token);
}
if ((displayName != null && user.getDisplayName() == null) || (displayName != null && user.getDisplayName() != null && !displayName.equals(user.getDisplayName()))) {
user.setDisplayName(displayName);
}
if (pushConfigurationState != null && !pushConfigurationState.equals(user.getPushConfigurationState())) {
user.setPushConfigurationState(pushConfigurationState);
}
if (capabilities != null && !capabilities.equals(user.getCapabilities())) {
user.setCapabilities(capabilities);
}
if (currentUser != null) {
user.setCurrent(currentUser);
}
}
return dataStore.upsert(user).toObservable().subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread());
}
use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.
the class UserUtils method deleteUser.
public Completable deleteUser(String username, String serverUrl) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username).and(UserEntity.BASE_URL.eq(serverUrl))).limit(1).get();
UserEntity user = (UserEntity) findUserQueryResult.firstOrNull();
return dataStore.delete(user).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread());
}
use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.
the class PushUtils method verifySignature.
public SignatureVerification verifySignature(byte[] signatureBytes, byte[] subjectBytes) {
Signature signature = null;
PushConfigurationState pushConfigurationState;
PublicKey publicKey;
SignatureVerification signatureVerification = new SignatureVerification();
signatureVerification.setSignatureValid(false);
List<UserEntity> userEntities = userUtils.getUsers();
try {
signature = Signature.getInstance("SHA512withRSA");
if (userEntities != null && userEntities.size() > 0) {
for (UserEntity userEntity : userEntities) {
if (!TextUtils.isEmpty(userEntity.getPushConfigurationState())) {
pushConfigurationState = LoganSquare.parse(userEntity.getPushConfigurationState(), PushConfigurationState.class);
publicKey = (PublicKey) readKeyFromString(true, pushConfigurationState.getUserPublicKey());
signature.initVerify(publicKey);
signature.update(subjectBytes);
if (signature.verify(signatureBytes)) {
signatureVerification.setSignatureValid(true);
signatureVerification.setUserEntity(userEntity);
return signatureVerification;
}
}
}
}
} catch (NoSuchAlgorithmException e) {
Log.d(TAG, "No such algorithm");
} catch (IOException e) {
Log.d(TAG, "Error while trying to parse push configuration state");
} catch (InvalidKeyException e) {
Log.d(TAG, "Invalid key while trying to verify");
} catch (SignatureException e) {
Log.d(TAG, "Signature exception while trying to verify");
}
return signatureVerification;
}
use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.
the class ShareUtils method getStringForIntent.
public static String getStringForIntent(Context context, @Nullable String password, UserUtils userUtils, Room room) {
UserEntity userEntity = userUtils.getCurrentUser();
String shareString = "";
if (userEntity != null && context != null) {
shareString = String.format(context.getResources().getString(R.string.nc_share_text), userEntity.getBaseUrl(), room.getToken());
if (!TextUtils.isEmpty(password)) {
shareString += String.format(context.getResources().getString(R.string.nc_share_text_pass), password);
}
}
return shareString;
}
Aggregations