From 90201606bb485988f5a85cd578f3f5b8ecddf4db Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 26 Apr 2023 09:11:53 +0300 Subject: Expose `friendsOnly` message property over API --- src/main/java/com/juick/ActivityPubManager.java | 2 +- src/main/java/com/juick/model/Message.java | 14 ++++++++++---- src/main/java/com/juick/service/MessagesServiceImpl.java | 2 +- src/main/java/com/juick/util/MessageUtils.java | 2 +- src/main/java/com/juick/www/api/Messages.java | 4 +--- src/main/resources/templates/views/partial/message.html | 2 +- src/main/resources/templates/views/thread.html | 4 ++-- 7 files changed, 17 insertions(+), 13 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/juick/ActivityPubManager.java b/src/main/java/com/juick/ActivityPubManager.java index d5ee0b50..566cc1fd 100644 --- a/src/main/java/com/juick/ActivityPubManager.java +++ b/src/main/java/com/juick/ActivityPubManager.java @@ -313,7 +313,7 @@ public class ActivityPubManager implements ActivityListener, NotificationListene note.setTo(Collections.singletonList(profileUriBuilder.personUri(msg.getTo()))); } else { var followers = Collections.singletonList(profileUriBuilder.followersUri(msg.getUser())); - if (!msg.FriendsOnly) { + if (!msg.isFriendsOnly()) { note.setTo(Collections.singletonList(Context.ACTIVITYSTREAMS_PUBLIC)); note.setCc(followers); } else { diff --git a/src/main/java/com/juick/model/Message.java b/src/main/java/com/juick/model/Message.java index d5066af6..3c86970b 100644 --- a/src/main/java/com/juick/model/Message.java +++ b/src/main/java/com/juick/model/Message.java @@ -30,7 +30,6 @@ import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import org.apache.commons.lang3.builder.ToStringBuilder; -import javax.annotation.Nonnull; import java.io.Serializable; import java.net.URI; import java.time.Instant; @@ -59,8 +58,7 @@ public class Message implements Comparable, Serializable { @JsonIgnore private int privacy = 1; @XmlTransient - @JsonIgnore - public boolean FriendsOnly = false; + private boolean friendsOnly = false; @XmlTransient @JsonIgnore public boolean ReadOnly = false; @@ -105,7 +103,7 @@ public class Message implements Comparable, Serializable { .append("rid", rid) .append("replyto", replyto) .append("privacy", privacy) - .append("FriendsOnly", FriendsOnly) + .append("friendsOnly", isFriendsOnly()) .append("ReadOnly", ReadOnly) .append("Hidden", Hidden) .append("VisitorCanComment", VisitorCanComment) @@ -394,4 +392,12 @@ public class Message implements Comparable, Serializable { public void setSubscribed(boolean subscribed) { this.subscribed = subscribed; } + + public boolean isFriendsOnly() { + return friendsOnly; + } + + public void setFriendsOnly(boolean friendsOnly) { + this.friendsOnly = friendsOnly; + } } diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index 9da5c16c..fc190c97 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -88,7 +88,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ msg.setCreated(MessagesServiceImpl.this.getOffsetDateTime(rs, 7).toInstant()); msg.ReadOnly = rs.getBoolean(8); msg.setPrivacy(rs.getInt(9)); - msg.FriendsOnly = msg.getPrivacy() < 0; + msg.setFriendsOnly(msg.getPrivacy() < 0); msg.setReplies(rs.getInt(10)); msg.setAttachmentType(rs.getString(11)); msg.Hidden = rs.getBoolean(13); diff --git a/src/main/java/com/juick/util/MessageUtils.java b/src/main/java/com/juick/util/MessageUtils.java index 6a325c0c..ff0641ae 100644 --- a/src/main/java/com/juick/util/MessageUtils.java +++ b/src/main/java/com/juick/util/MessageUtils.java @@ -326,7 +326,7 @@ public class MessageUtils { for (Tag Tag : tags) builder.append(" *").append(Tag.getName()); - if (msg.FriendsOnly) + if (msg.isFriendsOnly()) builder.append(" *friends"); if (msg.ReadOnly) builder.append(" *readonly"); diff --git a/src/main/java/com/juick/www/api/Messages.java b/src/main/java/com/juick/www/api/Messages.java index ead2c076..ef55944b 100644 --- a/src/main/java/com/juick/www/api/Messages.java +++ b/src/main/java/com/juick/www/api/Messages.java @@ -21,7 +21,6 @@ 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; import com.juick.util.HttpBadRequestException; @@ -43,7 +42,6 @@ import org.springframework.web.bind.annotation.*; import javax.inject.Inject; import java.io.IOException; import java.util.*; -import java.util.stream.Collectors; /** * @author ugnich @@ -216,7 +214,7 @@ public class Messages { public void togglePrivacy(@Parameter(hidden = true) User visitor, @RequestParam Integer mid) { if (visitor.isPremium() || userService.isAdminUser(visitor)) { var msg = messagesService.getMessage(mid).orElseThrow(HttpNotFoundException::new); - messagesService.setFriendsOnly(mid, !msg.FriendsOnly); + messagesService.setFriendsOnly(mid, !msg.isFriendsOnly()); msg = messagesService.getMessage(mid).orElseThrow(HttpNotFoundException::new); applicationEventPublisher.publishEvent( new UpdateEvent(this, visitor, msg)); diff --git a/src/main/resources/templates/views/partial/message.html b/src/main/resources/templates/views/partial/message.html index e9ddd3db..219b1b1a 100644 --- a/src/main/resources/templates/views/partial/message.html +++ b/src/main/resources/templates/views/partial/message.html @@ -7,7 +7,7 @@ {{ msg.user.name }}