aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/assets/scripts.js
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/main/assets/scripts.js
parentecac3aa08c45953f09f5ab02a422cb12c6fef74f (diff)
subscribe over api
Diffstat (limited to 'juick-server/src/main/assets/scripts.js')
-rw-r--r--juick-server/src/main/assets/scripts.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/juick-server/src/main/assets/scripts.js b/juick-server/src/main/assets/scripts.js
index 21e3fdee3..1c0902564 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();