Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 74e5b22c authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

AM: Return list from getByAccountName and update getUserId

parent 28ec8c80
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ interface ServiceDao {
    suspend fun getByAccountAndType(accountName: String, @ServiceType type: String): Service?

    @Query("SELECT * FROM service WHERE accountName=:accountName")
    suspend fun getByAccountName(accountName: String): Service?
    suspend fun getByAccountName(accountName: String): List<Service?>

    @Query("SELECT * FROM service WHERE accountName=:accountName AND type=:type")
    fun getByAccountAndTypeFlow(accountName: String, @ServiceType type: String): Flow<Service?>
+7 −3
Original line number Diff line number Diff line
@@ -117,11 +117,15 @@ class SsoGrantPermissionViewModel @Inject constructor(

    private suspend fun getUserId(account: Account): String {
        val accountManager = AccountManager.get(context)
        val userId = accountManager.getUserData(account, AccountUtils.Constants.KEY_USER_ID)
        if (!userId.isNullOrBlank()) return userId
        accountManager.getUserData(account, AccountUtils.Constants.KEY_USER_ID)
            ?.takeIf { it.isNotBlank() }
            ?.let { return it }

        val principalUrl = database.serviceDao()
            .getByAccountName(account.name)?.principal?.toString()
            .getByAccountName(account.name)
            .firstOrNull()
            ?.principal
            ?.toString()

        return principalUrl?.let { UserIdFetcher.fetch(it) } ?: account.name
    }