diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/ApiProvider.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/ApiProvider.java index 1199e6e1cc34f8facc13374acae62b7935cae33f..0cab114eeb1f2140e0612397dd9ce0c2e67130a8 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/ApiProvider.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/ApiProvider.java @@ -38,7 +38,7 @@ public class ApiProvider { private static final ApiProvider INSTANCE = new ApiProvider(); - private static final String API_ENDPOINT_OCS = "/ocs/v1.php/cloud/"; + private static final String API_ENDPOINT_OCS = "/ocs/v2.php/cloud/"; private static final Map API_CACHE = new ConcurrentHashMap<>(); 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 8b8f79c413ea2f2a5673a36e6c3405e1b9ca50a5..d772981f0d02238fe5ad629de93b410ff326a0f7 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 @@ -1,22 +1,15 @@ package it.niedermann.owncloud.notes.persistence; import android.content.Context; -import trikita.log.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; -import com.nextcloud.android.sso.api.ParsedResponse; import com.nextcloud.android.sso.model.SingleSignOnAccount; -import java.util.Map; - -import it.niedermann.owncloud.notes.persistence.sync.OcsAPI; import it.niedermann.owncloud.notes.shared.model.Capabilities; -import it.niedermann.owncloud.notes.shared.model.OcsResponse; -import it.niedermann.owncloud.notes.shared.model.OcsUser; -import retrofit2.Response; +import trikita.log.Log; @WorkerThread public class CapabilitiesClient { @@ -53,7 +46,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(ssoAccount.userId).execute(); + final var userResponse = ocsAPI.getUser(sanitizeUserId(ssoAccount.userId)).execute(); if (userResponse.isSuccessful()) { final var ocsResponse = userResponse.body(); if (ocsResponse != null) { @@ -69,4 +62,21 @@ 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]; + } }