aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-29 13:25:39 +0300
committerGravatar Vitaly Takmazov2018-11-29 14:32:03 +0300
commit33cc60ac5c5c4028c0f1fb64097523f606b6141e (patch)
treef5d8b7272a3df045d1bcea8853416c2c47f82380 /src/main
parentc89c69205a72d3324489f0d527276d9bcb99122a (diff)
ActivityPub likes fix
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/juick/server/ActivityPubManager.java13
-rw-r--r--src/main/java/com/juick/service/MessagesService.java4
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java22
3 files changed, 26 insertions, 13 deletions
diff --git a/src/main/java/com/juick/server/ActivityPubManager.java b/src/main/java/com/juick/server/ActivityPubManager.java
index de24985c..5249f3c9 100644
--- a/src/main/java/com/juick/server/ActivityPubManager.java
+++ b/src/main/java/com/juick/server/ActivityPubManager.java
@@ -1,6 +1,7 @@
package com.juick.server;
import com.juick.Message;
+import com.juick.Reaction;
import com.juick.User;
import com.juick.formatters.PlainTextFormatter;
import com.juick.server.api.activity.model.Context;
@@ -137,30 +138,28 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
@Override
public void processAnnounceEvent(AnnounceEvent event) {
- logger.info("Announce: {} -> {}", event.getActorUri(), event.getMessageUri());
UriComponents uriComponents = UriComponentsBuilder.fromUriString(event.getMessageUri()).build();
List<String> segments = uriComponents.getPathSegments();
if (segments.get(0).equals("n")) {
String[] ids = segments.get(1).split("-", 2);
- if (ids.length == 1) {
+ if (ids.length == 2 && Integer.valueOf(ids[1]) == 0) {
// only messages
logger.info("{} recommends {}", event.getActorUri(), Integer.valueOf(ids[0]));
- messagesService.recommendMessage(Integer.valueOf(ids[0]), 0, event.getActorUri());
+ messagesService.likeMessage(Integer.valueOf(ids[0]), 0, Reaction.LIKE, event.getActorUri());
}
}
}
@Override
public void undoAnnounceEvent(UndoAnnounceEvent event) {
- logger.info("Undo announce: {} -> {}", event.getActorUri(), event.getMessageUri());
UriComponents uriComponents = UriComponentsBuilder.fromUriString(event.getMessageUri()).build();
List<String> segments = uriComponents.getPathSegments();
- if (segments.get(0).equals("m")) {
+ if (segments.get(0).equals("n")) {
String[] ids = segments.get(1).split("-", 2);
- if (ids.length == 1) {
+ if (ids.length == 2 && Integer.valueOf(ids[1]) == 0) {
// only messages
logger.info("{} stop recommending {}", event.getActorUri(), Integer.valueOf(ids[0]));
- messagesService.recommendMessage(Integer.valueOf(ids[0]), 0, event.getActorUri());
+ messagesService.likeMessage(Integer.valueOf(ids[0]), 0, null, event.getActorUri());
}
}
}
diff --git a/src/main/java/com/juick/service/MessagesService.java b/src/main/java/com/juick/service/MessagesService.java
index fb2b3d95..4bcdba46 100644
--- a/src/main/java/com/juick/service/MessagesService.java
+++ b/src/main/java/com/juick/service/MessagesService.java
@@ -47,9 +47,9 @@ public interface MessagesService {
List<Reaction> listReactions();
- RecommendStatus likeMessage(int mid, int vuid, int reactionId);
+ RecommendStatus likeMessage(int mid, int vuid, Integer reaction);
- RecommendStatus likeMessage(int mid, int vuid, int reactionId, String userUri);
+ RecommendStatus likeMessage(int mid, int vuid, Integer reaction, String userUri);
boolean canViewThread(int mid, int uid);
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java
index f45ee351..7951eb42 100644
--- a/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -268,15 +268,29 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
}
@Override
- public RecommendStatus likeMessage(int mid, int vuid, int reactionId) {
- return likeMessage(mid, vuid, reactionId, StringUtils.EMPTY);
+ public RecommendStatus likeMessage(int mid, int vuid, Integer reaction) {
+ return likeMessage(mid, vuid, reaction, StringUtils.EMPTY);
}
@Transactional
@Override
- public RecommendStatus likeMessage(int mid, int vuid, int reactionId, String userUri) throws IllegalArgumentException {
+ public RecommendStatus likeMessage(int mid, int vuid, Integer reaction, String userUri) throws IllegalArgumentException {
+ if (reaction == null) {
+ SqlParameterSource sqlParameterSource = new MapSqlParameterSource()
+ .addValue("uid", vuid)
+ .addValue("uri", userUri)
+ .addValue("like_id", reaction)
+ .addValue("mid", mid);
+ boolean wasDeleted = getNamedParameterJdbcTemplate()
+ .update("DELETE FROM favorites WHERE user_id=:uid AND message_id=:mid AND like_id=:like_id AND user_uri=:uri", sqlParameterSource) > 0;
+ if (wasDeleted) {
+ return RecommendStatus.Deleted;
+ } else {
+ return RecommendStatus.Error;
+ }
+ }
boolean wasAdded = getJdbcTemplate()
- .update("INSERT INTO favorites(user_id, message_id, ts, like_id, user_uri) VALUES (?, ?, NOW(), ?, ?)", vuid, mid, reactionId, userUri) == 1;
+ .update("INSERT INTO favorites(user_id, message_id, ts, like_id, user_uri) VALUES (?, ?, NOW(), ?, ?)", vuid, mid, reaction, userUri) == 1;
if (wasAdded) {
return RecommendStatus.Added;
}