Skip to content

Commit

Permalink
Don't return unresolved asynchronous recipients for non-async callers
Browse files Browse the repository at this point in the history
Fixes #6082
// FREEBIE
  • Loading branch information
moxie0 committed Jan 23, 2017
1 parent dadc8d0 commit 21a0fe3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/org/thoughtcrime/securesms/recipients/Recipient.java
Expand Up @@ -46,6 +46,7 @@ public class Recipient {
private @NonNull String number;
private @Nullable String name;
private boolean stale;
private boolean resolving;

private ContactPhoto contactPhoto;
private Uri contactUri;
Expand All @@ -61,6 +62,7 @@ public class Recipient {
this.number = number;
this.contactPhoto = ContactPhotoFactory.getLoadingPhoto();
this.color = null;
this.resolving = true;

if (stale != null) {
this.name = stale.name;
Expand All @@ -79,6 +81,7 @@ public void onSuccess(RecipientDetails result) {
Recipient.this.contactUri = result.contactUri;
Recipient.this.contactPhoto = result.avatar;
Recipient.this.color = result.color;
Recipient.this.resolving = false;
}

notifyListeners();
Expand All @@ -99,6 +102,7 @@ public void onFailure(Throwable error) {
this.name = details.name;
this.contactPhoto = details.avatar;
this.color = details.color;
this.resolving = false;
}

public synchronized @Nullable Uri getContactUri() {
Expand Down Expand Up @@ -193,4 +197,9 @@ boolean isStale() {
void setStale() {
this.stale = true;
}

synchronized boolean isResolving() {
return resolving;
}

}
10 changes: 7 additions & 3 deletions src/org/thoughtcrime/securesms/recipients/RecipientProvider.java
Expand Up @@ -49,7 +49,7 @@
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;

public class RecipientProvider {
class RecipientProvider {

private static final String TAG = RecipientProvider.class.getSimpleName();

Expand All @@ -72,7 +72,9 @@ public class RecipientProvider {

@NonNull Recipient getRecipient(Context context, long recipientId, boolean asynchronous) {
Recipient cachedRecipient = recipientCache.get(recipientId);
if (cachedRecipient != null && !cachedRecipient.isStale()) return cachedRecipient;
if (cachedRecipient != null && !cachedRecipient.isStale() && (asynchronous || !cachedRecipient.isResolving())) {
return cachedRecipient;
}

String number = CanonicalAddressDatabase.getInstance(context).getAddressFromId(recipientId);

Expand All @@ -88,7 +90,9 @@ public class RecipientProvider {

@NonNull Recipients getRecipients(Context context, long[] recipientIds, boolean asynchronous) {
Recipients cachedRecipients = recipientsCache.get(new RecipientIds(recipientIds));
if (cachedRecipients != null && !cachedRecipients.isStale()) return cachedRecipients;
if (cachedRecipients != null && !cachedRecipients.isStale() && (asynchronous || !cachedRecipients.isResolving())) {
return cachedRecipients;
}

List<Recipient> recipientList = new LinkedList<>();

Expand Down
8 changes: 8 additions & 0 deletions src/org/thoughtcrime/securesms/recipients/Recipients.java
Expand Up @@ -344,6 +344,14 @@ void setStale() {
this.stale = true;
}

boolean isResolving() {
for (Recipient recipient : recipients) {
if (recipient.isResolving()) return true;
}

return false;
}

public interface RecipientsModifiedListener {
public void onModified(Recipients recipient);
}
Expand Down

0 comments on commit 21a0fe3

Please sign in to comment.