diff options
author | Vitaly Takmazov | 2023-04-18 13:36:37 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-04-18 13:36:37 +0300 |
commit | 66801ba91a51c9b7df6d85136d677350d2495b86 (patch) | |
tree | 6ed5b2ee31b5bb3158ae1d3b791a6e284f438465 /src | |
parent | 9e34dffdcdeac0057f1bbd36a3978b992f2c4790 (diff) |
ActivityPub compatibility with private posts
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/juick/ActivityPubManager.java | 10 | ||||
-rw-r--r-- | src/main/java/com/juick/www/api/Messages.java | 4 | ||||
-rw-r--r-- | src/main/java/com/juick/www/api/activity/Profile.java | 4 |
3 files changed, 15 insertions, 3 deletions
diff --git a/src/main/java/com/juick/ActivityPubManager.java b/src/main/java/com/juick/ActivityPubManager.java index 62faccf6..d5ee0b50 100644 --- a/src/main/java/com/juick/ActivityPubManager.java +++ b/src/main/java/com/juick/ActivityPubManager.java @@ -183,7 +183,6 @@ public class ActivityPubManager implements ActivityListener, NotificationListene update.setId(note.getId() + "#update"); update.setActor(me.getId()); update.setObject(note); - update.setTo(Collections.singletonList(Context.ACTIVITYSTREAMS_PUBLIC)); update.setPublished(Instant.now()); logger.info("{} sends note update to followers", me.getId()); activityToFollowers(user, me, update); @@ -313,8 +312,13 @@ public class ActivityPubManager implements ActivityListener, NotificationListene if (MessageUtils.isPM(msg)) { note.setTo(Collections.singletonList(profileUriBuilder.personUri(msg.getTo()))); } else { - note.setTo(Collections.singletonList(Context.ACTIVITYSTREAMS_PUBLIC)); - note.setCc(Collections.singletonList(profileUriBuilder.followersUri(msg.getUser()))); + var followers = Collections.singletonList(profileUriBuilder.followersUri(msg.getUser())); + if (!msg.FriendsOnly) { + note.setTo(Collections.singletonList(Context.ACTIVITYSTREAMS_PUBLIC)); + note.setCc(followers); + } else { + note.setTo(followers); + } } note.setPublished(msg.getCreated()); if (StringUtils.isNotBlank(msg.getAttachmentType())) { diff --git a/src/main/java/com/juick/www/api/Messages.java b/src/main/java/com/juick/www/api/Messages.java index f059aa88..d127d166 100644 --- a/src/main/java/com/juick/www/api/Messages.java +++ b/src/main/java/com/juick/www/api/Messages.java @@ -20,6 +20,7 @@ package com.juick.www.api; import com.juick.model.Message; import com.juick.model.Tag; import com.juick.model.User; +import com.juick.service.activities.UpdateEvent; import com.juick.util.WebUtils; import com.juick.www.WebApp; import com.juick.model.CommandResult; @@ -208,6 +209,9 @@ public class Messages { if (visitor.isPremium() || userService.isAdminUser(visitor)) { var msg = messagesService.getMessage(mid).orElseThrow(HttpNotFoundException::new); messagesService.setFriendsOnly(mid, !msg.FriendsOnly); + msg = messagesService.getMessage(mid).orElseThrow(HttpNotFoundException::new); + applicationEventPublisher.publishEvent( + new UpdateEvent(this, visitor, msg)); } else { throw new HttpBadRequestException(); } 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 f37ef6ff..68ea66ae 100644 --- a/src/main/java/com/juick/www/api/activity/Profile.java +++ b/src/main/java/com/juick/www/api/activity/Profile.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.model.Message; import com.juick.model.User; +import com.juick.util.HttpForbiddenException; import com.juick.util.formatters.PlainTextFormatter; import com.juick.model.CommandResult; import com.juick.ActivityPubManager; @@ -258,6 +259,9 @@ public class Profile { Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE }) public Context showNote(@PathVariable int mid, @PathVariable int rid) { var message = activityPubManager.findMessage(mid, rid); + if (!messagesService.canViewThread(mid, 0)) { + throw new HttpForbiddenException(); + } if (message != null) { return Context.build(activityPubManager.makeNote(message)); } |