From ced48d078806d25f1976c3dad92ce2900bc7232b Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Wed, 25 Sep 2019 18:35:17 -0400 Subject: [PATCH] Fix custom notification creation. --- .../securesms/database/RecipientDatabase.java | 2 +- .../notifications/NotificationChannels.java | 3 ++ .../securesms/recipients/LiveRecipient.java | 42 ++++++++++++++----- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/org/thoughtcrime/securesms/database/RecipientDatabase.java b/src/org/thoughtcrime/securesms/database/RecipientDatabase.java index fee1370c65..fda06a559c 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 2cc0014961..27eb95fce0 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 3ef0464b21..7306da7870 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);