aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/juick/CommandsManager.java3
-rw-r--r--src/main/java/com/juick/service/MessagesService.java3
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java6
-rw-r--r--src/main/java/com/juick/service/UserService.java1
-rw-r--r--src/main/java/com/juick/www/api/Messages.java9
5 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/com/juick/CommandsManager.java b/src/main/java/com/juick/CommandsManager.java
index a643225fb..a7a880c52 100644
--- a/src/main/java/com/juick/CommandsManager.java
+++ b/src/main/java/com/juick/CommandsManager.java
@@ -554,6 +554,9 @@ public class CommandsManager {
return CommandResult.fromString("Tags are NOT updated (5 tags maximum?)");
}
} else {
+ if (!messagesService.canViewThread(mid, user.getUid())) {
+ return CommandResult.fromString("Message unavailable");
+ }
if (txt.length() > 4096) {
return CommandResult.fromString("Sorry, 4096 characters maximum.");
}
diff --git a/src/main/java/com/juick/service/MessagesService.java b/src/main/java/com/juick/service/MessagesService.java
index a6b6e2e2f..91788a3c7 100644
--- a/src/main/java/com/juick/service/MessagesService.java
+++ b/src/main/java/com/juick/service/MessagesService.java
@@ -162,4 +162,7 @@ public interface MessagesService {
void setMessageProperty(Integer mid, Integer rid, String key, String value);
Optional<Pair<Integer, Integer>> findMessageByProperty(String key, String value);
+
+ @CacheEvict(value = { "discover", "discussions", "messages", "replies" }, allEntries = true)
+ void setFriendsOnly(Integer mid, Boolean friendsOnly);
}
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java
index 53f2407c0..85dadd77e 100644
--- a/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -1175,4 +1175,10 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
}
return Optional.empty();
}
+ @Transactional
+ @Override
+ public void setFriendsOnly(Integer mid, Boolean friendsOnly) {
+ int privacy = friendsOnly ? -1 : 1;
+ jdbcTemplate.update("UPDATE messages SET privacy=? WHERE message_id=?", privacy, mid);
+ }
}
diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java
index ec5beb13c..53acdfaba 100644
--- a/src/main/java/com/juick/service/UserService.java
+++ b/src/main/java/com/juick/service/UserService.java
@@ -201,5 +201,6 @@ public interface UserService {
boolean deleteToken(String serviceType, String token);
+ @CacheEvict(value = "users_by_name", allEntries = true)
void setPremium(Integer uid, boolean isPremium);
}
diff --git a/src/main/java/com/juick/www/api/Messages.java b/src/main/java/com/juick/www/api/Messages.java
index e34264548..f059aa881 100644
--- a/src/main/java/com/juick/www/api/Messages.java
+++ b/src/main/java/com/juick/www/api/Messages.java
@@ -203,4 +203,13 @@ public class Messages {
}
throw new HttpBadRequestException();
}
+ @PostMapping("/api/messages/set_privacy")
+ public void togglePrivacy(@Parameter(hidden = true) User visitor, @RequestParam Integer mid) {
+ if (visitor.isPremium() || userService.isAdminUser(visitor)) {
+ var msg = messagesService.getMessage(mid).orElseThrow(HttpNotFoundException::new);
+ messagesService.setFriendsOnly(mid, !msg.FriendsOnly);
+ } else {
+ throw new HttpBadRequestException();
+ }
+ }
}