From 084917b0a517c7e6b97e63c383580d1068634175 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 26 Aug 2021 14:28:06 +0300 Subject: Fix notifications endpoint flow --- src/main/java/com/juick/www/api/Notifications.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/juick/www/api/Notifications.java b/src/main/java/com/juick/www/api/Notifications.java index 76bb4380..524e4da4 100644 --- a/src/main/java/com/juick/www/api/Notifications.java +++ b/src/main/java/com/juick/www/api/Notifications.java @@ -30,6 +30,8 @@ import com.juick.service.TelegramService; import com.juick.service.UserService; import com.juick.service.security.annotation.Visitor; import io.swagger.v3.oas.annotations.Hidden; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -50,7 +52,8 @@ import java.util.stream.Collectors; */ @RestController public class Notifications { - + private static final Logger logger = LoggerFactory.getLogger("www"); + @Inject private PushQueriesService pushQueriesService; @Inject @@ -64,7 +67,6 @@ public class Notifications { @Value("${api_user:juick}") private String serviceUser; - private User collectTokens(Integer uid) { User user = userService.getUserByUID(uid).orElse(AnonymousUser.INSTANCE); user.setUnreadCount(messagesService.getUnread(user).size()); @@ -99,11 +101,15 @@ public class Notifications { if (mid > 0) { // reply Message msg = messagesService.getMessage(mid).orElseThrow(IllegalStateException::new); - List users; + List users = Collections.emptyList(); if (rid > 0) { Message op = messagesService.getMessage(mid).orElseThrow(IllegalStateException::new); Message reply = messagesService.getReply(mid, rid); - users = subscriptionService.getUsersSubscribedToComments(op, reply); + if (reply != null) { + users = subscriptionService.getUsersSubscribedToComments(op, reply); + } else { + logger.warn("Reply not found: {}/{}", mid, rid); + } } else { users = subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg); } -- cgit v1.2.3