Improve notification channel consistency checks with Android Conversations.

This commit is contained in:
Cody Henthorne
2021-06-07 15:58:39 -04:00
committed by GitHub
parent 36443c59f9
commit bece58d939
8 changed files with 108 additions and 15 deletions

View File

@@ -10,15 +10,12 @@ import com.annimon.stream.Stream;
import org.signal.core.util.concurrent.SignalExecutors;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.color.MaterialColor;
import org.thoughtcrime.securesms.color.MaterialColors;
import org.thoughtcrime.securesms.contacts.sync.DirectoryHelper;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.GroupDatabase;
import org.thoughtcrime.securesms.database.IdentityDatabase;
import org.thoughtcrime.securesms.database.ThreadDatabase;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
@@ -106,4 +103,13 @@ final class ManageRecipientRepository {
void getActiveGroupCount(@NonNull Consumer<Integer> onComplete) {
SignalExecutors.BOUNDED.execute(() -> onComplete.accept(DatabaseFactory.getGroupDatabase(context).getActiveGroupCount()));
}
@WorkerThread
boolean hasCustomNotifications(Recipient recipient) {
if (recipient.getNotificationChannel() != null || !NotificationChannels.supported()) {
return true;
}
return NotificationChannels.updateWithShortcutBasedChannel(context, recipient);
}
}

View File

@@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.recipients.ui.managerecipient;
import android.app.Activity;
import android.app.NotificationChannel;
import android.content.Context;
import android.database.Cursor;
@@ -78,7 +79,7 @@ public final class ManageRecipientViewModel extends ViewModel {
this.groupListCollapseState = new DefaultValueLiveData<>(CollapseState.COLLAPSED);
this.disappearingMessageTimer = Transformations.map(this.recipient, r -> ExpirationUtil.getExpirationDisplayValue(context, r.getExpireMessages()));
this.muteState = Transformations.map(this.recipient, r -> new MuteState(r.getMuteUntil(), r.isMuted()));
this.hasCustomNotifications = Transformations.map(this.recipient, r -> r.getNotificationChannel() != null || !NotificationChannels.supported());
this.hasCustomNotifications = LiveDataUtil.mapAsync(this.recipient, manageRecipientRepository::hasCustomNotifications);
this.canBlock = Transformations.map(this.recipient, r -> RecipientUtil.isBlockable(r) && !r.isBlocked());
this.canUnblock = Transformations.map(this.recipient, Recipient::isBlocked);
this.internalDetails = Transformations.map(this.recipient, this::populateInternalDetails);