diff options
author | Vitaly Takmazov | 2023-04-26 09:11:53 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-04-26 09:12:11 +0300 |
commit | 90201606bb485988f5a85cd578f3f5b8ecddf4db (patch) | |
tree | 009e6691d9b32e1cb8605592fcaeed2b8e90977a /src | |
parent | bd521d4b86f9b3b16caaba714d04e05c2f288847 (diff) |
Expose `friendsOnly` message property over API
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/juick/ActivityPubManager.java | 2 | ||||
-rw-r--r-- | src/main/java/com/juick/model/Message.java | 14 | ||||
-rw-r--r-- | src/main/java/com/juick/service/MessagesServiceImpl.java | 2 | ||||
-rw-r--r-- | src/main/java/com/juick/util/MessageUtils.java | 2 | ||||
-rw-r--r-- | src/main/java/com/juick/www/api/Messages.java | 4 | ||||
-rw-r--r-- | src/main/resources/templates/views/partial/message.html | 2 | ||||
-rw-r--r-- | src/main/resources/templates/views/thread.html | 4 | ||||
-rw-r--r-- | src/test/java/com/juick/MessageTest.java | 2 | ||||
-rw-r--r-- | src/test/java/com/juick/server/tests/ServerTests.java | 7 |
9 files changed, 21 insertions, 18 deletions
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<Message>, 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<Message>, 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<Message>, 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 @@ <img src="{{ msg.user.avatar }}" alt="{{ msg.user.name }}"/></a> </div> <div class="msg-ts"> - {% if msg.FriendsOnly %} + {% if msg.friendsOnly %} <i data-icon="ei-lock" data-size="s"></i> · {% endif %} <a href="/{{ msg.user.name }}/{{ msg.mid }}"> diff --git a/src/main/resources/templates/views/thread.html b/src/main/resources/templates/views/thread.html index 819a627e..3974fddb 100644 --- a/src/main/resources/templates/views/thread.html +++ b/src/main/resources/templates/views/thread.html @@ -12,7 +12,7 @@ <a href="/{{ msg.user.name }}/"><span>{{ msg.user.name }}</span>{% if msg.user.premium %}<span style="color: green;"><i data-icon="ei-star" data-size="s"></i></span>{% endif %}</a> </span> <div class="msg-ts"> - {% if msg.FriendsOnly %} + {% if msg.friendsOnly %} <i data-icon="ei-lock" data-size="s"></i> · {% endif %} <a href="/{{ msg.user.name }}/{{ msg.mid }}"> @@ -43,7 +43,7 @@ {% if visitor.uid == msg.user.uid and (msg.user.premium or beans.userServiceImpl.isAdminUser(msg.user)) %} <a href="/{{ msg.mid }}" class="a-privacy msg-button"> <span class="msg-button-icon"> - {% if msg.FriendsOnly %} + {% if msg.friendsOnly %} <i data-icon="ei-unlock" data-size="s"></i> <span> {{ i18n("messages","message.unlock") }}</span> {% else %} diff --git a/src/test/java/com/juick/MessageTest.java b/src/test/java/com/juick/MessageTest.java index 9c079fa3..c4aae8d5 100644 --- a/src/test/java/com/juick/MessageTest.java +++ b/src/test/java/com/juick/MessageTest.java @@ -132,7 +132,7 @@ public class MessageTest { assertThat(MessageUtils.getTagsString(message), is(emptyString())); - message.FriendsOnly = true; + message.setFriendsOnly(true); assertThat(MessageUtils.getTagsString(message), is(emptyString())); diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index e8a90e92..ce9b49d0 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -71,7 +71,6 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.text.StringEscapeUtils; -import org.apache.http.conn.ssl.TrustSelfSignedStrategy; import org.junit.jupiter.api.*; import org.mockito.ArgumentCaptor; import org.mockito.Captor; @@ -2666,19 +2665,19 @@ public class ServerTests { userService.setPremium(ugnich.getUid(), true); int mid = messagesService.createMessage(ugnich.getUid(), "hidden", "", Collections.emptySet()); var msg = messagesService.getMessage(ugnich.getUid(), mid).orElseThrow(); - assertThat(msg.FriendsOnly, is(false)); + assertThat(msg.isFriendsOnly(), is(false)); mockMvc.perform(post("/api/messages/set_privacy?mid=" + mid) .with(httpBasic(ugnichName, ugnichPassword))) .andExpect(status().isOk()); msg = messagesService.getMessage(ugnich.getUid(), mid).orElseThrow(); - assertThat(msg.FriendsOnly, is(true)); + assertThat(msg.isFriendsOnly(), is(true)); var res = commandsManager.processCommand(freefd, String.format("#%d reply", mid), emptyUri); assertThat(res.getNewMessage(), is(Optional.empty())); mockMvc.perform(post("/api/messages/set_privacy?mid=" + mid) .with(httpBasic(ugnichName, ugnichPassword))) .andExpect(status().isOk()); msg = messagesService.getMessage(ugnich.getUid(), mid).orElseThrow(); - assertThat(msg.FriendsOnly, is(false)); + assertThat(msg.isFriendsOnly(), is(false)); userService.setPremium(ugnich.getUid(), false); mockMvc.perform(post("/api/messages/set_privacy?mid=" + mid) .with(httpBasic(ugnichName, ugnichPassword))) |