aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/server')
-rw-r--r--src/main/java/com/juick/server/ActivityPubManager.java31
-rw-r--r--src/main/java/com/juick/server/api/activity/Profile.java28
2 files changed, 43 insertions, 16 deletions
diff --git a/src/main/java/com/juick/server/ActivityPubManager.java b/src/main/java/com/juick/server/ActivityPubManager.java
index dddb4344..9829760f 100644
--- a/src/main/java/com/juick/server/ActivityPubManager.java
+++ b/src/main/java/com/juick/server/ActivityPubManager.java
@@ -14,6 +14,7 @@ import com.juick.server.api.activity.model.objects.Mention;
import com.juick.server.api.activity.model.objects.Note;
import com.juick.server.api.activity.model.objects.Person;
import com.juick.server.util.HttpUtils;
+import com.juick.service.MessagesService;
import com.juick.service.SocialService;
import com.juick.service.UserService;
import com.juick.service.activities.*;
@@ -56,6 +57,8 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
@Inject
private UserService userService;
@Inject
+ private MessagesService messagesService;
+ @Inject
private PebbleEngine pebbleEngine;
@Value("${ap_base_uri:http://localhost:8080/}")
private String baseUri;
@@ -133,6 +136,34 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
}
@Override
+ public void processAnnounceEvent(AnnounceEvent event) {
+ UriComponents uriComponents = UriComponentsBuilder.fromUriString(event.getMessageUri()).build();
+ List<String> segments = uriComponents.getPathSegments();
+ if (segments.get(0).equals("m")) {
+ String[] ids = segments.get(1).split("-", 2);
+ if (ids.length == 1) {
+ // only messages
+ logger.info("{} recommends {}", event.getActorUri(), Integer.valueOf(ids[0]));
+ messagesService.recommendMessage(Integer.valueOf(ids[0]), 0, event.getActorUri());
+ }
+ }
+ }
+
+ @Override
+ public void undoAnnounceEvent(UndoAnnounceEvent event) {
+ UriComponents uriComponents = UriComponentsBuilder.fromUriString(event.getMessageUri()).build();
+ List<String> segments = uriComponents.getPathSegments();
+ if (segments.get(0).equals("m")) {
+ String[] ids = segments.get(1).split("-", 2);
+ if (ids.length == 1) {
+ // only messages
+ logger.info("{} stop recommending {}", event.getActorUri(), Integer.valueOf(ids[0]));
+ messagesService.recommendMessage(Integer.valueOf(ids[0]), 0, event.getActorUri());
+ }
+ }
+ }
+
+ @Override
public void processMessageEvent(MessageEvent messageEvent) {
Message msg = messageEvent.getMessage();
if (MessageUtils.isPM(msg)) {
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 5a2a766e..e8fb45ec 100644
--- a/src/main/java/com/juick/server/api/activity/Profile.java
+++ b/src/main/java/com/juick/server/api/activity/Profile.java
@@ -28,9 +28,7 @@ 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.DeleteUserEvent;
-import com.juick.service.activities.FollowEvent;
-import com.juick.service.activities.UndoFollowEvent;
+import com.juick.service.activities.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -283,9 +281,16 @@ public class Profile {
}
if (activity instanceof Undo) {
- String follower = (String) ((Map) activity.getObject()).get("object");
- applicationEventPublisher.publishEvent(new UndoFollowEvent(this, activity.getActor(), follower));
- return new ResponseEntity<>(HttpStatus.OK);
+ Map object = (Map) activity.getObject();
+ String objectType = (String) object.get("type");
+ String objectObject = (String) object.get("object");
+ if (objectType.equals("Follow")) {
+ applicationEventPublisher.publishEvent(new UndoFollowEvent(this, activity.getActor(), objectObject));
+ return new ResponseEntity<>(HttpStatus.OK);
+ } else if (objectType.equals("Like") || objectType.equals("Announce")) {
+ applicationEventPublisher.publishEvent(new UndoAnnounceEvent(this, activity.getActor(), objectObject));
+ return new ResponseEntity<>(HttpStatus.OK);
+ }
}
if (activity instanceof Delete) {
if (activity.getObject() instanceof String) {
@@ -356,16 +361,7 @@ public class Profile {
}
}
if (activity instanceof Like || activity instanceof Announce) {
- String msgUri = (String)activity.getObject();
- User user = new User();
- user.setUri(URI.create(activity.getActor()));
- Person person = (Person) signatureManager.getContext(user.getUri()).get();
- user.setName(person.getPreferredUsername());
- String[] ids = msgUri.split("\\/", 2);
- if (ids.length == 1) {
- // only messages
- commandsManager.processCommand(user, String.format("! #%s", ids[0]), URI.create(StringUtils.EMPTY));
- }
+ applicationEventPublisher.publishEvent(new AnnounceEvent(this, activity.getActor(), (String)((Map)activity.getObject()).get("object")));
return new ResponseEntity<>(HttpStatus.OK);
}
logger.warn("Unknown activity: {}", jsonMapper.writeValueAsString(activity));