diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java index d772981f0d02238fe5ad629de93b410ff326a0f7..99fee65716de6f3952456e2365e061c6aeef654a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java @@ -9,6 +9,7 @@ import androidx.annotation.WorkerThread; import com.nextcloud.android.sso.model.SingleSignOnAccount; import it.niedermann.owncloud.notes.shared.model.Capabilities; +import it.niedermann.owncloud.notes.shared.util.SSOUtil; import trikita.log.Log; @WorkerThread @@ -46,7 +47,7 @@ public class CapabilitiesClient { public static String getDisplayName(@NonNull Context context, @NonNull SingleSignOnAccount ssoAccount, @NonNull ApiProvider apiProvider) { final var ocsAPI = apiProvider.getOcsAPI(context, ssoAccount); try { - final var userResponse = ocsAPI.getUser(sanitizeUserId(ssoAccount.userId)).execute(); + final var userResponse = ocsAPI.getUser(SSOUtil.sanitizeUserId(ssoAccount.userId)).execute(); if (userResponse.isSuccessful()) { final var ocsResponse = userResponse.body(); if (ocsResponse != null) { @@ -62,21 +63,4 @@ public class CapabilitiesClient { } return null; } - - /** - * Murena account's userId is set same as it's email address (passed by accountManager app). - * For old accounts (@e.email) userId = email. - * For new accounts (@murena.io) userId is first part of email (ex: for email abc@murena.io, userId is abc). - * For api requests, we needed to pass the actual userId. This method remove the unwanted part (@murena.io) from the userId - */ - @NonNull - private static String sanitizeUserId(@NonNull String userId) { - final String murenaMailEndPart = "@murena.io"; - - if (!userId.endsWith(murenaMailEndPart)) { - return userId; - } - - return userId.split(murenaMailEndPart)[0]; - } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java index 0aeb1bf49fd2ff8f6eb61e519394fa0894e1f7f1..0d1388d9c1df124169ed975346653bd0179244ad 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java @@ -107,6 +107,6 @@ public class DisplayUtils { @NonNull public static String getAvatarUrl(@NonNull Account account) { - return account.getUrl() + "/index.php/avatar/" + Uri.encode(account.getUserName()) + "/64"; + return account.getUrl() + "/index.php/avatar/" + Uri.encode(SSOUtil.sanitizeUserId(account.getUserName())) + "/64"; } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/SSOUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/SSOUtil.java index 115009aafcf2f26e2f872696ec47a5e7c3111563..1f2b48d48b9d29bab2fb55eb7e023d8d42089908 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/SSOUtil.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/SSOUtil.java @@ -49,4 +49,21 @@ public class SSOUtil { return false; } } + + /** + * Murena account's userId is set same as it's email address (passed by accountManager app). + * For old accounts (@e.email) userId = email. + * For new accounts (@murena.io) userId is first part of email (ex: for email abc@murena.io, userId is abc). + * For api requests, we needed to pass the actual userId. This method remove the unwanted part (@murena.io) from the userId + */ + @NonNull + public static String sanitizeUserId(@NonNull String userId) { + final String murenaMailEndPart = "@murena.io"; + + if (!userId.endsWith(murenaMailEndPart)) { + return userId; + } + + return userId.split(murenaMailEndPart)[0]; + } }