From e43b64a9ea8bf80ec62cd59ad4eed19b112f5093 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 13 Mar 2024 02:20:33 +0300 Subject: ActivityPub: handle Flag with multiple objects TODO: refactor Activity to handle multiple objects --- .../com/juick/www/api/activity/model/Context.java | 10 ++++++ .../www/api/activity/model/activities/Flag.java | 38 ++++++++++++++++++++-- .../juick/www/api/activity/model/objects/Note.java | 10 ------ 3 files changed, 45 insertions(+), 13 deletions(-) (limited to 'src/main/java/com/juick/www/api/activity/model') 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 cfcc9379..80694b7a 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 @@ -68,6 +68,8 @@ public class Context implements Serializable { private Image icon; private Instant published; + private String content; + @JsonDeserialize(using = LinkValueDeserializer.class) private String url; @@ -172,4 +174,12 @@ public class Context implements Serializable { public void setCc(List cc) { this.cc = cc; } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } } diff --git a/src/main/java/com/juick/www/api/activity/model/activities/Flag.java b/src/main/java/com/juick/www/api/activity/model/activities/Flag.java index 2c61d344..1c37dec0 100644 --- a/src/main/java/com/juick/www/api/activity/model/activities/Flag.java +++ b/src/main/java/com/juick/www/api/activity/model/activities/Flag.java @@ -17,8 +17,40 @@ package com.juick.www.api.activity.model.activities; -import com.juick.www.api.activity.model.Activity; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.juick.www.api.activity.helpers.ActivityIdDeserializer; +import com.juick.www.api.activity.helpers.ContextDeserializer; +import com.juick.www.api.activity.model.Context; +import org.apache.commons.lang3.StringUtils; -public class Flag extends Activity { - +import java.util.List; +import java.util.UUID; + +public class Flag extends Context { + + @JsonDeserialize(using = ActivityIdDeserializer.class) + private String actor; + + public String getActor() { + return actor; + } + + public void setActor(String actor) { + this.actor = actor; + if (StringUtils.isEmpty(getId())) { + setId(String.format("%s#%s", this.actor, UUID.randomUUID())); + } + } + + @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) + private List object; + + public List getObject() { + return object; + } + + public void setObject(List object) { + this.object = object; + } } 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 465ad07c..6792c34e 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 @@ -24,7 +24,6 @@ import java.time.Instant; import java.util.List; public class Note extends Context { - private String content; private String attributedTo; private String inReplyTo; private List attachment; @@ -32,15 +31,6 @@ public class Note extends Context { private List cc; private boolean sensitive; private Instant updated; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - public String getAttributedTo() { return attributedTo; } -- cgit v1.2.3