From 2ae9bb8e420d2c68fef9215fbed6d15c3a434b2e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 8 Oct 2018 13:02:06 +0300 Subject: user_uri in favorites --- .../java/com/juick/service/MessagesService.java | 4 ++++ .../com/juick/server/api/activity/Profile.java | 23 +++++++++++++++--- .../juick/server/api/activity/model/Context.java | 1 + .../com/juick/service/MessagesServiceImpl.java | 27 +++++++++++++++++----- .../db/migration/V1.10__favorites_user_uri.sql | 3 +++ 5 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 juick-server/src/main/resources/db/migration/V1.10__favorites_user_uri.sql 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 011780d4..1bbd62f8 100644 --- a/juick-common/src/main/java/com/juick/service/MessagesService.java +++ b/juick-common/src/main/java/com/juick/service/MessagesService.java @@ -44,12 +44,16 @@ public interface MessagesService { Deleted } + RecommendStatus recommendMessage(int mid, int vuid, String userUri); + RecommendStatus recommendMessage(int mid, int vuid); List listReactions(); RecommendStatus likeMessage(int mid, int vuid, int reactionId); + RecommendStatus likeMessage(int mid, int vuid, int reactionId, String userUri); + boolean canViewThread(int mid, int uid); 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; } @@ -248,6 +253,11 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ return RecommendStatus.Error; } + @Override + public RecommendStatus recommendMessage(int mid, int vuid) { + return recommendMessage(mid, vuid, StringUtils.EMPTY); + } + @Override public List listReactions() { return jdbcTemplate.query("SELECT like_id, description FROM reactions", (rs, rowNum) -> { @@ -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 -- cgit v1.2.3