diff --git a/src/org/thoughtcrime/securesms/database/RecipientDatabase.java b/src/org/thoughtcrime/securesms/database/RecipientDatabase.java index fee1370c6..fda06a559 100644 --- a/src/org/thoughtcrime/securesms/database/RecipientDatabase.java +++ b/src/org/thoughtcrime/securesms/database/RecipientDatabase.java @@ -848,7 +848,7 @@ public class RecipientDatabase extends Database { public @NonNull Recipient getCurrent() { RecipientId id = RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(ID))); - return Recipient.live(id).get(); + return Recipient.resolved(id); } public @Nullable Recipient getNext() { diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationChannels.java b/src/org/thoughtcrime/securesms/notifications/NotificationChannels.java index 2cc001496..27eb95fce 100644 --- a/src/org/thoughtcrime/securesms/notifications/NotificationChannels.java +++ b/src/org/thoughtcrime/securesms/notifications/NotificationChannels.java @@ -407,14 +407,17 @@ public class NotificationChannels { for (NotificationChannel existingChannel : notificationManager.getNotificationChannels()) { if (existingChannel.getId().startsWith(CONTACT_PREFIX) && !customChannelIds.contains(existingChannel.getId())) { + Log.i(TAG, "Consistency: Deleting channel '"+ existingChannel.getId() + "' because the DB has no record of it."); notificationManager.deleteNotificationChannel(existingChannel.getId()); } else if (existingChannel.getId().startsWith(MESSAGES_PREFIX) && !existingChannel.getId().equals(getMessagesChannel(context))) { + Log.i(TAG, "Consistency: Deleting channel '"+ existingChannel.getId() + "' because it's out of date."); notificationManager.deleteNotificationChannel(existingChannel.getId()); } } for (Recipient customRecipient : customRecipients) { if (!existingChannelIds.contains(customRecipient.getNotificationChannel())) { + Log.i(TAG, "Consistency: Removing custom channel '"+ customRecipient.getNotificationChannel() + "' because the system doesn't have it."); db.setNotificationChannel(customRecipient.getId(), null); } } diff --git a/src/org/thoughtcrime/securesms/recipients/LiveRecipient.java b/src/org/thoughtcrime/securesms/recipients/LiveRecipient.java index 3ef0464b2..7306da787 100644 --- a/src/org/thoughtcrime/securesms/recipients/LiveRecipient.java +++ b/src/org/thoughtcrime/securesms/recipients/LiveRecipient.java @@ -119,15 +119,28 @@ public final class LiveRecipient { */ @WorkerThread public @NonNull Recipient resolve() { - Recipient recipient = get(); + Recipient current = get(); - if (recipient.isResolving()) { - recipient = fetchRecipientFromDisk(defaultRecipient.getId()); - liveData.postValue(recipient); - Stream.of(recipient.getParticipants()).forEach(Recipient::resolve); + if (!current.isResolving()) { + return current; } - return recipient; + Recipient updated = fetchRecipientFromDisk(defaultRecipient.getId()); + List participants = Stream.of(updated.getParticipants()) + .filter(Recipient::isResolving) + .map(Recipient::getId) + .map(this::fetchRecipientFromDisk) + .toList(); + + Util.runOnMainSync(() -> { + for (Recipient participant : participants) { + participant.live().liveData.setValue(participant); + } + + liveData.setValue(updated); + }); + + return updated; } /** @@ -135,11 +148,20 @@ public final class LiveRecipient { */ @WorkerThread public void refresh() { - Recipient recipient = fetchRecipientFromDisk(defaultRecipient.getId()); - liveData.postValue(recipient); - Stream.of(recipient.getParticipants()).map(Recipient::live).forEach(LiveRecipient::refresh); - } + Recipient recipient = fetchRecipientFromDisk(defaultRecipient.getId()); + List participants = Stream.of(recipient.getParticipants()) + .map(Recipient::getId) + .map(this::fetchRecipientFromDisk) + .toList(); + Util.runOnMainSync(() -> { + for (Recipient participant : participants) { + participant.live().liveData.setValue(participant); + } + + liveData.setValue(recipient); + }); + } private @NonNull Recipient fetchRecipientFromDisk(RecipientId id) { RecipientSettings settings = recipientDatabase.getRecipientSettings(id);