aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc/src
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server-jdbc/src')
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java21
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java20
-rw-r--r--juick-server-jdbc/src/main/resources/schema.sql1
3 files changed, 22 insertions, 20 deletions
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 3b73ed259..c811e3007 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
@@ -167,7 +167,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
/**
* @param mid
* @param rid
- * @param uid
+ * @param user
* @param txt
* @param attachment
* @return
@@ -175,17 +175,18 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
*/
@Transactional
@Override
- public int createReply(final int mid, final int rid, final int uid, final String txt, final String attachment) {
+ public int createReply(final int mid, final int rid, final User user, final String txt, final String attachment) {
int ridnew = getReplyIDIncrement(mid);
Date ts = Date.from(Instant.now());
getJdbcTemplate().update("INSERT INTO replies(message_id, reply_id, user_id, replyto, attach, txt, ts) " +
"VALUES (?, ?, ?, ?, ?, ?, ?)",
- mid, ridnew, uid, rid, attachment, txt, ts);
+ mid, ridnew, user.getUid(), rid, attachment, txt, ts);
if (ridnew > 0) {
getJdbcTemplate().update(
"UPDATE messages SET replies = replies + 1, updated=? WHERE message_id = ?",
ts, mid);
+ setLastReadComment(user, mid, ridnew);
}
return ridnew;
}
@@ -771,8 +772,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Transactional(readOnly = true)
@Override
- public List<com.juick.Message> getReplies(final int mid) {
- return getNamedParameterJdbcTemplate().query(
+ public List<Message> getReplies(final User user, final int mid) {
+ List<Message> replies = getNamedParameterJdbcTemplate().query(
"SELECT replies.message_id as mid, replies.reply_id, replies.replyto, " +
"replies.user_id, users.nick, users.banned, " +
"TIMESTAMPDIFF(MINUTE, replies.ts, NOW()), replies.ts, " +
@@ -793,6 +794,10 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
"WHERE replies.message_id = :mid ORDER BY replies.reply_id ASC",
new MapSqlParameterSource("mid", mid),
new MessageMapper());
+ if (replies.size() > 0) {
+ setLastReadComment(user, mid, replies.stream().map(Message::getRid).max(Comparator.naturalOrder()).get());
+ }
+ return replies;
}
@Transactional
@@ -919,4 +924,10 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
"WHERE COALESCE(messages_tags.tag_id, 0) != 2 AND favorites.ts > TIMESTAMPADD(HOUR, -2, CURRENT_TIMESTAMP) " +
"AND messages.popular=0 GROUP BY messages.message_id HAVING COUNT(DISTINCT favorites.user_id) > 1;", Integer.class);
}
+ @Transactional
+ @Override
+ public void setLastReadComment(User user, Integer mid, Integer rid) {
+ jdbcTemplate.update("UPDATE subscr_messages SET last_read_rid=? WHERE message_id=? AND suser_id=?",
+ rid, mid, user.getUid());
+ }
}
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java
index 0273c1c36..d580f97a0 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java
@@ -41,22 +41,12 @@ import java.util.stream.Collectors;
*/
@Repository
public class SubscriptionServiceImpl extends BaseJdbcService implements SubscriptionService {
- private final UserService userService;
- private final MessagesService messagesService;
- private final TagService tagService;
-
@Inject
- public SubscriptionServiceImpl(UserService userService,
- MessagesService messagesService, TagService tagService) {
- Assert.notNull(userService, "UserService must be initialized");
- this.userService = userService;
-
- Assert.notNull(messagesService,"MessagesService must be initialized");
- this.messagesService = messagesService;
-
- Assert.notNull(tagService, "TagService must be initialized");
- this.tagService = tagService;
- }
+ private UserService userService;
+ @Inject
+ private MessagesService messagesService;
+ @Inject
+ private TagService tagService;
@Transactional(readOnly = true)
@Override
diff --git a/juick-server-jdbc/src/main/resources/schema.sql b/juick-server-jdbc/src/main/resources/schema.sql
index 544b4e518..66b4d7ac7 100644
--- a/juick-server-jdbc/src/main/resources/schema.sql
+++ b/juick-server-jdbc/src/main/resources/schema.sql
@@ -227,6 +227,7 @@ CREATE TABLE IF NOT EXISTS `replies` (
CREATE TABLE IF NOT EXISTS `subscr_messages` (
`message_id` int(10) unsigned NOT NULL,
`suser_id` int(10) unsigned NOT NULL,
+ `last_read_rid` smallint(5) unsigned NOT NULL DEFAULT '0',
UNIQUE KEY (`message_id`,`suser_id`)
);