notification fixes

This commit is contained in:
Efstratios Giannopoulos 2024-05-13 14:40:19 +03:00
parent 035185d7fb
commit 7947df3a3a
2 changed files with 4 additions and 3 deletions

View File

@ -120,7 +120,7 @@ public class NotificationBuilder extends BaseBuilder<Notification, NotificationE
Map<UUID, User> itemMap; Map<UUID, User> itemMap;
if (!fields.hasOtherField(this.asIndexer(User._id))) { if (!fields.hasOtherField(this.asIndexer(User._id))) {
itemMap = this.asEmpty( itemMap = this.asEmpty(
data.stream().map(NotificationEntity::getUserId).distinct().collect(Collectors.toList()), data.stream().map(NotificationEntity::getUserId).filter(Objects::nonNull).distinct().collect(Collectors.toList()),
x -> { x -> {
User item = new User(); User item = new User();
item.setId(x); item.setId(x);
@ -129,7 +129,7 @@ public class NotificationBuilder extends BaseBuilder<Notification, NotificationE
User::getId); User::getId);
} else { } else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(User._id); FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(User._id);
UserQuery q = this.queryFactory.query(UserQuery.class).authorize(this.authorize).ids(data.stream().map(NotificationEntity::getUserId).distinct().collect(Collectors.toList())); UserQuery q = this.queryFactory.query(UserQuery.class).authorize(this.authorize).ids(data.stream().map(NotificationEntity::getUserId).filter(Objects::nonNull).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asForeignKey(q, clone, User::getId); itemMap = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asForeignKey(q, clone, User::getId);
} }
if (!fields.hasField(User._id)) { if (!fields.hasField(User._id)) {

View File

@ -158,6 +158,7 @@ public class NotificationServiceImpl implements NotificationService {
} }
private List<NotificationContactType> orderContactTypesFromPreferences(NotificationEntity notification) { private List<NotificationContactType> orderContactTypesFromPreferences(NotificationEntity notification) {
if (notification.getUserId() == null) return null;
Ordering ordering = new Ordering(); Ordering ordering = new Ordering();
ordering.addAscending(UserNotificationPreference._ordinal); ordering.addAscending(UserNotificationPreference._ordinal);
UserNotificationPreferenceQuery query = this.queryFactory.query(UserNotificationPreferenceQuery.class).userId(notification.getUserId()).type(notification.getType()).isActives(IsActive.Active); UserNotificationPreferenceQuery query = this.queryFactory.query(UserNotificationPreferenceQuery.class).userId(notification.getUserId()).type(notification.getType()).isActives(IsActive.Active);
@ -175,7 +176,7 @@ public class NotificationServiceImpl implements NotificationService {
} }
private List<NotificationContactType> orderContactTypes(NotificationEntity notification) { private List<NotificationContactType> orderContactTypes(NotificationEntity notification) {
List<NotificationContactType> contactTypes = this.channelResolutionService.resolve(notification.getType(), notification.getUserId()); List<NotificationContactType> contactTypes = notification.getUserId() == null ? this.channelResolutionService.resolve(notification.getType()): this.channelResolutionService.resolve(notification.getType(), notification.getUserId());
if (notification.getContactTypeHint() == null) return contactTypes; if (notification.getContactTypeHint() == null) return contactTypes;
List<NotificationContactType> ordered = new ArrayList<>(Collections.singleton(notification.getContactTypeHint())); List<NotificationContactType> ordered = new ArrayList<>(Collections.singleton(notification.getContactTypeHint()));