aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/api/activity
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-04-29 14:06:24 +0300
committerGravatar Vitaly Takmazov2019-04-29 14:06:24 +0300
commitc3a9365645ec94d5b7c9778ab32c93e5eb4be5f6 (patch)
treed853fc7df61fdc18a20a52c93291853796e9a60f /src/main/java/com/juick/server/api/activity
parent409ef92da23f4b650340197e7383ba8b528999e4 (diff)
UserUtils -> @Visitor
Diffstat (limited to 'src/main/java/com/juick/server/api/activity')
-rw-r--r--src/main/java/com/juick/server/api/activity/Profile.java27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/main/java/com/juick/server/api/activity/Profile.java b/src/main/java/com/juick/server/api/activity/Profile.java
index 701b1949..a7ba65a5 100644
--- a/src/main/java/com/juick/server/api/activity/Profile.java
+++ b/src/main/java/com/juick/server/api/activity/Profile.java
@@ -25,11 +25,14 @@ import com.juick.server.api.activity.model.objects.OrderedCollectionPage;
import com.juick.server.api.activity.model.objects.Person;
import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpNotFoundException;
-import com.juick.server.util.UserUtils;
import com.juick.server.www.WebApp;
import com.juick.service.MessagesService;
import com.juick.service.UserService;
-import com.juick.service.activities.*;
+import com.juick.service.activities.AnnounceEvent;
+import com.juick.service.activities.FollowEvent;
+import com.juick.service.activities.UndoAnnounceEvent;
+import com.juick.service.activities.UndoFollowEvent;
+import com.juick.service.security.annotation.Visitor;
import com.overzealous.remark.Remark;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
@@ -43,20 +46,15 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
-import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import javax.inject.Inject;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -132,15 +130,15 @@ public class Profile {
}
@GetMapping(value = "/u/{userName}/blog", produces = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE})
- public OrderedCollectionPage getOutboxPage(@PathVariable String userName,
+ public OrderedCollectionPage getOutboxPage(@Visitor User visitor, @PathVariable String userName,
@RequestParam(required = false, defaultValue = "0") int before) {
- User visitor = UserUtils.getCurrentUser();
User user = userService.getUserByName(userName);
if (!user.isAnonymous() && !user.isBanned()) {
UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri);
String personUri = uri.path(String.format("/u/%s", userName)).toUriString();
List<Integer> mids = messagesService.getUserBlog(user.getUid(), 0, before);
- List<Note> notes = messagesService.getMessages(visitor, mids).stream().map(activityPubManager::makeNote).collect(Collectors.toList());
+ List<Note> notes = messagesService.getMessages(visitor, mids)
+ .stream().map(activityPubManager::makeNote).collect(Collectors.toList());
OrderedCollectionPage page = new OrderedCollectionPage();
page.setPartOf(uri.replacePath(String.format("/u/%s/blog/toc", userName)).toUriString());
page.setFirst(uri.replacePath(String.format("/u/%s/blog", userName)).toUriString());
@@ -260,12 +258,15 @@ public class Profile {
}
@PostMapping(value = "/api/inbox", consumes = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE})
- public ResponseEntity<CommandResult> processInbox(InputStream inboxData) throws Exception {
+ public ResponseEntity<CommandResult> processInbox(
+ @Visitor User visitor,
+ InputStream inboxData) throws Exception {
String inbox = IOUtils.toString(inboxData, StandardCharsets.UTF_8);
logger.info("Inbox: {}", inbox);
Activity activity = jsonMapper.readValue(inbox, Activity.class);
- User visitor = UserUtils.getCurrentUser();
- if ((StringUtils.isNotEmpty(visitor.getUri().toString()) && visitor.getUri().equals(URI.create(activity.getActor()))) || !visitor.isAnonymous()) {
+ if ((StringUtils.isNotEmpty(visitor.getUri().toString())
+ && visitor.getUri().equals(URI.create(activity.getActor())))
+ || !visitor.isAnonymous()) {
if (activity instanceof Follow) {
Follow followRequest = (Follow) activity;
applicationEventPublisher.publishEvent(