Merge pull request #1059 from nextcloud/fixPhonebookIntegration

Fix phonebook integration
This commit is contained in:
Marcel Hibbe 2021-03-17 16:07:53 +01:00 committed by GitHub
commit 808d68ecec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 32 deletions

View file

@ -171,8 +171,8 @@ class MainActivity : BaseActivity(), ActionBarProvider {
when (intent.type) { when (intent.type) {
"vnd.android.cursor.item/vnd.com.nextcloud.talk2.chat" -> { "vnd.android.cursor.item/vnd.com.nextcloud.talk2.chat" -> {
val user = userId.split("@")[0] val user = userId.substringBeforeLast("@")
val baseUrl = userId.split("@")[1] val baseUrl = userId.substringAfterLast("@")
if (userUtils.currentUser?.baseUrl?.endsWith(baseUrl) == true) { if (userUtils.currentUser?.baseUrl?.endsWith(baseUrl) == true) {
startConversation(user) startConversation(user)
} else { } else {

View file

@ -86,45 +86,45 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
} }
} }
AccountManager.get(context).addAccountExplicitly(Account(ACCOUNT_NAME, ACCOUNT_TYPE), "", null) if(AccountManager.get(context).getAccountsByType(ACCOUNT_TYPE).isEmpty()){
AccountManager.get(context).addAccountExplicitly(Account(ACCOUNT_NAME, ACCOUNT_TYPE), "", null)
}
// collect all contacts with phone number // collect all contacts with phone number
val contactsWithNumbers = collectPhoneNumbers() val contactsWithNumbers = collectPhoneNumbers()
val currentLocale = ConfigurationCompat.getLocales(context.resources.configuration)[0].country if(contactsWithNumbers.isNotEmpty()){
val currentLocale = ConfigurationCompat.getLocales(context.resources.configuration)[0].country
val map = mutableMapOf<String, Any>() val map = mutableMapOf<String, Any>()
map["location"] = currentLocale map["location"] = currentLocale
map["search"] = contactsWithNumbers map["search"] = contactsWithNumbers
val json = Gson().toJson(map) val json = Gson().toJson(map)
ncApi.searchContactsByPhoneNumber( ncApi.searchContactsByPhoneNumber(
ApiUtils.getCredentials(currentUser.username, currentUser.token), ApiUtils.getCredentials(currentUser.username, currentUser.token),
ApiUtils.getUrlForSearchByNumber(currentUser.baseUrl), ApiUtils.getUrlForSearchByNumber(currentUser.baseUrl),
RequestBody.create(MediaType.parse("application/json"), json)) RequestBody.create(MediaType.parse("application/json"), json))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<ContactsByNumberOverall> { .subscribe(object : Observer<ContactsByNumberOverall> {
override fun onComplete() { override fun onComplete() {
} }
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
} }
override fun onNext(foundContacts: ContactsByNumberOverall) { override fun onNext(foundContacts: ContactsByNumberOverall) {
Log.d(javaClass.simpleName, "next") up(foundContacts)
}
// todo update override fun onError(e: Throwable) {
up(foundContacts) Log.e(javaClass.simpleName, "Failed to searchContactsByPhoneNumber", e)
} }
override fun onError(e: Throwable) { })
// TODO error handling }
Log.d(javaClass.simpleName, "error")
}
})
// store timestamp // store timestamp
appPreferences.setPhoneBookIntegrationLastRun(System.currentTimeMillis()) appPreferences.setPhoneBookIntegrationLastRun(System.currentTimeMillis())
@ -321,9 +321,9 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
try { try {
context.contentResolver.applyBatch(ContactsContract.AUTHORITY, ops) context.contentResolver.applyBatch(ContactsContract.AUTHORITY, ops)
} catch (e: OperationApplicationException) { } catch (e: OperationApplicationException) {
e.printStackTrace() Log.e(javaClass.simpleName, "", e)
} catch (e: RemoteException) { } catch (e: RemoteException) {
e.printStackTrace() Log.e(javaClass.simpleName, "", e)
} }
} }