aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-09-30 23:04:44 +0300
committerGravatar Vitaly Takmazov2018-09-30 23:04:44 +0300
commit2998e390b70618e214032e87c683664ac22b6a0f (patch)
treef9e6b7f9d232e85c500e396c2e2d78a89a9a4422 /juick-server/src
parentecac3aa08c45953f09f5ab02a422cb12c6fef74f (diff)
subscribe over api
Diffstat (limited to 'juick-server/src')
-rw-r--r--juick-server/src/main/assets/scripts.js28
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Post.java19
-rw-r--r--juick-server/src/main/resources/templates/views/thread.html2
3 files changed, 48 insertions, 1 deletions
diff --git a/juick-server/src/main/assets/scripts.js b/juick-server/src/main/assets/scripts.js
index 21e3fdee..1c090256 100644
--- a/juick-server/src/main/assets/scripts.js
+++ b/juick-server/src/main/assets/scripts.js
@@ -562,6 +562,26 @@ function likeMessage(e, mid) {
return false;
}
+function subscribeMessage(e, mid) {
+ fetch('/api/subscribe?mid=' + mid
+ + '&hash=' + document.getElementById('body').getAttribute('data-hash'), {
+ method: 'POST',
+ mode: 'cors',
+ credentials: 'omit'
+ })
+ .then(function (response) {
+ if (response.ok) {
+ window.location.reload(true);
+ } else {
+ alert('Something went wrong :(');
+ }
+ })
+ .catch(error => {
+ alert(error.message);
+ });
+ return false;
+}
+
/******************************************************************************/
function setPopular(e, mid, popular) {
@@ -774,6 +794,14 @@ ready(function () {
e.preventDefault();
});
});
+ document.querySelectorAll('.l .a-sub').forEach(function (e) {
+ e.addEventListener('click', function (e) {
+ subscribeMessage(
+ e.target,
+ e.target.closest('article').getAttribute('data-mid'));
+ e.preventDefault();
+ });
+ });
document.querySelectorAll('.a-login').forEach(function (el) {
el.addEventListener('click', function (e) {
openDialogLogin();
diff --git a/juick-server/src/main/java/com/juick/server/api/Post.java b/juick-server/src/main/java/com/juick/server/api/Post.java
index b36f324a..74a29de7 100644
--- a/juick-server/src/main/java/com/juick/server/api/Post.java
+++ b/juick-server/src/main/java/com/juick/server/api/Post.java
@@ -173,6 +173,25 @@ public class Post {
return Status.getStatus(status.getText());
}
+ @PostMapping("/api/subscribe")
+ @ResponseStatus(value = HttpStatus.OK)
+ public Status doPostSubscribe(@RequestParam Integer mid) throws Exception {
+ com.juick.User visitor = UserUtils.getCurrentUser();
+ if (visitor.isAnonymous()) {
+ throw new HttpForbiddenException();
+ }
+ com.juick.Message msg = messagesService.getMessage(mid);
+ if (msg == null) {
+ throw new HttpNotFoundException();
+ }
+ if (msg.getUser().getUid() == visitor.getUid()) {
+ throw new HttpForbiddenException();
+ }
+ CommandResult status = commandsManager.processCommand(visitor, String.format("S #%d", mid),
+ URI.create(StringUtils.EMPTY));
+ return Status.getStatus(status.getText());
+ }
+
@GetMapping("/api/reactions")
@ResponseStatus(value = HttpStatus.OK)
public List<Reaction> reactionsList() {
diff --git a/juick-server/src/main/resources/templates/views/thread.html b/juick-server/src/main/resources/templates/views/thread.html
index 343a2591..2da3645f 100644
--- a/juick-server/src/main/resources/templates/views/thread.html
+++ b/juick-server/src/main/resources/templates/views/thread.html
@@ -70,7 +70,7 @@
<span>&nbsp;{{ i18n("messages","message.subscribed") }}</span>
</a>
{% else %}
- <a href="/post?body=S+%23{{ msg.mid }}" class="msg-button">
+ <a href="/post?body=S+%23{{ msg.mid }}" class="a-sub msg-button">
<i data-icon="ei-eye" data-size="s"></i>
<span>&nbsp;{{ i18n("messages","message.subscribe") }}</span>
</a>