mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-28 02:37:46 +00:00
Don't return unresolved asynchronous recipients for non-async callers
Fixes #6082 // FREEBIE
This commit is contained in:
parent
dadc8d0183
commit
21a0fe3a48
@ -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;
|
||||
@ -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;
|
||||
@ -79,6 +81,7 @@ public class Recipient {
|
||||
Recipient.this.contactUri = result.contactUri;
|
||||
Recipient.this.contactPhoto = result.avatar;
|
||||
Recipient.this.color = result.color;
|
||||
Recipient.this.resolving = false;
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
@ -99,6 +102,7 @@ public class Recipient {
|
||||
this.name = details.name;
|
||||
this.contactPhoto = details.avatar;
|
||||
this.color = details.color;
|
||||
this.resolving = false;
|
||||
}
|
||||
|
||||
public synchronized @Nullable Uri getContactUri() {
|
||||
@ -193,4 +197,9 @@ public class Recipient {
|
||||
void setStale() {
|
||||
this.stale = true;
|
||||
}
|
||||
|
||||
synchronized boolean isResolving() {
|
||||
return resolving;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
public class RecipientProvider {
|
||||
class RecipientProvider {
|
||||
|
||||
private static final String TAG = RecipientProvider.class.getSimpleName();
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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<>();
|
||||
|
||||
|
@ -344,6 +344,14 @@ public class Recipients implements Iterable<Recipient>, RecipientModifiedListene
|
||||
this.stale = true;
|
||||
}
|
||||
|
||||
boolean isResolving() {
|
||||
for (Recipient recipient : recipients) {
|
||||
if (recipient.isResolving()) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public interface RecipientsModifiedListener {
|
||||
public void onModified(Recipients recipient);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user