Added developper setting button to delete orphan auth info

This commit is contained in:
Sylvain Berfini 2026-02-16 10:56:44 +01:00
parent 8c0499a1ef
commit 2a815972ff
4 changed files with 75 additions and 6 deletions

View file

@ -1235,4 +1235,34 @@ class SettingsViewModel
showGreenToast(R.string.settings_developer_cleared_native_friends_in_database_toast, R.drawable.trash_simple)
}
}
@UiThread
fun clearOrphanAuthInfo() {
coreContext.postOnCoreThread { core ->
var count = 0
for (authInfo in core.authInfoList) {
val username = authInfo.username
if (username == null) {
Log.i("$TAG Removing auth info [$authInfo] without username")
core.removeAuthInfo(authInfo)
count += 1
} else {
val account = core.accountList.find {
it.params.identityAddress?.username == username
}
if (account == null) {
Log.i("$TAG Removing auth info [$authInfo] with username [$username] for which no account was found")
core.removeAuthInfo(authInfo)
count += 1
}
}
}
if (count == 0) {
showGreenToast(R.string.settings_developer_no_auth_info_removed_toast, R.drawable.trash_simple)
} else {
val message = AppUtils.getStringWithPlural(R.plurals.settings_developer_cleared_auth_info_toast, count, "$count")
showFormattedGreenToast(message, R.drawable.warning_circle)
}
}
}
}

View file

@ -315,21 +315,25 @@
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/settings_title_style"
style="@style/tertiary_button_label_style"
android:id="@+id/clear_friends_db_label"
android:onClick="@{() -> viewModel.clearNativeFriendsDatabase()}"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="10dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="20dp"
android:background="@drawable/tertiary_button_background"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:gravity="center"
android:text="@string/settings_developer_clear_native_friends_in_database_title"
android:maxLines="2"
android:ellipsize="end"
android:drawablePadding="5dp"
android:drawableEnd="@drawable/warning_circle"
android:drawableTint="?attr/color_main2_600"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/push_compatible_domains_list"/>
<androidx.appcompat.widget.AppCompatTextView
@ -346,7 +350,30 @@
app:layout_constraintVertical_bias="0"
app:layout_constraintTop_toBottomOf="@id/clear_friends_db_label"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/tertiary_button_label_style"
android:id="@+id/clear_orphan_auth_info"
android:onClick="@{() -> viewModel.clearOrphanAuthInfo()}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:background="@drawable/tertiary_button_background"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:gravity="center"
android:text="@string/settings_developer_clear_orphan_auth_info_title"
android:maxLines="2"
android:ellipsize="end"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/clear_friends_db_subtitle"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -332,6 +332,12 @@
<string name="settings_developer_clear_native_friends_in_database_title">Supprimer les contacts natifs importés</string>
<string name="settings_developer_clear_native_friends_in_database_subtitle">Ils seront synchronisés à nouveau au prochain démarrage de l\'application sauf si vous retirez la permission de lire les contacts</string>
<string name="settings_developer_cleared_native_friends_in_database_toast">Contacts importés supprimés</string>
<string name="settings_developer_clear_orphan_auth_info_title">Supprimer les informations d\'authentification orphelines</string>
<string name="settings_developer_no_auth_info_removed_toast">Aucune information d\'authentification orpheline trouvée</string>
<plurals name="settings_developer_cleared_auth_info_toast" tools:ignore="MissingQuantity">
<item quantity="one">%s information d\'authentification supprimée</item>
<item quantity="other">%s informations d\'authentification supprimées</item>
</plurals>
<!-- Account profile & settings -->
<string name="manage_account_title">Mon compte</string>

View file

@ -374,6 +374,12 @@
<string name="settings_developer_clear_native_friends_in_database_title">Clear imported contacts from native address book</string>
<string name="settings_developer_clear_native_friends_in_database_subtitle">They will be imported again the next time the app starts unless you remove the contacts permission</string>
<string name="settings_developer_cleared_native_friends_in_database_toast">Imported contacts have been deleted</string>
<string name="settings_developer_clear_orphan_auth_info_title">Clear authentication info no longer associated to any account</string>
<string name="settings_developer_no_auth_info_removed_toast">No orphan authentication info found</string>
<plurals name="settings_developer_cleared_auth_info_toast">
<item quantity="one">%s orphan authentication info removed</item>
<item quantity="other">%s orphans authentication info removed</item>
</plurals>
<!-- Account profile & settings -->
<string name="manage_account_title">Manage account</string>