aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-07 00:33:21 +0300
committerGravatar Vitaly Takmazov2018-10-07 00:33:21 +0300
commitb1499230aa4a53b8ee406d17b991100c17615f84 (patch)
treec96b614b8e6d3731b1499090c7071a53628936a6
parent2109acda68cce512b7b2dc80f8243651a213374d (diff)
ActivityPub: handle Delete activity
-rw-r--r--juick-common/src/main/java/com/juick/service/MessagesService.java2
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/Profile.java9
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java5
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java3
-rw-r--r--juick-server/src/test/resources/delete.json1
5 files changed, 20 insertions, 0 deletions
diff --git a/juick-common/src/main/java/com/juick/service/MessagesService.java b/juick-common/src/main/java/com/juick/service/MessagesService.java
index 2298e769..011780d4 100644
--- a/juick-common/src/main/java/com/juick/service/MessagesService.java
+++ b/juick-common/src/main/java/com/juick/service/MessagesService.java
@@ -134,4 +134,6 @@ public interface MessagesService {
boolean updateReplyUri(Message reply, URI replyUri);
boolean replyExists(URI replyUri);
+
+ boolean deleteReply(URI userUri, URI replyUri);
}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
index 6a35f3d9..96ed75d1 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
@@ -311,6 +311,15 @@ public class Profile {
}
}
}
+ if (activity instanceof Delete) {
+ Map<String, Object> tombstone = (Map<String, Object>) activity.getObject();
+ if (tombstone.get("type").equals("Tombstone")) {
+ URI actor = URI.create(activity.getActor());
+ URI reply = URI.create((String)tombstone.get("id"));
+ messagesService.deleteReply(actor, reply);
+ return new ResponseEntity<>(HttpStatus.OK);
+ }
+ }
logger.warn("Unknown activity: {}", jsonMapper.writeValueAsString(activity));
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
diff --git a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
index 4831c9d1..838dee48 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -1112,4 +1112,9 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
return jdbcTemplate.queryForList("SELECT reply_id FROM replies WHERE reply_uri=?",
Integer.class, replyUri.toASCIIString()).size() > 0;
}
+
+ @Override
+ public boolean deleteReply(URI userUri, URI replyUri) {
+ return jdbcTemplate.update("DELETE FROM replies WHERE user_uri=? AND reply_uri=?", userUri, replyUri) > 0;
+ }
}
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index 682b5084..49988097 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -35,6 +35,7 @@ import com.juick.server.api.activity.model.Context;
import com.juick.server.api.activity.model.Key;
import com.juick.server.api.activity.model.Person;
import com.juick.server.api.activity.model.activities.Create;
+import com.juick.server.api.activity.model.activities.Delete;
import com.juick.server.api.activity.model.activities.Follow;
import com.juick.server.api.activity.model.activities.Undo;
import com.juick.server.util.HttpUtils;
@@ -1696,6 +1697,8 @@ public class ServerTests {
Map<String, Object> note = (Map<String, Object>) create.getObject();
Map<String, Object> attachmentObj = (Map<String, Object> )((List<Object>) note.get("attachment")).get(0);
String attachment = attachmentObj != null ? (String)attachmentObj.get("url") : StringUtils.EMPTY;
+ String deleteJsonStr = IOUtils.toString(URI.create("classpath:delete.json"), StandardCharsets.UTF_8);
+ Delete delete = jsonMapper.readValue(deleteJsonStr, Delete.class);
}
@Test
diff --git a/juick-server/src/test/resources/delete.json b/juick-server/src/test/resources/delete.json
new file mode 100644
index 00000000..9bd3fdea
--- /dev/null
+++ b/juick-server/src/test/resources/delete.json
@@ -0,0 +1 @@
+{"type":"Delete","id":"https://mastodon.social/users/xwatt/statuses/100850777554564322#delete","to":["https://www.w3.org/ns/activitystreams#Public"],"actor":"https://mastodon.social/users/xwatt","object":{"id":"https://mastodon.social/users/xwatt/statuses/100850777554564322","type":"Tombstone","atomUri":"https://mastodon.social/users/xwatt/statuses/100850777554564322"},"type":"Delete","@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":{"@id":"as:movedTo","@type":"@id"},"Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","focalPoint":{"@container":"@list","@id":"toot:focalPoint"},"featured":{"@id":"toot:featured","@type":"@id"},"schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value"}]} \ No newline at end of file