Skip to content

Commit

Permalink
Retrieve any keys for dummy Contact (fix #973)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ricci <[email protected]>
  • Loading branch information
daniele-athome committed Mar 10, 2017
1 parent c512deb commit 9089f4d
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions app/src/main/java/org/kontalk/data/Contact.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,14 +521,7 @@ public static Contact fromUsersCursor(Context context, Cursor cursor) {
c.mRegistered = registered;
c.mStatus = status;

// trusted key
Keyring.TrustedPublicKeyData trustedKeyring = Keyring.getPublicKeyData(context, jid, Keys.TRUST_IGNORED);
// latest (possibly unknown) fingerprint
c.mFingerprint = Keyring.getFingerprint(context, jid, Keys.TRUST_UNKNOWN);
if (trustedKeyring != null) {
c.mTrustedKeyRing = new PGPLazyPublicKeyRingLoader(trustedKeyring.keyData);
c.mTrustedLevel = trustedKeyring.trustLevel;
}
retrieveKeyInfo(context, c);

cache.put(jid, c);
}
Expand Down Expand Up @@ -562,11 +555,27 @@ public static Contact findByUserId(Context context, @NonNull String userId) {
public static Contact findByUserId(Context context, @NonNull String userId, String numberHint) {
Contact c = cache.get(context, userId, numberHint);
// build dummy contact if not found
if (c == null)
if (c == null) {
c = new Contact(-1, null, userId, numberHint, userId, false);
// try to retrieve the key from the keyring
// We may find one for pending subscription users which have
// disappeared from the users table after a resync
retrieveKeyInfo(context, c);
}
return c;
}

private static void retrieveKeyInfo(Context context, Contact c) {
// trusted key
Keyring.TrustedPublicKeyData trustedKeyring = Keyring.getPublicKeyData(context, c.getJID(), Keys.TRUST_IGNORED);
// latest (possibly unknown) fingerprint
c.mFingerprint = Keyring.getFingerprint(context, c.getJID(), Keys.TRUST_UNKNOWN);
if (trustedKeyring != null) {
c.mTrustedKeyRing = new PGPLazyPublicKeyRingLoader(trustedKeyring.keyData);
c.mTrustedLevel = trustedKeyring.trustLevel;
}
}

static Contact _findByUserId(Context context, String userId) {
ContentResolver cres = context.getContentResolver();
Cursor c = cres.query(Uri.withAppendedPath(Users.CONTENT_URI, userId),
Expand Down Expand Up @@ -594,14 +603,7 @@ static Contact _findByUserId(Context context, String userId) {
contact.mRegistered = registered;
contact.mStatus = status;

// trusted key
Keyring.TrustedPublicKeyData trustedKeyring = Keyring.getPublicKeyData(context, userId, Keys.TRUST_IGNORED);
// latest (possibly unknown) fingerprint
contact.mFingerprint = Keyring.getFingerprint(context, userId, Keys.TRUST_UNKNOWN);
if (trustedKeyring != null) {
contact.mTrustedKeyRing = new PGPLazyPublicKeyRingLoader(trustedKeyring.keyData);
contact.mTrustedLevel = trustedKeyring.trustLevel;
}
retrieveKeyInfo(context, contact);

return contact;
}
Expand Down

0 comments on commit 9089f4d

Please sign in to comment.