Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
resolves #54 where Google contacts that were entirely invisible to th…
Browse files Browse the repository at this point in the history
…e user were being copied over and made visible on import of Google accounts to Flock. these invisible contacts were either exact duplicates of visible contacts or email addresses from which the user received an email but never replied, starred, archived, or otherwise interacted with in any way.
  • Loading branch information
rhodey committed Sep 11, 2014
1 parent 114b3d6 commit 3a42de6
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public class ContactFactory {
private static final String PROPERTY_EVENT_CUSTOM = "X-EVENT-CUSTOM";
private static final String PARAMETER_EVENT_CUSTOM_LABEL = "X-EVENT-CUSTOM-LABEL";

private static final String PROPERTY_INVISIBLE_CONTACT = "X-INVISIBLE-CONTACT";

private static String propertyNameToLabel(String propertyName) {
return WordUtils.capitalize(propertyName.toLowerCase().replace("x-", "").replace("_", " "));
}
Expand Down Expand Up @@ -1264,4 +1266,23 @@ protected static void addSipAddress(VCard vCard, ContentValues sipAddressValues)
vCard.setExtendedProperty(PROPERTY_SIP, sipAddress);
}

protected static String[] getProjectionForGroupMembership() {
return new String[] {
ContactsContract.Data.DATA1, // 00
};
}

protected static Long getIdForGroupMembership(Cursor cursor) {
return cursor.getLong(0);
}

protected static void addInvisibleProperty(VCard vCard) {
Log.d(TAG, "addInvisibleProperty()");
vCard.addExtendedProperty(PROPERTY_INVISIBLE_CONTACT, "true");
}

protected static boolean hasInvisibleProperty(VCard vCard) {
return vCard.getExtendedProperty(PROPERTY_INVISIBLE_CONTACT) != null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -458,21 +458,74 @@ private void addSipAddresses(Long rawContactId, VCard vCard)
cursor.close();
}

private List<Long> getGroupIdsForContact(Long rawContactId)
throws RemoteException
{
String SELECTION = getColumnNameComponentDataLocalId() + "=? " +
"AND " + ContactsContract.Data.MIMETYPE + "=?";
String[] SELECTION_ARGS = new String[] {
rawContactId.toString(),
ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE
};

List<Long> groupIds = new LinkedList<Long>();
Cursor cursor = client.query(getUriForData(),
ContactFactory.getProjectionForGroupMembership(),
SELECTION,
SELECTION_ARGS,
null);

while (cursor.moveToNext())
groupIds.add(ContactFactory.getIdForGroupMembership(cursor));

cursor.close();
return groupIds;
}

private boolean isContactWithoutGroupVisible()
throws RemoteException
{
boolean contactWithoutGroupVisible = true;
Cursor cursor = client.query(getSyncAdapterUri(ContactsContract.Settings.CONTENT_URI),
new String[] {
ContactsContract.Settings.UNGROUPED_VISIBLE,
},
null,
null,
null);

if (cursor.moveToNext())
contactWithoutGroupVisible = cursor.getInt(0) != 0;

cursor.close();
return contactWithoutGroupVisible;
}

private void addInvisibleProperty(Long rawContactId, VCard vCard)
throws RemoteException
{
boolean isMemberOfGroup = getGroupIdsForContact(rawContactId).size() > 0;

if (!isMemberOfGroup && !isContactWithoutGroupVisible())
ContactFactory.addInvisibleProperty(vCard);
}

private void buildContact(Long rawContactId, VCard vCard)
throws InvalidComponentException, RemoteException
{
addStructuredNames( rawContactId, vCard);
addPhoneNumbers( rawContactId, vCard);
addEmailAddresses( rawContactId, vCard);
addPhotos(rawContactId, vCard);
addOrganizations( rawContactId, vCard);
addInstantMessaging(rawContactId, vCard);
addNickNames( rawContactId, vCard);
addNotes( rawContactId, vCard);
addPostalAddresses( rawContactId, vCard);
addWebsites( rawContactId, vCard);
addEvents( rawContactId, vCard);
addSipAddresses( rawContactId, vCard);
addStructuredNames( rawContactId, vCard);
addPhoneNumbers( rawContactId, vCard);
addEmailAddresses( rawContactId, vCard);
addPhotos( rawContactId, vCard);
addOrganizations( rawContactId, vCard);
addInstantMessaging( rawContactId, vCard);
addNickNames( rawContactId, vCard);
addNotes( rawContactId, vCard);
addPostalAddresses( rawContactId, vCard);
addWebsites( rawContactId, vCard);
addEvents( rawContactId, vCard);
addSipAddresses( rawContactId, vCard);
addInvisibleProperty(rawContactId, vCard);
}

@Override
Expand Down Expand Up @@ -561,7 +614,9 @@ public List<ComponentETagPair<VCard>> getComponents()
}

@Override
public void addComponent(ComponentETagPair<VCard> vCard) throws InvalidComponentException {
public void addComponent(ComponentETagPair<VCard> vCard)
throws InvalidComponentException, RemoteException
{
ContentValues rawContactValues = ContactFactory.getValuesForRawContact(vCard);

int raw_contact_op_index = pendingOperations.size();
Expand Down Expand Up @@ -694,12 +749,17 @@ public void copyToAccount(Account toAccount, ContactCopiedListener listener)

Optional<VCard> copyContact = getComponent(contactId);
if (copyContact.isPresent()) {
copyContact.get().setUid(null);
ComponentETagPair<VCard> correctedContact =
new ComponentETagPair<VCard>(copyContact.get(), Optional.<String>absent());
if (!ContactFactory.hasInvisibleProperty(copyContact.get())) {
copyContact.get().setUid(null);
ComponentETagPair<VCard> correctedContact =
new ComponentETagPair<VCard>(copyContact.get(), Optional.<String>absent());

toCollection.addComponent(correctedContact);
toCollection.commitPendingOperations();
}
else
Log.w(TAG, "contact is entirely invisible to the user, skipping.");

toCollection.addComponent(correctedContact);
toCollection.commitPendingOperations();
listener.onContactCopied(getAccount(), toAccount);
}
else
Expand Down

1 comment on commit 3a42de6

@WhisperBTC
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! BitHub has sent payment of $18.51USD for this commit.

Please sign in to comment.