aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc/src/main/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-11 21:34:14 +0300
committerGravatar Vitaly Takmazov2018-04-11 21:34:14 +0300
commitad99117a15062a3819dad1f52a072e9694a954df (patch)
tree61b47950cca3adba91ef4f7c8ce80c1a1f8a531f /juick-server-jdbc/src/main/java
parent47254ab8555162bc121c7b618fff42fc64b9454c (diff)
server: last read marker for threads
Diffstat (limited to 'juick-server-jdbc/src/main/java')
-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
2 files changed, 21 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 3b73ed25..c811e300 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 0273c1c3..d580f97a 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