Fix issue where group read was happening on main thread.

This commit is contained in:
Greyson Parrelli 2022-03-17 14:30:57 -04:00 committed by Cody Henthorne
parent bf897d10d2
commit 43ad0b2294

View file

@ -337,35 +337,40 @@ public class ConversationViewModel extends ViewModel {
} }
@NonNull Observable<Map<RecipientId, NameColor>> getNameColorsMap() { @NonNull Observable<Map<RecipientId, NameColor>> getNameColorsMap() {
return recipientId.map(Recipient::resolved) return recipientId
.map(Recipient::getGroupId) .observeOn(Schedulers.io())
.map(groupId -> { .distinctUntilChanged()
if (groupId.isPresent()) { .map(Recipient::resolved)
List<Recipient> fullMembers = SignalDatabase.groups().getGroupMembers(groupId.get(), GroupDatabase.MemberSet.FULL_MEMBERS_INCLUDING_SELF); .map(Recipient::getGroupId)
Set<Recipient> cachedMembers = MapUtil.getOrDefault(sessionMemberCache, groupId.get(), new HashSet<>()); .map(groupId -> {
cachedMembers.addAll(fullMembers); if (groupId.isPresent()) {
sessionMemberCache.put(groupId.get(), cachedMembers); List<Recipient> fullMembers = SignalDatabase.groups().getGroupMembers(groupId.get(), GroupDatabase.MemberSet.FULL_MEMBERS_INCLUDING_SELF);
return cachedMembers; Set<Recipient> cachedMembers = MapUtil.getOrDefault(sessionMemberCache, groupId.get(), new HashSet<>());
} else {
return Collections.<Recipient>emptySet();
}
})
.map(members -> {
List<Recipient> sorted = Stream.of(members)
.filter(member -> !Objects.equals(member, Recipient.self()))
.sortBy(Recipient::requireStringId)
.toList();
List<NameColor> names = ChatColorsPalette.Names.getAll(); cachedMembers.addAll(fullMembers);
Map<RecipientId, NameColor> colors = new HashMap<>(); sessionMemberCache.put(groupId.get(), cachedMembers);
for (int i = 0; i < sorted.size(); i++) {
colors.put(sorted.get(i).getId(), names.get(i % names.size()));
}
return colors; return cachedMembers;
}) } else {
.subscribeOn(Schedulers.io()) return Collections.<Recipient>emptySet();
.observeOn(AndroidSchedulers.mainThread()); }
})
.map(members -> {
List<Recipient> sorted = Stream.of(members)
.filter(member -> !Objects.equals(member, Recipient.self()))
.sortBy(Recipient::requireStringId)
.toList();
List<NameColor> names = ChatColorsPalette.Names.getAll();
Map<RecipientId, NameColor> colors = new HashMap<>();
for (int i = 0; i < sorted.size(); i++) {
colors.put(sorted.get(i).getId(), names.get(i % names.size()));
}
return colors;
})
.observeOn(AndroidSchedulers.mainThread());
} }
@NonNull LiveData<Optional<NotificationProfile>> getActiveNotificationProfile() { @NonNull LiveData<Optional<NotificationProfile>> getActiveNotificationProfile() {