diff options
Diffstat (limited to 'src/main/java/com/juick/www/api')
-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 |
4 files changed, 16 insertions, 12 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); |