Skip to content

Commit

Permalink
Merge pull request #3342 from nextcloud/issue-3340-phonebook-sync-info
Browse files Browse the repository at this point in the history
Error 429 "Too Many Requests" is now handled
  • Loading branch information
mahibi authored Sep 29, 2023
2 parents d2ad977 + 79af073 commit fd643da
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import android.net.Uri
import android.os.RemoteException
import android.provider.ContactsContract
import android.util.Log
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.core.os.ConfigurationCompat
import androidx.work.Data
Expand Down Expand Up @@ -143,9 +144,22 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
}

override fun onNext(foundContacts: ContactsByNumberOverall) {
val contactsWithAssociatedPhoneNumbers = foundContacts.ocs!!.map
deleteLinkedAccounts(contactsWithAssociatedPhoneNumbers)
createLinkedAccounts(contactsWithAssociatedPhoneNumbers)
when (foundContacts.ocs?.meta?.statusCode) {
HTTP_CODE_TOO_MANY_REQUESTS -> {
Toast.makeText(
context,
context.resources.getString(
R.string.nc_settings_phone_book_integration_phone_number_dialog_429
),
Toast.LENGTH_SHORT
).show()
}
else -> {
val contactsWithAssociatedPhoneNumbers = foundContacts.ocs!!.map
deleteLinkedAccounts(contactsWithAssociatedPhoneNumbers)
createLinkedAccounts(contactsWithAssociatedPhoneNumbers)
}
}
}

override fun onError(e: Throwable) {
Expand Down Expand Up @@ -449,6 +463,7 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
const val REQUEST_PERMISSION = 231
const val KEY_FORCE = "KEY_FORCE"
const val DELETE_ALL = "DELETE_ALL"
private const val HTTP_CODE_TOO_MANY_REQUESTS: Int = 429

fun run(context: Context) {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_CONTACTS) ==
Expand Down
34 changes: 18 additions & 16 deletions app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1079,21 +1079,23 @@ class SettingsActivity : BaseActivity() {
}

override fun onNext(genericOverall: GenericOverall) {
val statusCode = genericOverall.ocs?.meta?.statusCode
if (statusCode == HTTP_CODE) {
dialog.dismiss()
Snackbar.make(
binding.root,
context.resources.getString(
R.string.nc_settings_phone_book_integration_phone_number_dialog_success
),
Snackbar.LENGTH_LONG
).show()
} else {
textInputLayout.helperText = context.resources.getString(
R.string.nc_settings_phone_book_integration_phone_number_dialog_invalid
)
Log.d(TAG, "failed to set phoneNumber. statusCode=$statusCode")
when (val statusCode = genericOverall.ocs?.meta?.statusCode) {
HTTP_CODE_OK -> {
dialog.dismiss()
Snackbar.make(
binding.root,
context.resources.getString(
R.string.nc_settings_phone_book_integration_phone_number_dialog_success
),
Snackbar.LENGTH_LONG
).show()
}
else -> {
textInputLayout.helperText = context.resources.getString(
R.string.nc_settings_phone_book_integration_phone_number_dialog_invalid
)
Log.d(TAG, "failed to set phoneNumber. statusCode=$statusCode")
}
}
}

Expand Down Expand Up @@ -1181,7 +1183,7 @@ class SettingsActivity : BaseActivity() {
private const val START_DELAY: Long = 5000
private const val DISABLED_ALPHA: Float = 0.38f
private const val ENABLED_ALPHA: Float = 1.0f
private const val HTTP_CODE: Int = 200
private const val HTTP_CODE_OK: Int = 200
private const val PHONE_NUMBER_SIDE_PADDING: Int = 50
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -706,5 +706,6 @@ How to translate with transifex:
<string name="custom">Custom</string>
<string name="set">Set</string>
<string name="calendar">Calendar</string>
<string name="nc_settings_phone_book_integration_phone_number_dialog_429">Error 429 Too Many Requests</string>

</resources>

0 comments on commit fd643da

Please sign in to comment.