Skip to content

Commit

Permalink
Fix some timing issues around recipient events.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Jul 19, 2021
1 parent c2a6963 commit 39709c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Expand Up @@ -16,6 +16,7 @@
import org.thoughtcrime.securesms.components.AvatarImageView;
import org.thoughtcrime.securesms.components.FromTextView;
import org.thoughtcrime.securesms.mms.GlideRequests;
import org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter;
import org.thoughtcrime.securesms.recipients.LiveRecipient;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientForeverObserver;
Expand Down Expand Up @@ -95,8 +96,9 @@ public void set(@NonNull GlideRequests glideRequests,
Recipient recipientSnapshot = recipient != null ? recipient.get() : null;

if (recipientSnapshot != null && !recipientSnapshot.isResolving()) {
name = recipientSnapshot.getDisplayName(getContext());
} else {
contactName = recipientSnapshot.getDisplayName(getContext());
name = contactName;
} else if (recipient != null) {
name = "";
}

Expand Down Expand Up @@ -212,6 +214,10 @@ public Optional<RecipientId> getRecipientId() {
@Override
public void onRecipientChanged(@NonNull Recipient recipient) {
if (this.recipient != null && this.recipient.getId().equals(recipient.getId())) {
contactName = recipient.getDisplayName(getContext());
contactAbout = recipient.getCombinedAboutAndEmoji();
contactNumber = PhoneNumberFormatter.prettyPrint(recipient.getE164().or(""));

contactPhotoImage.setAvatar(glideRequests, recipient, false);
setText(recipient, contactType, contactName, contactNumber, contactLabel, contactAbout);
smsTag.setVisibility(recipient.isRegistered() ? GONE : VISIBLE);
Expand Down
Expand Up @@ -50,9 +50,11 @@ public final class LiveRecipient {
this.groupDatabase = DatabaseFactory.getGroupDatabase(context);
this.observers = new CopyOnWriteArraySet<>();
this.foreverObserver = recipient -> {
for (RecipientForeverObserver o : observers) {
o.onRecipientChanged(recipient);
}
ThreadUtil.postToMain(() -> {
for (RecipientForeverObserver o : observers) {
o.onRecipientChanged(recipient);
}
});
};
this.refreshForceNotify = new MutableLiveData<>(new Object());
this.observableLiveData = LiveDataUtil.combineLatest(LiveDataUtil.distinctUntilChanged(liveData, Recipient::hasSameContent),
Expand Down

0 comments on commit 39709c8

Please sign in to comment.