Skip to content

Commit

Permalink
Fix initial LiveData value for recipients.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-signal committed Jan 25, 2021
1 parent c058452 commit 49535f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public final class LiveRecipient {
private final GroupDatabase groupDatabase;
private final MutableLiveData<Object> refreshForceNotify;

LiveRecipient(@NonNull Context context, @NonNull MutableLiveData<Recipient> liveData, @NonNull Recipient defaultRecipient) {
LiveRecipient(@NonNull Context context, @NonNull Recipient defaultRecipient) {
this.context = context.getApplicationContext();
this.liveData = liveData;
this.liveData = new MutableLiveData<>(defaultRecipient);
this.recipient = new AtomicReference<>(defaultRecipient);
this.recipientDatabase = DatabaseFactory.getRecipientDatabase(context);
this.groupDatabase = DatabaseFactory.getGroupDatabase(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import androidx.annotation.AnyThread;
import androidx.annotation.GuardedBy;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.annimon.stream.Stream;

import org.signal.core.util.concurrent.SignalExecutors;
import org.signal.core.util.logging.Log;
Expand All @@ -22,7 +19,6 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -50,7 +46,7 @@ public LiveRecipientCache(@NonNull Context context) {
this.context = context.getApplicationContext();
this.recipientDatabase = DatabaseFactory.getRecipientDatabase(context);
this.recipients = new LRUCache<>(CACHE_MAX);
this.unknown = new LiveRecipient(context, new MutableLiveData<>(), Recipient.UNKNOWN);
this.unknown = new LiveRecipient(context, Recipient.UNKNOWN);
}

@AnyThread
Expand All @@ -60,7 +56,7 @@ public LiveRecipientCache(@NonNull Context context) {
LiveRecipient live = recipients.get(id);

if (live == null) {
final LiveRecipient newLive = new LiveRecipient(context, new MutableLiveData<>(), new Recipient(id));
final LiveRecipient newLive = new LiveRecipient(context, new Recipient(id));

recipients.put(id, newLive);

Expand Down Expand Up @@ -93,7 +89,7 @@ public synchronized void addToCache(@NonNull Collection<Recipient> newRecipients
boolean needsResolve = false;

if (live == null) {
live = new LiveRecipient(context, new MutableLiveData<>(), recipient);
live = new LiveRecipient(context, recipient);
recipients.put(recipient.getId(), live);
needsResolve = recipient.isResolving();
} else if (live.get().isResolving() || !recipient.isResolving()) {
Expand Down

0 comments on commit 49535f6

Please sign in to comment.