diff options
author | Vitaly Takmazov | 2021-08-22 06:55:37 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2021-08-22 06:55:37 +0300 |
commit | 03d42d6e6ccaee4ff9d2a0808e51e5f9f0dc18c3 (patch) | |
tree | a3a6f5ef310b2130ff6fdf541f34facecd8bf2b3 /src/main/java/com/juick/www/api | |
parent | 9100b5bda037fcd1b051b98585744077132320bc (diff) |
ActivityPub: return Application profile for service user
Diffstat (limited to 'src/main/java/com/juick/www/api')
-rw-r--r-- | src/main/java/com/juick/www/api/activity/Profile.java | 32 | ||||
-rw-r--r-- | src/main/java/com/juick/www/api/activity/model/Context.java | 13 | ||||
-rw-r--r-- | src/main/java/com/juick/www/api/activity/model/objects/Actor.java (renamed from src/main/java/com/juick/www/api/activity/model/objects/SecurityObject.java) | 47 | ||||
-rw-r--r-- | src/main/java/com/juick/www/api/activity/model/objects/Application.java | 2 | ||||
-rw-r--r-- | src/main/java/com/juick/www/api/activity/model/objects/Person.java | 68 |
5 files changed, 75 insertions, 87 deletions
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 751d0cff..724e0747 100644 --- a/src/main/java/com/juick/www/api/activity/Profile.java +++ b/src/main/java/com/juick/www/api/activity/Profile.java @@ -34,6 +34,8 @@ import com.juick.www.api.activity.model.activities.Flag; import com.juick.www.api.activity.model.activities.Follow; import com.juick.www.api.activity.model.activities.Like; import com.juick.www.api.activity.model.activities.Undo; +import com.juick.www.api.activity.model.objects.Actor; +import com.juick.www.api.activity.model.objects.Application; import com.juick.www.api.activity.model.objects.Image; import com.juick.www.api.activity.model.objects.Key; import com.juick.www.api.activity.model.objects.Note; @@ -106,28 +108,28 @@ public class Profile { @GetMapping(value = "/u/{userName}", produces = { Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE, Context.FALLBACK_JSON_MEDIA_TYPE }) - public Person getUser(@PathVariable String userName) { + public Actor getUser(@PathVariable String userName) { User user = userService.getUserByName(userName); if (!user.isAnonymous()) { - Person person = new Person(); - person.setId(activityPubManager.personUri(user)); - person.setUrl(activityPubManager.personWebUri(user)); - person.setName(userName); - person.setPreferredUsername(userName); + Actor profile = userService.isServiceUser(user) ? new Application() : new Person(); + profile.setId(activityPubManager.personUri(user)); + profile.setUrl(activityPubManager.personWebUri(user)); + profile.setName(userName); + profile.setPreferredUsername(userName); Key publicKey = new Key(); - publicKey.setId(person.getId() + "#main-key"); - publicKey.setOwner(person.getId()); + publicKey.setId(profile.getId() + "#main-key"); + publicKey.setOwner(profile.getId()); publicKey.setPublicKeyPem(keystoreManager.getPublicKeyPem()); - person.setPublicKey(publicKey); - person.setInbox(activityPubManager.inboxUri()); - person.setOutbox(activityPubManager.outboxUri(user)); - person.setFollowers(activityPubManager.followersUri(user)); - person.setFollowing(activityPubManager.followingUri(user)); + profile.setPublicKey(publicKey); + profile.setInbox(activityPubManager.inboxUri()); + profile.setOutbox(activityPubManager.outboxUri(user)); + profile.setFollowers(activityPubManager.followersUri(user)); + profile.setFollowing(activityPubManager.followingUri(user)); Image avatar = new Image(); avatar.setUrl(webApp.getAvatarUrl(user)); avatar.setMediaType("image/png"); - person.setIcon(avatar); - return (Person) Context.build(person); + profile.setIcon(avatar); + return (Actor) Context.build(profile); } throw new HttpNotFoundException(); } diff --git a/src/main/java/com/juick/www/api/activity/model/Context.java b/src/main/java/com/juick/www/api/activity/model/Context.java index edfa89b1..f5d95d24 100644 --- a/src/main/java/com/juick/www/api/activity/model/Context.java +++ b/src/main/java/com/juick/www/api/activity/model/Context.java @@ -58,11 +58,9 @@ import java.util.Map; public class Context { private List<Object> context; - private String id; - private String name; - + private Image icon; private Instant published; @JsonDeserialize(using = LinkValueDeserializer.class) @@ -150,4 +148,13 @@ public class Context { public void setName(String name) { this.name = name; } + + @JsonTypeInfo(use = JsonTypeInfo.Id.NONE) + public Image getIcon() { + return icon; + } + + public void setIcon(Image icon) { + this.icon = icon; + } } diff --git a/src/main/java/com/juick/www/api/activity/model/objects/SecurityObject.java b/src/main/java/com/juick/www/api/activity/model/objects/Actor.java index 8d17aa29..f8bd63e0 100644 --- a/src/main/java/com/juick/www/api/activity/model/objects/SecurityObject.java +++ b/src/main/java/com/juick/www/api/activity/model/objects/Actor.java @@ -20,7 +20,13 @@ package com.juick.www.api.activity.model.objects; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.juick.www.api.activity.model.Context; -public class SecurityObject extends Context { +public class Actor extends Context { + + private String preferredUsername; + private String inbox; + private String outbox; + private String following; + private String followers; private Key publicKey; @@ -33,4 +39,43 @@ public class SecurityObject extends Context { this.publicKey = publicKey; } + public String getOutbox() { + return outbox; + } + + public void setOutbox(String outbox) { + this.outbox = outbox; + } + + public String getInbox() { + return inbox; + } + + public void setInbox(String inbox) { + this.inbox = inbox; + } + + public String getFollowing() { + return following; + } + + public void setFollowing(String following) { + this.following = following; + } + + public String getFollowers() { + return followers; + } + + public void setFollowers(String followers) { + this.followers = followers; + } + + public String getPreferredUsername() { + return preferredUsername; + } + + public void setPreferredUsername(String preferredUsername) { + this.preferredUsername = preferredUsername; + } } diff --git a/src/main/java/com/juick/www/api/activity/model/objects/Application.java b/src/main/java/com/juick/www/api/activity/model/objects/Application.java index 29361b33..d30d36c9 100644 --- a/src/main/java/com/juick/www/api/activity/model/objects/Application.java +++ b/src/main/java/com/juick/www/api/activity/model/objects/Application.java @@ -17,5 +17,5 @@ package com.juick.www.api.activity.model.objects; -public class Application extends SecurityObject { +public class Application extends Actor { } diff --git a/src/main/java/com/juick/www/api/activity/model/objects/Person.java b/src/main/java/com/juick/www/api/activity/model/objects/Person.java index 84844510..e59c793a 100644 --- a/src/main/java/com/juick/www/api/activity/model/objects/Person.java +++ b/src/main/java/com/juick/www/api/activity/model/objects/Person.java @@ -17,72 +17,6 @@ package com.juick.www.api.activity.model.objects; -import com.fasterxml.jackson.annotation.JsonTypeInfo; +public class Person extends Actor { -public class Person extends SecurityObject { - - private String name; - private String preferredUsername; - private Image icon; - private String inbox; - private String outbox; - private String following; - private String followers; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @JsonTypeInfo(use = JsonTypeInfo.Id.NONE) - public Image getIcon() { - return icon; - } - - public void setIcon(Image icon) { - this.icon = icon; - } - - public String getOutbox() { - return outbox; - } - - public void setOutbox(String outbox) { - this.outbox = outbox; - } - - public String getInbox() { - return inbox; - } - - public void setInbox(String inbox) { - this.inbox = inbox; - } - - public String getFollowing() { - return following; - } - - public void setFollowing(String following) { - this.following = following; - } - - public String getFollowers() { - return followers; - } - - public void setFollowers(String followers) { - this.followers = followers; - } - - public String getPreferredUsername() { - return preferredUsername; - } - - public void setPreferredUsername(String preferredUsername) { - this.preferredUsername = preferredUsername; - } } |