diff options
Diffstat (limited to 'src/main/java/com/juick/www')
-rw-r--r-- | src/main/java/com/juick/www/api/Messages.java | 6 | ||||
-rw-r--r-- | src/main/java/com/juick/www/api/Notifications.java | 10 | ||||
-rw-r--r-- | src/main/java/com/juick/www/api/Service.java | 8 | ||||
-rw-r--r-- | src/main/java/com/juick/www/api/activity/Profile.java | 4 | ||||
-rw-r--r-- | src/main/java/com/juick/www/controllers/Site.java | 4 | ||||
-rw-r--r-- | src/main/java/com/juick/www/rss/Feeds.java | 2 |
6 files changed, 20 insertions, 14 deletions
diff --git a/src/main/java/com/juick/www/api/Messages.java b/src/main/java/com/juick/www/api/Messages.java index 7b003220..9608813d 100644 --- a/src/main/java/com/juick/www/api/Messages.java +++ b/src/main/java/com/juick/www/api/Messages.java @@ -65,6 +65,8 @@ public class Messages { private WebApp webApp; @Value("classpath:Transparent.gif") private Resource invisiblePixel; + @Inject + private User serviceUser; // TODO: serialize image urls @@ -102,7 +104,7 @@ public class Messages { throw new HttpNotFoundException(); } } else if (StringUtils.hasText(withrecommended)) { - mids = messagesService.getUserBlogWithRecommendations(user.getUid(), 0, before); + mids = messagesService.getUserBlogWithRecommendations(user, visitor, 0, before); } else if (daysback > 0) { mids = messagesService.getUserBlogAtDay(user.getUid(), 0, daysback); } else if (StringUtils.hasText(search)) { @@ -116,7 +118,7 @@ public class Messages { } } else { if (StringUtils.hasText(popular)) { - mids = messagesService.getPopular(visitor.getUid(), before); + mids = messagesService.getUserBlogWithRecommendations(serviceUser, visitor, 0, before); } else if (StringUtils.hasText(media)) { mids = messagesService.getPhotos(visitor.getUid(), before); } else if (StringUtils.hasText(tag)) { diff --git a/src/main/java/com/juick/www/api/Notifications.java b/src/main/java/com/juick/www/api/Notifications.java index d00fe4ca..613e6cfc 100644 --- a/src/main/java/com/juick/www/api/Notifications.java +++ b/src/main/java/com/juick/www/api/Notifications.java @@ -63,8 +63,8 @@ public class Notifications { private UserService userService; @Inject private TelegramService telegramService; - @Value("${api_user:juick}") - private String serviceUser; + @Inject + private User serviceUser; private User collectTokens(Integer uid) { User user = userService.getUserByUID(uid).orElse(AnonymousUser.INSTANCE); @@ -90,7 +90,7 @@ public class Notifications { @RequestParam(required = false, defaultValue = "0") int uid, @RequestParam(required = false, defaultValue = "0") int mid, @RequestParam(required = false, defaultValue = "0") int rid) { - if (!(visitor.getName().equals(serviceUser))) { + if (!(visitor.equals(serviceUser))) { throw new HttpForbiddenException(); } if (uid > 0 && mid == 0) { @@ -127,7 +127,7 @@ public class Notifications { public Status doDelete( @Visitor User visitor, @RequestBody List<ExternalToken> list) { - if (!visitor.getName().equals(serviceUser)) { + if (!visitor.equals(serviceUser)) { throw new HttpForbiddenException(); } list.forEach(t -> { @@ -153,7 +153,7 @@ public class Notifications { public Status doDeleteTokens( @Visitor User visitor, @RequestBody List<ExternalToken> list) { - if (!visitor.getName().equals(serviceUser)) { + if (!visitor.equals(serviceUser)) { throw new HttpForbiddenException(); } list.forEach(t -> { diff --git a/src/main/java/com/juick/www/api/Service.java b/src/main/java/com/juick/www/api/Service.java index 3844d003..fc0132b1 100644 --- a/src/main/java/com/juick/www/api/Service.java +++ b/src/main/java/com/juick/www/api/Service.java @@ -75,8 +75,8 @@ public class Service { private CommandsManager commandsManager; @Inject private ApplicationEventPublisher applicationEventPublisher; - @Value("${api_user:juick}") - private String serviceUser; + @Inject + private User serviceUser; @Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}") private String tmpDir; @Value("${banned_emails:}") @@ -90,7 +90,7 @@ public class Service { @PostMapping("/api/mail") @ResponseStatus(value = HttpStatus.OK) public void processMail(@Visitor User current, InputStream data) throws Exception { - if (current.getName().equals(serviceUser)) { + if (current.equals(serviceUser)) { MimeMessage msg = new MimeMessage(session, data); String[] returnPaths = msg.getHeader("Return-Path"); if (returnPaths != null) { @@ -197,7 +197,7 @@ public class Service { @PostMapping("/api/mail/unsubscribe") @ResponseStatus(value = HttpStatus.OK) public void processMailUnsubscribe(@Visitor User current, InputStream data) throws Exception { - if (current.getName().equals(serviceUser)) { + if (current.equals(serviceUser)) { MimeMessage msg = new MimeMessage(session, data); String from = msg.getFrom() == null || msg.getFrom().length > 1 ? ((InternetAddress) msg.getSender()).getAddress() diff --git a/src/main/java/com/juick/www/api/activity/Profile.java b/src/main/java/com/juick/www/api/activity/Profile.java index 3dc717e9..045e919d 100644 --- a/src/main/java/com/juick/www/api/activity/Profile.java +++ b/src/main/java/com/juick/www/api/activity/Profile.java @@ -105,13 +105,15 @@ public class Profile { private WebApp webApp; @Inject private Remark remarkConverter; + @Inject + private User serviceUser; @GetMapping(value = "/u/{userName}", produces = { Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE, Context.FALLBACK_JSON_MEDIA_TYPE }) public Actor getUser(@PathVariable String userName) { User user = userService.getUserByName(userName); if (!user.isAnonymous()) { - Actor profile = userService.isServiceUser(user) ? new Application() : new Person(); + Actor profile = user.equals(serviceUser) ? new Application() : new Person(); profile.setId(activityPubManager.personUri(user)); profile.setUrl(activityPubManager.personWebUri(user)); profile.setName(userName); diff --git a/src/main/java/com/juick/www/controllers/Site.java b/src/main/java/com/juick/www/controllers/Site.java index 682ed247..9eb4c917 100644 --- a/src/main/java/com/juick/www/controllers/Site.java +++ b/src/main/java/com/juick/www/controllers/Site.java @@ -69,6 +69,8 @@ public class Site { private PMQueriesService pmQueriesService; @Inject private WebApp webApp; + @Inject + private User serviceUser; private void fillUserModel(ModelMap model, User user, User visitor) { user.setAvatar(webApp.getAvatarWebPath(user)); @@ -118,7 +120,7 @@ public class Site { mids = messagesService.getDiscussions(visitor.getUid(), paramTo); } else if (paramShow.equals("top")) { title = ResourceBundle.getBundle("messages", locale).getString("link.popular"); - mids = messagesService.getPopular(visitor.getUid(), paramBefore); + mids = messagesService.getUserBlogWithRecommendations(serviceUser, visitor, 0, paramBefore); model.addAttribute("discover", true); } else if (paramShow.equals("my") && !visitor.isAnonymous()) { title = ResourceBundle.getBundle("messages", locale).getString("link.my"); diff --git a/src/main/java/com/juick/www/rss/Feeds.java b/src/main/java/com/juick/www/rss/Feeds.java index 34ad7e5e..8b396fd2 100644 --- a/src/main/java/com/juick/www/rss/Feeds.java +++ b/src/main/java/com/juick/www/rss/Feeds.java @@ -51,7 +51,7 @@ public class Feeds { public ModelAndView getBlog(@Visitor User visitor, @PathVariable String userName, @PathVariable FeedType feedType) { User user = userService.getUserByName(userName); if (!user.isAnonymous() && !user.isBanned()) { - List<Integer> mids = feedType == FeedType.blog ? messagesService.getUserBlog(user.getUid(), 0, 0) : messagesService.getUserBlogWithRecommendations(user.getUid(), 0, 0); + List<Integer> mids = feedType == FeedType.blog ? messagesService.getUserBlog(user.getUid(), 0, 0) : messagesService.getUserBlogWithRecommendations(user, visitor, 0, 0); ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("messagesView"); modelAndView.addObject("user", user); |