Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP. Fix failing login etc #4700

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.work.WorkInfo
import androidx.work.WorkManager
import autodagger.AutoInjector
import com.bluelinelabs.logansquare.LoganSquare
import com.google.android.material.snackbar.Snackbar
import com.nextcloud.talk.R
import com.nextcloud.talk.activities.BaseActivity
import com.nextcloud.talk.api.NcApi
Expand Down Expand Up @@ -240,7 +239,7 @@ class AccountVerificationActivity : BaseActivity() {
UserManager.UserAttributes(
id = null,
serverUrl = baseUrl,
currentUser = true,
currentUser = false,
userId = userId,
token = token,
displayName = displayName,
Expand All @@ -259,25 +258,32 @@ class AccountVerificationActivity : BaseActivity() {

@SuppressLint("SetTextI18n")
override fun onSuccess(user: User) {
internalAccountId = user.id!!
if (ClosedInterfaceImpl().isGooglePlayServicesAvailable) {
ClosedInterfaceImpl().setUpPushTokenRegistration()
} else {
Log.w(TAG, "Skipping push registration.")
runOnUiThread {
binding.progressText.text =
""" ${binding.progressText.text}
if (userManager.setUserAsActive(user).blockingGet()) {
internalAccountId = user.id!!
if (ClosedInterfaceImpl().isGooglePlayServicesAvailable) {
ClosedInterfaceImpl().setUpPushTokenRegistration()
} else {
Log.w(TAG, "Skipping push registration.")
runOnUiThread {
binding.progressText.text =
""" ${binding.progressText.text}
${resources!!.getString(R.string.nc_push_disabled)}
""".trimIndent()
""".trimIndent()
}
fetchAndStoreCapabilities()
}
fetchAndStoreCapabilities()
} else {
Log.e(TAG, "Failed to set user active")
binding.progressText.text = """ ${binding.progressText.text}""".trimIndent() +
resources!!.getString(R.string.nc_common_error_sorry)
abortVerification()
}
}

@SuppressLint("SetTextI18n")
override fun onError(e: Throwable) {
binding.progressText.text = """ ${binding.progressText.text}""".trimIndent() +
resources!!.getString(R.string.nc_display_name_not_stored)
resources!!.getString(R.string.nc_common_error_sorry)
abortVerification()
}

Expand Down Expand Up @@ -371,16 +377,25 @@ class AccountVerificationActivity : BaseActivity() {
fetchAndStoreExternalSignalingSettings()
}
} else if (eventStatus.eventType == EventStatus.EventType.SIGNALING_SETTINGS) {
if (internalAccountId == eventStatus.userId && !eventStatus.isAllGood) {
runOnUiThread {
binding.progressText.text =
"""
if (internalAccountId == eventStatus.userId) {
if (eventStatus.isAllGood) {
proceedWithLogin()
} else {
runOnUiThread {
binding.progressText.text =
"""
${binding.progressText.text}
${resources!!.getString(R.string.nc_external_server_failed)}
""".trimIndent()
""".trimIndent()
}
}
} else {
Log.d(
TAG,
"got SIGNALING_SETTINGS, internalAccountId=$internalAccountId , eventStatus.userId=" +
eventStatus.userId
)
}
proceedWithLogin()
}
}

Expand Down Expand Up @@ -414,33 +429,27 @@ class AccountVerificationActivity : BaseActivity() {

private fun proceedWithLogin() {
cookieManager.cookieStore.removeAll()

if (userManager.users.blockingGet().size == 1 ||
currentUserProvider.currentUser.blockingGet().id != internalAccountId
) {
val userToSetAsActive = userManager.getUserWithId(internalAccountId).blockingGet()
Log.d(TAG, "userToSetAsActive: " + userToSetAsActive.username)

if (userManager.setUserAsActive(userToSetAsActive).blockingGet()) {
runOnUiThread {
if (userManager.users.blockingGet().size == 1) {
val intent = Intent(context, ConversationsListActivity::class.java)
startActivity(intent)
} else {
if (isAccountImport) {
ApplicationWideMessageHolder.getInstance().messageType =
ApplicationWideMessageHolder.MessageType.ACCOUNT_WAS_IMPORTED
}
val intent = Intent(context, ConversationsListActivity::class.java)
startActivity(intent)
}
}
} else {
Log.e(TAG, "failed to set active user")
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
// make sure currentUser is already set! otherwise: continuing proceedWithLogin was skipped for this user

// val usersAmount = userManager.users.blockingGet().size
// val currentUserId = currentUserProvider.currentUser.blockingGet().id

// Log.d(TAG, "usersAmount in proceedWithLogin: $usersAmount")
// Log.d(TAG, "currentUserId in proceedWithLogin: $currentUserId")
Log.d(TAG, "internalAccountId in proceedWithLogin: $internalAccountId")

runOnUiThread {
// if (usersAmount == 1) {
// val intent = Intent(context, ConversationsListActivity::class.java)
// startActivity(intent)
// } else {
if (isAccountImport) {
ApplicationWideMessageHolder.getInstance().messageType =
ApplicationWideMessageHolder.MessageType.ACCOUNT_WAS_IMPORTED
}
} else {
Log.d(TAG, "continuing proceedWithLogin was skipped for this user")
val intent = Intent(context, ConversationsListActivity::class.java)
startActivity(intent)
// }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,7 @@ class ConversationsListActivity :

@SuppressLint("CheckResult")
private fun deleteUserAndRestartApp() {
val userToDeleteDisplayName = currentUser!!.displayName
userManager.scheduleUserForDeletionWithId(currentUser!!.id!!).blockingGet()
val accountRemovalWork = OneTimeWorkRequest.Builder(AccountRemovalWorker::class.java).build()
WorkManager.getInstance(applicationContext).enqueue(accountRemovalWork)
Expand All @@ -1791,7 +1792,7 @@ class ConversationsListActivity :
WorkInfo.State.SUCCEEDED -> {
val text = String.format(
context.resources.getString(R.string.nc_deleted_user),
currentUser!!.displayName
userToDeleteDisplayName
)
Toast.makeText(
context,
Expand All @@ -1807,7 +1808,7 @@ class ConversationsListActivity :
context.resources.getString(R.string.nc_common_error_sorry),
Toast.LENGTH_LONG
).show()
Log.e(TAG, "something went wrong when deleting user with id " + currentUser!!.userId)
Log.e(TAG, "something went wrong when deleting user")
restartApp()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ abstract class TalkDatabase : RoomDatabase() {
return Room
.databaseBuilder(context.applicationContext, TalkDatabase::class.java, dbName)
// comment out openHelperFactory to view the database entries in Android Studio for debugging
.openHelperFactory(factory)
// .openHelperFactory(factory)
.addMigrations(
Migrations.MIGRATION_6_8,
Migrations.MIGRATION_7_8,
Expand Down
Loading