aboutsummaryrefslogtreecommitdiff
path: root/juick-server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-05 13:45:14 +0300
committerGravatar Vitaly Takmazov2018-10-05 13:45:14 +0300
commitf85d0eb9e26b9ffae574b21a263b83c079342e6e (patch)
tree17aacec8c72cfb6689e2e34ee427b7a51dd94f2e /juick-server
parentd6e4aa12983c466ecff0a6fdc32e1a5c415baa68 (diff)
ActivityPub: change message uri to human readable
Diffstat (limited to 'juick-server')
-rw-r--r--juick-server/src/main/java/com/juick/server/ActivityPubManager.java7
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/Profile.java14
2 files changed, 6 insertions, 15 deletions
diff --git a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
index 46b7177f..2d6d06bc 100644
--- a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
+++ b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
@@ -4,7 +4,6 @@ import com.juick.Message;
import com.juick.User;
import com.juick.formatters.PlainTextFormatter;
import com.juick.server.api.activity.model.Image;
-import com.juick.server.api.activity.model.Link;
import com.juick.server.api.activity.model.Note;
import com.juick.server.api.activity.model.Person;
import com.juick.server.api.activity.model.activities.Accept;
@@ -22,7 +21,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
-import org.springframework.util.Base64Utils;
import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.Nonnull;
@@ -172,10 +170,7 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
}
public String messageUri(int mid, int rid) {
UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri);
- String postId = rid > 0 ?
- String.format("%d#%d", mid, rid)
- : String.valueOf(mid);
- uri.replacePath(String.format("/n/%s", Base64Utils.encodeToUrlSafeString(postId.getBytes())));
+ uri.replacePath(String.format("/n/%d-%d", mid, rid));
return uri.toUriString();
}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
index 4186539d..f2beaa53 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
@@ -2,7 +2,6 @@ package com.juick.server.api.activity;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.juick.Message;
import com.juick.User;
import com.juick.server.ActivityPubManager;
import com.juick.server.KeystoreManager;
@@ -25,7 +24,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
-import org.springframework.util.Base64Utils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import org.springframework.web.util.UriComponents;
@@ -223,17 +221,15 @@ public class Profile {
throw new HttpNotFoundException();
}
- @GetMapping(value = "/n/{base64id}", produces = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITY_JSON_MEDIA_TYPE})
- public Context showNote(@PathVariable String base64id) {
- String postId = new String(Base64Utils.decodeFromUrlSafeString(base64id));
- String[] ids = postId.split("#", 2);
- if (ids.length > 1) {
+ @GetMapping(value = "/n/{mid}-{rid}", produces = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITY_JSON_MEDIA_TYPE})
+ public Context showNote(@PathVariable int mid, @PathVariable int rid) {
+ if (rid > 0) {
// reply
return Context.build(activityPubManager.makeNote(
- messagesService.getReply(Integer.valueOf(ids[0]), Integer.valueOf(ids[1]))));
+ messagesService.getReply(mid, rid)));
}
return Context.build(activityPubManager.makeNote(
- messagesService.getMessage(Integer.valueOf(ids[0]))));
+ messagesService.getMessage(mid)));
}
@PostMapping(value = "/api/inbox", consumes = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITY_JSON_MEDIA_TYPE})