aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java')
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java21
1 files changed, 16 insertions, 5 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());
+ }
}