From bab10770a77f5f756a58c4ca6f19dd51e1b492ee Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 20 Aug 2021 11:25:44 +0300 Subject: map NSFW tag to as:sensitive ActivityPub property --- src/main/java/com/juick/ActivityPubManager.java | 1 + src/main/java/com/juick/util/MessageUtils.java | 4 ++++ src/main/java/com/juick/www/api/activity/model/Context.java | 1 + .../java/com/juick/www/api/activity/model/objects/Note.java | 11 ++++++++++- 4 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/juick') diff --git a/src/main/java/com/juick/ActivityPubManager.java b/src/main/java/com/juick/ActivityPubManager.java index ad887819..8aa2ef78 100644 --- a/src/main/java/com/juick/ActivityPubManager.java +++ b/src/main/java/com/juick/ActivityPubManager.java @@ -354,6 +354,7 @@ public class ActivityPubManager implements ActivityListener, NotificationListene note.setCc(cc); } }); + note.setSensitive(MessageUtils.isSensitive(msg)); if (msg.isHtml()) { note.setContent(msg.getText()); } else { diff --git a/src/main/java/com/juick/util/MessageUtils.java b/src/main/java/com/juick/util/MessageUtils.java index 75a7fbf0..b0093b38 100644 --- a/src/main/java/com/juick/util/MessageUtils.java +++ b/src/main/java/com/juick/util/MessageUtils.java @@ -396,4 +396,8 @@ public class MessageUtils { } return result; } + + public static boolean isSensitive(Message msg) { + return msg.getTags().stream().anyMatch((t) -> t.getName().equals("NSFW")); + } } 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 f41aa69c..e75f2440 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 @@ -115,6 +115,7 @@ public abstract class Context { public static Context build(Context response) { response.context = new ArrayList<>(Arrays.asList(ACTIVITY_STREAMS_URI, SECURITY_URI)); response.context.add(Collections.singletonMap("Hashtag", "as:Hashtag")); + response.context.add(Collections.singletonMap("sensitive", "as:sensitive")); return response; } diff --git a/src/main/java/com/juick/www/api/activity/model/objects/Note.java b/src/main/java/com/juick/www/api/activity/model/objects/Note.java index 8aa196a3..66470b5c 100644 --- a/src/main/java/com/juick/www/api/activity/model/objects/Note.java +++ b/src/main/java/com/juick/www/api/activity/model/objects/Note.java @@ -29,11 +29,12 @@ public class Note extends Context { private List attachment; private List to; private List cc; + private boolean sensitive; public String getContent() { return content; } - + public void setContent(String content) { this.content = content; } @@ -78,4 +79,12 @@ public class Note extends Context { public void setInReplyTo(String inReplyTo) { this.inReplyTo = inReplyTo; } + + public boolean isSensitive() { + return sensitive; + } + + public void setSensitive(boolean sensitive) { + this.sensitive = sensitive; + } } -- cgit v1.2.3