aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r--src/main/java/com/juick/config/WebConfig.java6
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java51
2 files changed, 35 insertions, 22 deletions
diff --git a/src/main/java/com/juick/config/WebConfig.java b/src/main/java/com/juick/config/WebConfig.java
index 94f30bd5..fcd9a46b 100644
--- a/src/main/java/com/juick/config/WebConfig.java
+++ b/src/main/java/com/juick/config/WebConfig.java
@@ -193,9 +193,15 @@ public class WebConfig implements WebMvcConfigurer {
private UserService userService;
@Value("${service_user:juick}")
private String serviceUsername;
+ @Value("${archive_user:archive}")
+ private String archiveUsername;
@Bean
public User serviceUser() {
return userService.getUserByName(serviceUsername);
}
+ @Bean
+ public User archiveUser() {
+ return userService.getUserByName(archiveUsername);
+ }
}
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java
index 3e197bf1..7e366a01 100644
--- a/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -68,6 +68,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
private WebApp webApp;
@Value("${photos_url:https://i.juick.com/}")
private String baseImagesUrl;
+ @Inject
+ private User archiveUser;
private class MessageMapper implements RowMapper<Message> {
@Override
@@ -878,25 +880,26 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
Optional<Message> message = getMessage(mid);
if (message.isPresent()) {
Instant ts = message.get().getUpdatedAt();
+ SqlParameterSource parameters = new MapSqlParameterSource().addValue("mid", mid).addValue("uid", uid)
+ .addValue("archive_uid", archiveUser.getUid());
if (ts.compareTo(messageDeletingWindow) >= 0) {
- SqlParameterSource sqlParameterSource = new MapSqlParameterSource().addValue("mid", mid).addValue("uid",
- uid);
-
- if (getNamedParameterJdbcTemplate().update(
- "DELETE FROM messages WHERE message_id = :mid AND user_id = :uid",
- sqlParameterSource) > 0) {
+ if (getNamedParameterJdbcTemplate()
+ .update("DELETE FROM messages WHERE message_id = :mid AND user_id = :uid", parameters) > 0) {
getNamedParameterJdbcTemplate().update("DELETE FROM messages_txt WHERE message_id = :mid",
- sqlParameterSource);
- getNamedParameterJdbcTemplate().update("DELETE FROM replies WHERE message_id = :mid",
- sqlParameterSource);
+ parameters);
+ getNamedParameterJdbcTemplate().update("DELETE FROM replies WHERE message_id = :mid", parameters);
getNamedParameterJdbcTemplate().update("DELETE FROM subscr_messages WHERE message_id = :mid",
- sqlParameterSource);
+ parameters);
getNamedParameterJdbcTemplate().update("DELETE FROM messages_tags WHERE message_id = :mid",
- sqlParameterSource);
+ parameters);
return true;
}
+ } else {
+ return getNamedParameterJdbcTemplate().update(
+ "UPDATE messages SET user_id=:archive_uid WHERE message_id = :mid AND user_id = :uid",
+ parameters) > 0;
}
}
return false;
@@ -910,26 +913,31 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
Message reply = getReply(mid, rid);
if (reply != null) {
Instant ts = reply.getUpdatedAt();
+ User author = getMessageAuthor(mid);
+ SqlParameterSource parameters = new MapSqlParameterSource().addValue("mid", mid).addValue("uid", uid)
+ .addValue("rid", rid).addValue("archive_uid", archiveUser.getUid());
if (ts.compareTo(messageDeletingWindow) >= 0) {
- User author = getMessageAuthor(mid);
- SqlParameterSource sqlParameterSource = new MapSqlParameterSource().addValue("mid", mid)
- .addValue("uid", uid).addValue("rid", rid);
boolean result;
+ // allow to delete author replies and replies to author
if (author.getUid() == uid) {
- result = getNamedParameterJdbcTemplate().update(
- "DELETE FROM replies WHERE message_id=:mid AND reply_id=:rid",
- sqlParameterSource) > 0;
+ result = getNamedParameterJdbcTemplate()
+ .update("DELETE FROM replies WHERE message_id=:mid AND reply_id=:rid", parameters) > 0;
} else {
result = getNamedParameterJdbcTemplate().update(
"DELETE FROM replies WHERE message_id=:mid AND reply_id=:rid AND user_id=:uid",
- sqlParameterSource) > 0;
+ parameters) > 0;
}
if (result) {
getNamedParameterJdbcTemplate()
- .update("UPDATE messages SET replies=replies-1 WHERE message_id=:mid", sqlParameterSource);
+ .update("UPDATE messages SET replies=replies-1 WHERE message_id=:mid", parameters);
updateRepliesBy(mid);
return true;
}
+ } else {
+ // only archive author replies
+ return getNamedParameterJdbcTemplate().update(
+ "UPDATE replies SET user_id=:archive_uid WHERE message_id=:mid AND reply_id=:rid AND user_id=:uid",
+ parameters) > 0;
}
}
return false;
@@ -1060,9 +1068,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Transactional
@Override
public boolean deleteReply(URI userUri, URI replyUri) {
- return jdbcTemplate.update(
- "DELETE FROM replies WHERE user_uri=? AND reply_uri=?",
- userUri.toASCIIString(), replyUri.toASCIIString()) > 0;
+ return jdbcTemplate.update("DELETE FROM replies WHERE user_uri=? AND reply_uri=?", userUri.toASCIIString(),
+ replyUri.toASCIIString()) > 0;
}
@Transactional(readOnly = true)