From dc18f73594cc95c7a65db38fe65b22d7e261dd0b Mon Sep 17 00:00:00 2001 From: AndHell Date: Tue, 11 Apr 2017 18:48:22 +0200 Subject: [PATCH] update contact query update query to remove duplicated numbers Fixes #4191 Closes #6475 --- .../thoughtcrime/securesms/contacts/ContactsDatabase.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/org/thoughtcrime/securesms/contacts/ContactsDatabase.java b/src/org/thoughtcrime/securesms/contacts/ContactsDatabase.java index 7208adcc86..8b4b37b18d 100644 --- a/src/org/thoughtcrime/securesms/contacts/ContactsDatabase.java +++ b/src/org/thoughtcrime/securesms/contacts/ContactsDatabase.java @@ -161,9 +161,11 @@ public class ContactsDatabase { put(LABEL_COLUMN, ContactsContract.CommonDataKinds.Phone.LABEL); }}; - String excludeSelection = ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " NOT IN (" + - "SELECT data.contact_id FROM raw_contacts, view_data data WHERE raw_contacts._id = data.raw_contact_id AND " + - "data.mimetype = '" + CONTACT_MIMETYPE + "')"; + String formattedNumber = "REPLACE(REPLACE(REPLACE(REPLACE(data1,' ',''),'-',''),'(',''),')','')"; + String excludeSelection = "(" + formattedNumber +" NOT IN " + + "(SELECT data1 FROM view_data WHERE "+formattedNumber+" = data1) " + + "OR "+formattedNumber+" = data1)" + + "AND " + formattedNumber + "NOT IN (SELECT "+formattedNumber+" FROM view_data where mimetype = '"+CONTACT_MIMETYPE+"')" ; String fallbackSelection = ContactsContract.Data.SYNC2 + " IS NULL OR " + ContactsContract.Data.SYNC2 + " != '" + SYNC + "'";