mirror of
https://github.com/nextcloud/talk-android
synced 2025-02-01 20:22:03 +00:00
handling error 429 in phonebook sync
Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
This commit is contained in:
parent
d2ad9775b0
commit
79af073d5a
@ -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
|
||||
@ -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) {
|
||||
@ -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) ==
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user