aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar mykhailo.dubovskyi2018-04-18 15:57:53 +0300
committerGravatar Vitaly Takmazov2018-04-20 11:03:47 +0300
commit842e903d5b987dd23e82a423bddae75acdea0c9c (patch)
tree59eabfb9969b6cbe00703674f8d3ddb7d2e029e0
parentef1c674b0dc1979e46e970ad67ccc7a9bb67b001 (diff)
Like -> Reaction
-rw-r--r--juick-common/src/main/java/com/juick/Message.java16
-rw-r--r--juick-common/src/main/java/com/juick/Reaction.java45
-rw-r--r--juick-common/src/main/java/com/juick/service/MessagesService.java8
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java72
-rw-r--r--juick-server-jdbc/src/main/resources/juick.sql19
-rw-r--r--juick-server-jdbc/src/main/resources/schema.sql12
-rw-r--r--juick-server/src/main/java/com/juick/server/TelegramBotManager.java4
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Messages.java1
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Post.java27
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java84
-rw-r--r--juick-server/src/test/resources/data.sql7
-rw-r--r--juick-www/src/main/resources/templates/views/partial/message.html6
-rw-r--r--juick-www/src/main/resources/templates/views/thread.html15
13 files changed, 282 insertions, 34 deletions
diff --git a/juick-common/src/main/java/com/juick/Message.java b/juick-common/src/main/java/com/juick/Message.java
index 72a25dfb..45a0fdd4 100644
--- a/juick-common/src/main/java/com/juick/Message.java
+++ b/juick-common/src/main/java/com/juick/Message.java
@@ -27,7 +27,9 @@ import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.time.Instant;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* @author Ugnich Anton
@@ -72,9 +74,12 @@ public class Message implements Comparable {
private User to;
private Recommendation Recommendation;
private String replyQuote;
+ @XmlTransient
+ private Set<Reaction> reactions;
public Message() {
tags = new ArrayList<>();
+ reactions = new HashSet<>();
}
@Override
@@ -91,6 +96,7 @@ public class Message implements Comparable {
.append("VisitorCanComment", VisitorCanComment)
.append("replies", replies)
.append("likes", likes)
+ .append("reactions", reactions)
.toString();
}
@@ -301,4 +307,14 @@ public class Message implements Comparable {
public void setUnread(boolean unread) {
this.unread = unread;
}
+
+
+ @XmlTransient
+ public Set<Reaction> getReactions() {
+ return reactions;
+ }
+
+ public void setReactions(Set<Reaction> reactions) {
+ this.reactions = reactions;
+ }
}
diff --git a/juick-common/src/main/java/com/juick/Reaction.java b/juick-common/src/main/java/com/juick/Reaction.java
new file mode 100644
index 00000000..536ac241
--- /dev/null
+++ b/juick-common/src/main/java/com/juick/Reaction.java
@@ -0,0 +1,45 @@
+package com.juick;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+public class Reaction {
+
+ public static final int LIKE = 1;
+
+ private final int id;
+ private String description;
+ private int count;
+
+ public Reaction(int id) {
+ this.id = id;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this)
+ .append("id", getId())
+ .append("description", description)
+ .append("count", count)
+ .build();
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ public int getId() {
+ return id;
+ }
+}
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 34c15271..853e4271 100644
--- a/juick-common/src/main/java/com/juick/service/MessagesService.java
+++ b/juick-common/src/main/java/com/juick/service/MessagesService.java
@@ -17,11 +17,14 @@
package com.juick.service;
+import com.juick.Reaction;
import com.juick.User;
import com.juick.server.helpers.ResponseReply;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* Created by aalexeev on 11/13/16.
@@ -41,6 +44,9 @@ public interface MessagesService {
RecommendStatus recommendMessage(int mid, int vuid);
+ RecommendStatus likeMessage(int mid, int vuid, int reactionId);
+
+
boolean canViewThread(int mid, int uid);
boolean isReadOnly(int mid);
@@ -95,6 +101,8 @@ public interface MessagesService {
List<com.juick.Message> getMessages(List<Integer> mids);
+ Map<Integer,Set<Reaction>> updateReactionsFor(final List<Integer> mid);
+
List<com.juick.Message> getReplies(User user, int mid);
boolean setMessagePopular(int mid, int popular);
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
index c0dccc6a..362a918c 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -17,9 +17,7 @@
package com.juick.service;
-import com.juick.Message;
-import com.juick.Tag;
-import com.juick.User;
+import com.juick.*;
import com.juick.server.helpers.PrivacyOpts;
import com.juick.server.helpers.ResponseReply;
import com.juick.util.MessageUtils;
@@ -105,6 +103,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
}
}
+
+
/**
* @see <a href="https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-type-conversions.html">Java, JDBC and MySQL Types</a>
*/
@@ -226,12 +226,12 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Override
public RecommendStatus recommendMessage(final int mid, final int vuid) {
int wasDeleted = getJdbcTemplate()
- .update("DELETE FROM favorites WHERE user_id=? AND message_id=?", vuid, mid);
+ .update("DELETE FROM favorites WHERE user_id=? AND message_id=? and like_id=?", vuid, mid, Reaction.LIKE);
if (wasDeleted > 0) {
return RecommendStatus.Deleted;
} else {
boolean wasAdded = getJdbcTemplate()
- .update("INSERT INTO favorites(user_id, message_id, ts) VALUES (?, ?, NOW())", vuid, mid) == 1;
+ .update("INSERT INTO favorites(user_id, message_id, ts, like_id ) VALUES (?, ?, NOW(), ?)", vuid, mid,Reaction.LIKE) == 1;
if (wasAdded) {
return RecommendStatus.Added;
}
@@ -239,6 +239,19 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
return RecommendStatus.Error;
}
+ @Override
+ public RecommendStatus likeMessage(int mid, int vuid, int reactionId) throws IllegalArgumentException {
+ if(reactionId == Reaction.LIKE) throw new IllegalArgumentException("this reaction type does not support here");
+
+ boolean wasAdded = getJdbcTemplate()
+ .update("INSERT INTO favorites(user_id, message_id, ts, like_id ) VALUES (?, ?, NOW(), ?)", vuid, mid, reactionId) == 1;
+ if (wasAdded) {
+ return RecommendStatus.Added;
+ }
+
+ return RecommendStatus.Error;
+ }
+
@Transactional(readOnly = true)
@Override
public boolean canViewThread(final int mid, final int uid) {
@@ -299,6 +312,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Transactional(readOnly = true)
@Override
public com.juick.Message getMessage(final int mid) {
+
List<com.juick.Message> list = getJdbcTemplate().query(
"SELECT messages.message_id as mid, 0 as rid, 0 as replyto, "
+ "messages.user_id as uid, users.nick, users.banned as banned, "
@@ -319,8 +333,13 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "privacy, replies, attach, place_id, lat, lon, tags, repliesby, q",
new MessageMapper(),
mid);
-
- return list.isEmpty() ? null : list.get(0);
+ if (!list.isEmpty()) {
+ final Message message = list.get(0);
+ Map<Integer, Set<Reaction>> reactionStats = updateReactionsFor(Collections.singletonList(mid));
+ message.setReactions(reactionStats.get(message.getMid()));
+ return message;
+ }
+ return null;
}
@Transactional(readOnly = true)
@@ -740,6 +759,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Override
public List<com.juick.Message> getMessages(final List<Integer> mids) {
if (CollectionUtils.isNotEmpty(mids)) {
+
List<com.juick.Message> msgs = getNamedParameterJdbcTemplate().query(
"SELECT messages.message_id, 0 as rid, 0 as replyto, "
+ "messages.user_id,users.nick, 0 as banned, "
@@ -758,12 +778,50 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "WHERE messages.message_id IN (:ids) GROUP BY messages.message_id",
new MapSqlParameterSource("ids", mids),
new MessageMapper());
+
+
+ Map<Integer,Set<Reaction>> likes = updateReactionsFor(mids);
+
+ msgs.forEach(i -> i.setReactions(likes.get(i.getMid())));
+
msgs.sort(Comparator.comparing(item -> mids.indexOf(item.getMid())));
+
return msgs;
}
return Collections.emptyList();
}
+
+ @Transactional(readOnly = true)
+ @Override
+ public Map<Integer,Set<Reaction>> updateReactionsFor(final List<Integer> mids) {
+
+ return getNamedParameterJdbcTemplate().query("select f.message_id as mid, f.like_id as lid, " +
+ "r.description as desc, count(f.like_id) as count" +
+ " from favorites f LEFT JOIN reactions r ON f.like_id = r.like_id " +
+ " where f.message_id IN (:mids) " +
+ " group by f.message_id, f.like_id", new MapSqlParameterSource("mids", mids), (ResultSet rs) -> {
+ Map<Integer,Set<Reaction>> results = new HashMap<>();
+
+
+ while (rs.next()) {
+ int messageId = rs.getInt("message_id");
+ int likeId = rs.getInt("like_id");
+ int count = rs.getInt("count");
+ String description = rs.getString("description");
+ Reaction reaction = new Reaction(likeId);
+ reaction.setCount(count);
+ reaction.setDescription(description);
+ results.computeIfAbsent(messageId, HashSet::new);
+ results.get(messageId).add(reaction);
+ }
+
+ return results;
+ });
+
+ }
+
+
@Transactional
@Override
public List<Message> getReplies(final User user, final int mid) {
diff --git a/juick-server-jdbc/src/main/resources/juick.sql b/juick-server-jdbc/src/main/resources/juick.sql
index d13a06a2..4f15ba70 100644
--- a/juick-server-jdbc/src/main/resources/juick.sql
+++ b/juick-server-jdbc/src/main/resources/juick.sql
@@ -177,9 +177,11 @@ CREATE TABLE `favorites` (
`user_id` int(10) unsigned NOT NULL,
`message_id` int(10) unsigned NOT NULL,
`ts` datetime NOT NULL,
+ `like_id` int(10) unsigned NOT NULL DEFAULT '1',
UNIQUE KEY `user_id_2` (`user_id`,`message_id`),
KEY `user_id` (`user_id`),
- KEY `message_id` (`message_id`)
+ KEY `message_id` (`message_id`),
+ KEY `like_id` (`like_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -504,6 +506,19 @@ CREATE TABLE `presence` (
/*!40101 SET character_set_client = @saved_cs_client */;
--
+-- Table structure for table `reactions`
+--
+
+DROP TABLE IF EXISTS `reactions`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `reactions` (
+ `like_id` int(10) unsigned NOT NULL,
+ `description` varchar(100) NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
-- Table structure for table `reader_links`
--
@@ -914,4 +929,4 @@ CREATE TABLE `wl_users` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2018-04-15 19:47:16
+-- Dump completed on 2018-04-20 7:47:13
diff --git a/juick-server-jdbc/src/main/resources/schema.sql b/juick-server-jdbc/src/main/resources/schema.sql
index ec28a456..59c979d5 100644
--- a/juick-server-jdbc/src/main/resources/schema.sql
+++ b/juick-server-jdbc/src/main/resources/schema.sql
@@ -39,13 +39,21 @@ CREATE TABLE IF NOT EXISTS `facebook` (
`crosspost` tinyint(1) unsigned NOT NULL DEFAULT '1',
KEY `user_id` (`user_id`)
);
+
+CREATE TABLE IF NOT EXISTS `reactions` (
+ `like_id` int(10) unsigned NOT NULL,
+ `description` varchar (100) NOT NULL
+);
CREATE TABLE IF NOT EXISTS `favorites` (
`user_id` int(10) unsigned NOT NULL,
`message_id` int(10) unsigned NOT NULL,
`ts` datetime NOT NULL,
- UNIQUE KEY `user_id_2` (`user_id`,`message_id`),
- KEY `message_id` (`message_id`)
+ `like_id` int(10),
+ foreign key (like_id) references reactions(like_id)
);
+
+
+
CREATE TABLE IF NOT EXISTS `friends_facebook` (
`user_id` int(10) unsigned NOT NULL,
`friend_id` bigint(20) unsigned NOT NULL,
diff --git a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
index 5bbfec91..31496407 100644
--- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
+++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
@@ -358,8 +358,8 @@ public class TelegramBotManager implements NotificationListener {
.forEach(c -> telegramNotify(c, String.format("%s recommends your [post](%s)",
MessageUtils.getMarkdownUser(liker), formatUrl(message)),null));
telegramService.getTelegramIdentifiers(subscribers)
- .forEach(c -> telegramNotify(c, String.format("%s recommends you someone's [post](%s)",
- MessageUtils.getMarkdownUser(liker), formatUrl(message)), null));
+ .forEach(c -> telegramNotify(c, String.format("%s recommends you someone's [post](%s)",
+ MessageUtils.getMarkdownUser(liker), formatUrl(message)), null));
}
@Override
diff --git a/juick-server/src/main/java/com/juick/server/api/Messages.java b/juick-server/src/main/java/com/juick/server/api/Messages.java
index 8142a179..c6600e2b 100644
--- a/juick-server/src/main/java/com/juick/server/api/Messages.java
+++ b/juick-server/src/main/java/com/juick/server/api/Messages.java
@@ -90,6 +90,7 @@ public class Messages {
@RequestParam(required = false) String popular,
@RequestParam(required = false) String media,
@RequestParam(required = false) String tag) {
+
User visitor = UserUtils.getCurrentUser();
int vuid = visitor.getUid();
diff --git a/juick-server/src/main/java/com/juick/server/api/Post.java b/juick-server/src/main/java/com/juick/server/api/Post.java
index 9dd42db0..5a027ece 100644
--- a/juick-server/src/main/java/com/juick/server/api/Post.java
+++ b/juick-server/src/main/java/com/juick/server/api/Post.java
@@ -22,8 +22,8 @@ import com.juick.User;
import com.juick.server.CommandsManager;
import com.juick.server.EmailManager;
import com.juick.server.XMPPConnection;
-import com.juick.server.util.*;
import com.juick.server.helpers.CommandResult;
+import com.juick.server.util.*;
import com.juick.service.MessagesService;
import com.juick.service.SubscriptionService;
import com.juick.service.UserService;
@@ -44,6 +44,7 @@ import javax.inject.Inject;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
+import javax.validation.constraints.NotNull;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -235,6 +236,7 @@ public class Post {
throw new HttpForbiddenException();
}
}
+
@PostMapping("/like")
@ResponseStatus(value = HttpStatus.OK)
public Status doPostRecomm(@RequestParam Integer mid) throws Exception {
@@ -253,4 +255,27 @@ public class Post {
URI.create(StringUtils.EMPTY));
return Status.getStatus(status.getText());
}
+
+ @PostMapping("/react")
+ @ResponseStatus(value = HttpStatus.OK)
+ public Status doPostReact(@RequestParam Integer mid,@RequestParam @NotNull int reactionId){
+
+ logger.info("got reaction with type: {}", reactionId);
+ com.juick.User visitor = UserUtils.getCurrentUser();
+ if (visitor.getUid() == 0) {
+ throw new HttpForbiddenException();
+ }
+ com.juick.Message msg = messagesService.getMessage(mid);
+ if (msg == null) {
+ throw new HttpNotFoundException();
+ }
+ if (msg.getUser().getUid() == visitor.getUid()) {
+ throw new HttpForbiddenException();
+ }
+
+ MessagesService.RecommendStatus recommendStatus = messagesService.likeMessage(mid,msg.getUser().getUid(),
+ reactionId);
+
+ return recommendStatus == MessagesService.RecommendStatus.Error ? Status.ERROR :Status.OK;
+ }
}
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 17c7e35c..6b31906d 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
@@ -19,10 +19,7 @@ package com.juick.server.tests;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.juick.ExternalToken;
-import com.juick.Message;
-import com.juick.Tag;
-import com.juick.User;
+import com.juick.*;
import com.juick.server.*;
import com.juick.server.component.MessageEvent;
import com.juick.server.helpers.AnonymousUser;
@@ -34,10 +31,9 @@ import com.juick.util.DateFormattersHolder;
import com.juick.util.MessageUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.hamcrest.Matchers;
+import org.junit.*;
+import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
@@ -77,6 +73,7 @@ import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
/**
@@ -261,11 +258,14 @@ public class ServerTests {
List<Message> replies2 = messagesService.getReplies(user, msg2.getMid());
assertThat(replies2.size(), equalTo(2));
assertThat(replies2.get(1), equalTo(reply2));
+
Message msg3 = messagesService.getMessage(mid2);
+
assertEquals(2, msg3.getReplies());
assertEquals("weather", msg3.getTags().get(0).getName());
assertEquals(ugnich.getUid(), userService.checkPassword(ugnich.getName(), "x"));
assertEquals(-1, userService.checkPassword(ugnich.getName(), "xy"));
+
subscriptionService.subscribeMessage(msg, user);
subscriptionService.subscribeMessage(msg, ugnich);
int reply_id = messagesService.createReply(msg.getMid(), 0, ugnich, "comment", null);
@@ -286,6 +286,28 @@ public class ServerTests {
assertEquals("tags string should be empty", StringUtils.EMPTY, MessageUtils.getTagsString(msg4));
messagesService.deleteMessage(user_id, mid4);
}
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ @Test
+ public void likeTypeStatsTests(){
+ int user_id = userService.createUser("dsdss", "secret");
+ final int freefdId = freefd.getUid();
+ int mid = messagesService.createMessage(user_id, "yo", null, new ArrayList<>());
+ messagesService.likeMessage(mid, freefdId , 2);
+ messagesService.likeMessage(mid, freefdId,2);
+ messagesService.likeMessage(mid, freefdId,3);
+ exception.expect(IllegalArgumentException.class);
+ messagesService.likeMessage(mid, freefdId,1);
+
+ Message msg4 = messagesService.getMessage(mid);
+
+ Assert.assertEquals(2, msg4.getReactions().stream().filter(r -> r.getId() == 2)
+ .findFirst().orElseThrow(IllegalStateException::new).getCount());
+ Assert.assertEquals(1,msg4.getReactions().stream().filter(r -> r.getId() == 3)
+ .findFirst().orElseThrow(IllegalStateException::new).getCount());
+ }
@Test
public void lastJidShouldNotBeDeleted() {
int ugnich_id = userService.createUser("hugnich2", "x");
@@ -405,6 +427,29 @@ public class ServerTests {
}
@Test
+ public void messagesUrlTest() throws Exception {
+ int user_id = userService.createUser("dsds4345", "secret");
+
+ String freefdHash = userService.getHashByUID(freefd.getUid());
+ System.out.println("user_id"+ user_id);
+ String userIdHash = userService.getHashByUID(user_id);
+ final int freefdId = freefd.getUid();
+ int mid = messagesService.createMessage(user_id, "yo", null, new ArrayList<>());
+ messagesService.likeMessage(mid, freefdId, 2 );
+ messagesService.likeMessage(mid, freefdId, 2 );
+ messagesService.likeMessage(mid, freefdId, 3 );
+
+ mockMvc.perform(get("/messages?"+ "hash=" + userIdHash))
+ .andDo(print())
+ .andExpect(status().isOk())
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
+ .andExpect((jsonPath("$[0].reactions[?(@.id == 3)].count",
+ Matchers.is(Collections.singletonList(1)))))
+ .andExpect((jsonPath("$[0].reactions[?(@.id == 2)].count",
+ Matchers.is(Collections.singletonList(2)))));
+ }
+
+ @Test
public void tags() throws Exception {
Tag weather = tagService.getTag("weather", true);
Tag yo = tagService.getTag("yo", true);
@@ -745,16 +790,37 @@ public class ServerTests {
}
@Test
- public void likesTests() throws Exception {
+ public void recommendTests() throws Exception {
+
int mid = messagesService.createMessage(ugnich.getUid(), "to be liked", null, null);
String freefdHash = userService.getHashByUID(freefd.getUid());
int freefdMid = messagesService.createMessage(freefd.getUid(), "to be not liked", null, null);
+
mockMvc.perform(post("/like?mid=" + mid + "&hash=" + freefdHash))
.andExpect(status().isOk())
.andExpect(jsonPath("$.status", is("Message is added to your recommendations")));
+
mockMvc.perform(post("/like?mid=" + freefdMid + "&hash=" + freefdHash))
.andExpect(status().isForbidden());
}
+
+ @Test
+ public void likesTests() throws Exception{
+ int user_id = userService.createUser("dsds", "secret");
+ String freefdHash = userService.getHashByUID(freefd.getUid());
+ System.out.println("user_id"+ user_id);
+ String userIdHash = userService.getHashByUID(user_id);
+ int mid1 = messagesService.createMessage(user_id, "yo", null, new ArrayList<>());
+
+ mockMvc.perform(post("/react?mid=" + mid1 + "&hash=" + freefdHash+ "&reactionId=2"))
+ .andExpect(status().isOk());
+
+ Message msg4 = messagesService.getMessage(mid1);
+ System.out.println("msg4"+msg4);
+ Assert.assertEquals(1, msg4.getReactions().stream().filter(r -> r.getId() == 2)
+ .findFirst().orElseThrow(IllegalStateException::new).getCount());
+ }
+
@Test
public void telegramTests() {
jdbcTemplate.update("INSERT INTO telegram(user_id, tg_id) VALUES(?,1)", ugnich.getUid());
diff --git a/juick-server/src/test/resources/data.sql b/juick-server/src/test/resources/data.sql
new file mode 100644
index 00000000..17421b16
--- /dev/null
+++ b/juick-server/src/test/resources/data.sql
@@ -0,0 +1,7 @@
+INSERT INTO reactions (like_id, description) VALUES (1, 'like');
+INSERT INTO reactions (like_id, description) VALUES (2, 'love');
+INSERT INTO reactions (like_id, description) VALUES (3, 'lol');
+INSERT INTO reactions (like_id, description) VALUES (4, 'hmm');
+INSERT INTO reactions (like_id, description) VALUES (5, 'angry');
+INSERT INTO reactions (like_id, description) VALUES (6, 'uhblya');
+INSERT INTO reactions (like_id, description) VALUES (7, 'ugh');
diff --git a/juick-www/src/main/resources/templates/views/partial/message.html b/juick-www/src/main/resources/templates/views/partial/message.html
index 2e3667f2..0b6db3df 100644
--- a/juick-www/src/main/resources/templates/views/partial/message.html
+++ b/juick-www/src/main/resources/templates/views/partial/message.html
@@ -29,7 +29,7 @@
<a href="/{{ msg.mid }}" class="a-like msg-button">
<span class="msg-button-icon">
<i data-icon="ei-heart" data-size="s"></i>
- {% if msg.Likes > 0 %}&nbsp;{{ msg.Likes }}{% endif %}
+ {% if msg.likes > 0 %}&nbsp;{{ msg.likes }}{% endif %}
</span>
<span>&nbsp;{{ i18n("messages","message.recommend") }}</span>
</a>
@@ -37,7 +37,7 @@
<a href="/post?body=!+%23{{ msg.mid }}" class="a-like msg-button">
<span class="msg-button-icon">
<i data-icon="ei-heart" data-size="s"></i>
- {% if msg.Likes > 0 %}&nbsp;{{ msg.Likes }}{% endif %}
+ {% if msg.likes > 0 %}&nbsp;{{ msg.likes }}{% endif %}
</span>
<span>&nbsp;{{ i18n("messages","message.recommend") }}</span>
</a>
@@ -45,7 +45,7 @@
<a href="/login" class="a-login msg-button">
<span class="msg-button-icon">
<i data-icon="ei-heart" data-size="s"></i>
- {% if msg.Likes > 0 %}&nbsp;{{ msg.Likes }}{% endif %}
+ {% if msg.likes > 0 %}&nbsp;{{ msg.likes }}{% endif %}
</span>
<span>&nbsp;{{ i18n("messages","message.recommend") }}</span>
</a>
diff --git a/juick-www/src/main/resources/templates/views/thread.html b/juick-www/src/main/resources/templates/views/thread.html
index ae429365..5981bd10 100644
--- a/juick-www/src/main/resources/templates/views/thread.html
+++ b/juick-www/src/main/resources/templates/views/thread.html
@@ -6,8 +6,7 @@
<div class="msg-cont" itemscope="" itemtype="http://schema.org/BlogPosting" itemref="org">
<div class="msg-header">
<div class="msg-avatar">
- <a href="/{{ msg.user.name }}/">
- <img src="//i.juick.com/a/{{ msg.user.uid }}.png" alt="{{ msg.user.name }}"/></a>
+ <a href="/{{ msg.user.name }}/"><img src="//i.juick.com/a/{{ msg.user.uid }}.png" alt="{{ msg.user.name }}"/></a>
</div>
<span itemprop="author" itemscope="" itemtype="http://schema.org/Person">
<a itemprop="url" rel="author" href="/{{ msg.user.name }}/"><span itemprop="name">{{ msg.user.name }}</span></a>
@@ -64,24 +63,24 @@
<span>&nbsp;{{ i18n("messages","message.share") }}</span>
</a>
{% if visitor.uid > 0 %}
- {% if visitor.uid != msg.user.uid %}
- {% if visitorSubscribed %}
+ {% if visitor.uid != msg.user.uid %}
+ {% if visitorSubscribed %}
<a href="/post?body=U+%23{{ msg.mid }}" class="msg-button">
<i data-icon="ei-check" data-size="s"></i>
<span>&nbsp;{{ i18n("messages","message.subscribed") }}</span>
</a>
- {% else %}
+ {% else %}
<a href="/post?body=S+%23{{ msg.mid }}" class="msg-button">
<i data-icon="ei-eye" data-size="s"></i>
<span>&nbsp;{{ i18n("messages","message.subscribe") }}</span>
</a>
- {% endif %}
- {% else %}
+ {% endif %}
+ {% else %}
<a href="/post?body=D+%23{{ msg.mid }}" class="msg-button">
<i data-icon="ei-close" data-size="s"></i>
<span>&nbsp;{{ i18n("messages","message.delete") }}</span>
</a>
- {% endif %}
+ {% endif %}
{% endif %}
{% if msg.FriendsOnly %}
<a href="#" class="a-privacy">Открыть доступ</a>