From eb93d08061e2220af8036aea00cf163204953059 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Sun, 22 Aug 2021 08:31:49 +0300
Subject: ActivityPub: make Mastodon happy with hashtags
---
.../java/com/juick/www/api/activity/model/objects/Hashtag.java | 2 +-
src/main/java/com/juick/www/api/activity/model/objects/Link.java | 7 +++++++
.../java/com/juick/www/api/activity/model/objects/Mention.java | 3 +--
src/main/resources/templates/views/macros/tags.html | 4 ++--
src/test/java/com/juick/UserTest.java | 6 +++++-
5 files changed, 16 insertions(+), 6 deletions(-)
(limited to 'src')
diff --git a/src/main/java/com/juick/www/api/activity/model/objects/Hashtag.java b/src/main/java/com/juick/www/api/activity/model/objects/Hashtag.java
index 0f524d72..cecefc18 100644
--- a/src/main/java/com/juick/www/api/activity/model/objects/Hashtag.java
+++ b/src/main/java/com/juick/www/api/activity/model/objects/Hashtag.java
@@ -20,7 +20,7 @@ package com.juick.www.api.activity.model.objects;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
-public class Hashtag extends Mention {
+public class Hashtag extends Link {
@JsonCreator
public Hashtag(@JsonProperty("href") String href, @JsonProperty("name") String name) {
super(href, name);
diff --git a/src/main/java/com/juick/www/api/activity/model/objects/Link.java b/src/main/java/com/juick/www/api/activity/model/objects/Link.java
index c544c4b2..5c31d789 100644
--- a/src/main/java/com/juick/www/api/activity/model/objects/Link.java
+++ b/src/main/java/com/juick/www/api/activity/model/objects/Link.java
@@ -17,9 +17,16 @@
package com.juick.www.api.activity.model.objects;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
import com.juick.www.api.activity.model.Context;
public class Link extends Context {
+ @JsonCreator
+ public Link(@JsonProperty("href") String href, @JsonProperty("name") String name) {
+ this.setHref(href);
+ this.setName(name);
+ }
private String href;
public String getHref() {
diff --git a/src/main/java/com/juick/www/api/activity/model/objects/Mention.java b/src/main/java/com/juick/www/api/activity/model/objects/Mention.java
index 30ba4d10..169a8960 100644
--- a/src/main/java/com/juick/www/api/activity/model/objects/Mention.java
+++ b/src/main/java/com/juick/www/api/activity/model/objects/Mention.java
@@ -26,7 +26,6 @@ import com.juick.util.UserUtils;
public class Mention extends Link {
@JsonCreator
public Mention(@JsonProperty("href") String href, @JsonProperty("name") String name) {
- this.setHref(href);
- this.setName(UserUtils.getPersonIdentifier(name, URI.create(href)));
+ super(href, UserUtils.getPersonIdentifier(name, URI.create(href)));
}
}
diff --git a/src/main/resources/templates/views/macros/tags.html b/src/main/resources/templates/views/macros/tags.html
index 08687f5a..c52847fc 100644
--- a/src/main/resources/templates/views/macros/tags.html
+++ b/src/main/resources/templates/views/macros/tags.html
@@ -1,11 +1,11 @@
{% macro tags(uname="", tagsList) %}
{% for tag in tagsList %}
-{{ tag }}
+{{ tag }}
{% endfor %}
{% endmacro %}
{% macro allTags(baseUri, tagsList) %}
{% for tag in tagsList %}
-#{{ tag }}
+#{{ tag }}
{% endfor %}
{% endmacro %}
\ No newline at end of file
diff --git a/src/test/java/com/juick/UserTest.java b/src/test/java/com/juick/UserTest.java
index 6c0cdb88..df89bb5b 100644
--- a/src/test/java/com/juick/UserTest.java
+++ b/src/test/java/com/juick/UserTest.java
@@ -20,6 +20,7 @@ package com.juick;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.juick.model.User;
import com.juick.test.util.MockUtils;
+import com.juick.www.api.activity.model.objects.Hashtag;
import com.juick.www.api.activity.model.objects.Mention;
import org.junit.jupiter.api.Test;
@@ -39,8 +40,11 @@ public class UserTest {
assertEquals(ugnich, jsonUgnich);
}
@Test
- public void mentionFormat() {
+ public void linkFormat() {
Mention mention = new Mention("https://example.com/users/test", "testuser");
+ assertEquals("Mention", mention.getType());
assertEquals("@testuser@example.com", mention.getName());
+ Hashtag tag = new Hashtag("https://example.com/t/test", "testtag");
+ assertEquals("testtag", tag.getName());
}
}
--
cgit v1.2.3