aboutsummaryrefslogtreecommitdiff
path: root/juick-server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-08 13:02:06 +0300
committerGravatar Vitaly Takmazov2018-10-08 13:02:06 +0300
commit2ae9bb8e420d2c68fef9215fbed6d15c3a434b2e (patch)
tree75851e8d1233b4298fcfbea7a3c5dd94701799c1 /juick-server
parent5e3bb9067b3052c0805b7b1d59215f2bd4b73905 (diff)
user_uri in favorites
Diffstat (limited to 'juick-server')
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/Profile.java23
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/Context.java1
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java27
-rw-r--r--juick-server/src/main/resources/db/migration/V1.10__favorites_user_uri.sql3
4 files changed, 45 insertions, 9 deletions
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 96ed75d1..669a28df 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
@@ -1,6 +1,5 @@
package com.juick.server.api.activity;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.juick.User;
import com.juick.model.CommandResult;
@@ -8,7 +7,15 @@ import com.juick.server.ActivityPubManager;
import com.juick.server.CommandsManager;
import com.juick.server.KeystoreManager;
import com.juick.server.SignatureManager;
-import com.juick.server.api.activity.model.*;
+import com.juick.server.api.activity.model.Activity;
+import com.juick.server.api.activity.model.Context;
+import com.juick.server.api.activity.model.Image;
+import com.juick.server.api.activity.model.Key;
+import com.juick.server.api.activity.model.Note;
+import com.juick.server.api.activity.model.OrderedCollection;
+import com.juick.server.api.activity.model.OrderedCollectionPage;
+import com.juick.server.api.activity.model.Person;
+import com.juick.server.api.activity.model.activities.Announce;
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;
@@ -29,7 +36,13 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
@@ -320,6 +333,10 @@ public class Profile {
return new ResponseEntity<>(HttpStatus.OK);
}
}
+ if (activity instanceof Announce) {
+ logger.info("Announce: {}", jsonMapper.writeValueAsString(activity));
+ 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/server/api/activity/model/Context.java b/juick-server/src/main/java/com/juick/server/api/activity/model/Context.java
index 64779b51..0c47ef73 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/Context.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/model/Context.java
@@ -20,6 +20,7 @@ import java.util.List;
@JsonSubTypes.Type(value = Undo.class, name = "Undo"),
@JsonSubTypes.Type(value = Like.class, name = "Like"),
@JsonSubTypes.Type(value = Block.class, name = "Block"),
+ @JsonSubTypes.Type(value = Announce.class, name = "Announce"),
@JsonSubTypes.Type(value = Activity.class, name = "Activity"),
@JsonSubTypes.Type(value = Image.class, name = "Image"),
@JsonSubTypes.Type(value = Key.class, name = "Key"),
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 62cdff0c..1d52e48a 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -233,14 +233,19 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Transactional
@Override
- public RecommendStatus recommendMessage(final int mid, final int vuid) {
- int wasDeleted = getJdbcTemplate()
- .update("DELETE FROM favorites WHERE user_id=? AND message_id=? and like_id=?", vuid, mid, Reaction.LIKE);
+ public RecommendStatus recommendMessage(final int mid, final int vuid, final String userUri) {
+ SqlParameterSource sqlParameterSource = new MapSqlParameterSource()
+ .addValue("uid", vuid)
+ .addValue("uri", userUri)
+ .addValue("like_id", Reaction.LIKE)
+ .addValue("mid", mid);
+ int wasDeleted = getNamedParameterJdbcTemplate()
+ .update("DELETE FROM favorites WHERE user_id=:uid AND message_id=:mid AND like_id=:like_id AND user_uri=:uri", sqlParameterSource);
if (wasDeleted > 0) {
return RecommendStatus.Deleted;
} else {
boolean wasAdded = getJdbcTemplate()
- .update("INSERT INTO favorites(user_id, message_id, ts, like_id ) VALUES (?, ?, NOW(), ?)", vuid, mid,Reaction.LIKE) == 1;
+ .update("INSERT INTO favorites(user_id, message_id, ts, like_id, user_uri) VALUES (?, ?, NOW(), ?, ?)", vuid, mid,Reaction.LIKE, userUri) == 1;
if (wasAdded) {
return RecommendStatus.Added;
}
@@ -249,6 +254,11 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
}
@Override
+ public RecommendStatus recommendMessage(int mid, int vuid) {
+ return recommendMessage(mid, vuid, StringUtils.EMPTY);
+ }
+
+ @Override
public List<Reaction> listReactions() {
return jdbcTemplate.query("SELECT like_id, description FROM reactions", (rs, rowNum) -> {
Reaction reaction = new Reaction(rs.getInt("like_id"));
@@ -257,11 +267,16 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
});
}
+ @Override
+ public RecommendStatus likeMessage(int mid, int vuid, int reactionId) {
+ return likeMessage(mid, vuid, reactionId, StringUtils.EMPTY);
+ }
+
@Transactional
@Override
- public RecommendStatus likeMessage(int mid, int vuid, int reactionId) throws IllegalArgumentException {
+ public RecommendStatus likeMessage(int mid, int vuid, int reactionId, String userUri) throws IllegalArgumentException {
boolean wasAdded = getJdbcTemplate()
- .update("INSERT INTO favorites(user_id, message_id, ts, like_id ) VALUES (?, ?, NOW(), ?)", vuid, mid, reactionId) == 1;
+ .update("INSERT INTO favorites(user_id, message_id, ts, like_id, user_uri) VALUES (?, ?, NOW(), ?, ?)", vuid, mid, reactionId, userUri) == 1;
if (wasAdded) {
return RecommendStatus.Added;
}
diff --git a/juick-server/src/main/resources/db/migration/V1.10__favorites_user_uri.sql b/juick-server/src/main/resources/db/migration/V1.10__favorites_user_uri.sql
new file mode 100644
index 00000000..8f382398
--- /dev/null
+++ b/juick-server/src/main/resources/db/migration/V1.10__favorites_user_uri.sql
@@ -0,0 +1,3 @@
+ALTER TABLE favorites ADD COLUMN user_uri char(255) DEFAULT NULL;
+UPDATE favorites SET user_uri='' WHERE user_uri IS NULL;
+ALTER TABLE favorites MODIFY COLUMN user_uri char(255) NOT NULL DEFAULT ''; \ No newline at end of file