aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesService.java2
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java6
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/Home.java22
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/NewMessage.java38
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/PM.java5
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java50
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/UserThread.java10
-rw-r--r--juick-www/src/main/static/scripts.js235
-rw-r--r--juick-www/src/main/webapp/WEB-INF/views/partial/navigation.html2
-rw-r--r--juick-www/src/main/webapp/WEB-INF/views/pm_inbox.html4
-rw-r--r--juick-www/src/main/webapp/WEB-INF/views/pm_sent.html2
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java32
12 files changed, 235 insertions, 173 deletions
diff --git a/juick-server/src/main/java/com/juick/service/MessagesService.java b/juick-server/src/main/java/com/juick/service/MessagesService.java
index 284b2018..cad0f860 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesService.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesService.java
@@ -81,4 +81,6 @@ public interface MessagesService {
List<Integer> getLastMessages(int hours);
List<ResponseReply> getLastReplies(int hours);
+
+ boolean isReadonly();
}
diff --git a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
index 5c2701eb..a19878d9 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -767,4 +767,10 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
return reply;
}, -hours);
}
+
+ @Transactional(readOnly = true)
+ @Override
+ public boolean isReadonly() {
+ return getJdbcTemplate().queryForObject("SELECT @@global.read_only", Integer.class) > 0;
+ }
}
diff --git a/juick-www/src/main/java/com/juick/www/controllers/Home.java b/juick-www/src/main/java/com/juick/www/controllers/Home.java
index 2f9dc903..405a4bd6 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/Home.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/Home.java
@@ -176,15 +176,19 @@ public class Home {
if (visitor.getUid() > 0) {
out.println("<form action=\"/post\" method=\"post\" enctype=\"multipart/form-data\">");
out.println("<section id=\"newmessage\">");
- out.println(" <textarea name=\"body\" placeholder=\"Новое сообщение...\"></textarea>");
- out.println(" <div>");
- out.println(" <input type=\"text\" class=\"img\" name=\"img\" " +
- "placeholder=\"Ссылка на изображение (JPG/PNG, до 10Мб)\"/> " +
- "или <a href=\"#\">загрузить</a><br/>");
- out.println(" <input type=\"text\" class=\"tags\" name=\"tags\" " +
- "placeholder=\"Теги (через пробел)\"/><br/>");
- out.println(" <input type=\"submit\" class=\"subm\" value=\"Отправить\"/>");
- out.println(" </div>");
+ if (messagesService.isReadonly()) {
+ out.println("<p>Комментирование временно недоступно</p>");
+ } else {
+ out.println(" <textarea name=\"body\" placeholder=\"Новое сообщение...\"></textarea>");
+ out.println(" <div>");
+ out.println(" <input type=\"text\" class=\"img\" name=\"img\" " +
+ "placeholder=\"Ссылка на изображение (JPG/PNG, до 10Мб)\"/> " +
+ "или <a href=\"#\">загрузить</a><br/>");
+ out.println(" <input type=\"text\" class=\"tags\" name=\"tags\" " +
+ "placeholder=\"Теги (через пробел)\"/><br/>");
+ out.println(" <input type=\"submit\" class=\"subm\" value=\"Отправить\"/>");
+ out.println(" </div>");
+ }
out.println("</section>");
out.println("</form>");
}
diff --git a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
index b340546f..938cd338 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
@@ -98,26 +98,30 @@ public class NewMessage {
templates.pageNavigation(out, visitor, null);
out.println("<section id=\"content\" class=\"pagetext\">");
- out.println("<form action=\"/post2\" method=\"post\" id=\"postmsg\" enctype=\"multipart/form-data\">");
- out.println("<p style=\"text-align: left\"><b>Место: <span id=\"location\"></span></b> <span id=\"locationclear\">&mdash; <a href=\"#\" onclick=\"clearLocation()\">Отменить</a></span></p>");
- out.println("<p style=\"text-align: left\"><b>Фото:</b> <span id=\"attachmentfile\"><input type=\"file\" name=\"attach\"/> <i>(JPG, PNG, до 10Мб)</i></span></p>");
-
- String body = request.getParameter("body");
- if (body == null) {
- body = StringUtils.EMPTY;
+ if (messagesService.isReadonly()) {
+ out.println("<p>Временно недоступно</p>");
} else {
- if (body.length() > 4096) {
- body = body.substring(0, 4096);
+ out.println("<form action=\"/post2\" method=\"post\" id=\"postmsg\" enctype=\"multipart/form-data\">");
+ out.println("<p style=\"text-align: left\"><b>Место: <span id=\"location\"></span></b> <span id=\"locationclear\">&mdash; <a href=\"#\" onclick=\"clearLocation()\">Отменить</a></span></p>");
+ out.println("<p style=\"text-align: left\"><b>Фото:</b> <span id=\"attachmentfile\"><input type=\"file\" name=\"attach\"/> <i>(JPG, PNG, до 10Мб)</i></span></p>");
+
+ String body = request.getParameter("body");
+ if (body == null) {
+ body = StringUtils.EMPTY;
+ } else {
+ if (body.length() > 4096) {
+ body = body.substring(0, 4096);
+ }
+ body = StringEscapeUtils.escapeHtml4(body);
}
- body = StringEscapeUtils.escapeHtml4(body);
- }
- out.println("<p><textarea name=\"body\" class=\"newmessage\" rows=\"7\" cols=\"10\">" + body + "</textarea><br/>");
+ out.println("<p><textarea name=\"body\" class=\"newmessage\" rows=\"7\" cols=\"10\">" + body + "</textarea><br/>");
- out.println("<input type=\"hidden\" name=\"place_id\"/>" + "" + "<input type=\"submit\" class=\"subm\" value=\" Отправить \"/></p>");
- out.println("</form>");
- out.println("<div id=\"geomap\"></div>");
- out.println("<p style=\"text-align: left\"><b>Теги:</b></p>");
- printUserTags(out, visitor);
+ out.println("<input type=\"hidden\" name=\"place_id\"/>" + "" + "<input type=\"submit\" class=\"subm\" value=\" Отправить \"/></p>");
+ out.println("</form>");
+ out.println("<div id=\"geomap\"></div>");
+ out.println("<p style=\"text-align: left\"><b>Теги:</b></p>");
+ printUserTags(out, visitor);
+ }
out.println("</section>");
templates.pageFooter(request, out, visitor, false);
diff --git a/juick-www/src/main/java/com/juick/www/controllers/PM.java b/juick-www/src/main/java/com/juick/www/controllers/PM.java
index 56b688cf..028feabc 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/PM.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/PM.java
@@ -17,6 +17,7 @@
*/
package com.juick.www.controllers;
+import com.juick.service.MessagesService;
import com.juick.service.PMQueriesService;
import com.juick.service.TagService;
import com.juick.service.UserService;
@@ -55,6 +56,8 @@ public class PM {
@Inject
UserService userService;
@Inject
+ MessagesService messagesService;
+ @Inject
WebApp webApp;
@RequestMapping(value = "/pm/inbox", method = RequestMethod.GET)
@@ -70,6 +73,7 @@ public class PM {
model.addAttribute("visitor", visitor);
model.addAttribute("msgs", msgs);
model.addAttribute("tags", tagService.getPopularTags());
+ model.addAttribute("readonly", messagesService.isReadonly());
return "views/pm_inbox";
}
@@ -92,6 +96,7 @@ public class PM {
model.addAttribute("msgs", msgs);
model.addAttribute("tags", tagService.getPopularTags());
model.addAttribute("uname", uname);
+ model.addAttribute("readonly", messagesService.isReadonly());
return "views/pm_sent";
}
diff --git a/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java b/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java
index eb241f7d..6ee18732 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java
@@ -81,9 +81,9 @@ public class PageTemplates {
out.println("</head>");
out.flush();
if (visitor.getUid() > 0) {
- out.println("<body id=\"body\" data-hash=\"" + visitor.getAuthHash() + "\">");
+ out.println("<body id=\"body\" data-hash=\"" + visitor.getAuthHash() + "\" data-readonly=\"" + messagesService.isReadonly() + "\">");
} else {
- out.println("<body id=\"body\">");
+ out.println("<body id=\"body\" data-readonly=\"" + messagesService.isReadonly() + "\">");
}
}
@@ -109,7 +109,9 @@ public class PageTemplates {
out.print("<li><a href=\"/?show=recommended\">Рекомендации</a></li>");
out.println("</ul></nav>");
out.print(" <nav id=\"actions\"><ul>");
- out.print("<li><a href=\"/#post\">Написать</a></li>");
+ if (!messagesService.isReadonly()) {
+ out.print("<li><a href=\"/#post\">Написать</a></li>");
+ }
out.print("<li><a href=\"/" + visitor.getName() + "\">@" + visitor.getName() + "</a></li>");
out.print("<li><a href=\"/logout\">Выйти</a></li>");
out.println("</ul></nav>");
@@ -345,27 +347,29 @@ public class PageTemplates {
if (msg.getAttachmentType() != null) {
out.println(" <div class=\"irbr\"></div>");
}
- out.print(" <nav class=\"l\">");
- msg.ReadOnly |= blUIDs.contains(msg.getUser().getUid());
- if (visitor.getUid() == 0) {
- out.print("<a href=\"#\" class=\"a-login\">Рекомендовать</a>");
- } else {
- out.print("<a href=\"/post?body=!+%23" + msg.getMid() + "\" class=\"a-like\">Рекомендовать</a>");
- }
- if (visitor.getUid() == 0 && !msg.ReadOnly) {
- out.print("<a href=\"/" + msg.getMid() + "\" class=\"a-login\">Комментировать</a> ");
- } else if (visitor.getUid() > 0 && (!msg.ReadOnly || visitor.getUid() == msg.getUser().getUid())) {
- out.print("<a class=\"a-comment\" href=\"/" + msg.getMid() + "\">Комментировать</a> ");
- }
- if (visitor.getUid() > 0 && msg.getPrivacy() < 0 && msg.getUser().getUid() == visitor.getUid()) {
- out.print(" <a href=\"#\" class=\"a-privacy\">Открыть доступ</a>");
- }
- if (visitor.getUid() > 0 && visitor.getUid() == 3694) {
- out.print(" <a href=\"#\" class=\"a-popular-plus\">+</a>");
- out.print(" <a href=\"#\" class=\"a-popular-minus\">-</a>");
- out.print(" <a href=\"#\" class=\"a-popular-delete\">x</a>");
+ if (!messagesService.isReadonly()) {
+ out.print(" <nav class=\"l\">");
+ msg.ReadOnly |= blUIDs.contains(msg.getUser().getUid());
+ if (visitor.getUid() == 0) {
+ out.print("<a href=\"#\" class=\"a-login\">Рекомендовать</a>");
+ } else {
+ out.print("<a href=\"/post?body=!+%23" + msg.getMid() + "\" class=\"a-like\">Рекомендовать</a>");
+ }
+ if (visitor.getUid() == 0 && !msg.ReadOnly) {
+ out.print("<a href=\"/" + msg.getMid() + "\" class=\"a-login\">Комментировать</a> ");
+ } else if (visitor.getUid() > 0 && (!msg.ReadOnly || visitor.getUid() == msg.getUser().getUid())) {
+ out.print("<a class=\"a-comment\" href=\"/" + msg.getMid() + "\">Комментировать</a> ");
+ }
+ if (visitor.getUid() > 0 && msg.getPrivacy() < 0 && msg.getUser().getUid() == visitor.getUid()) {
+ out.print(" <a href=\"#\" class=\"a-privacy\">Открыть доступ</a>");
+ }
+ if (visitor.getUid() > 0 && visitor.getUid() == 3694) {
+ out.print(" <a href=\"#\" class=\"a-popular-plus\">+</a>");
+ out.print(" <a href=\"#\" class=\"a-popular-minus\">-</a>");
+ out.print(" <a href=\"#\" class=\"a-popular-delete\">x</a>");
+ }
+ out.println("</nav>");
}
- out.println("</nav>");
out.print(" <nav class=\"s\">");
if (msg.getLikes() > 0) {
diff --git a/juick-www/src/main/java/com/juick/www/controllers/UserThread.java b/juick-www/src/main/java/com/juick/www/controllers/UserThread.java
index cde33a0e..7d3894a8 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/UserThread.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/UserThread.java
@@ -178,7 +178,7 @@ public class UserThread {
}
}
- if (msg.VisitorCanComment) {
+ if (msg.VisitorCanComment && !messagesService.isReadonly()) {
out.println(" <form action=\"/comment\" method=\"POST\" enctype=\"multipart/form-data\"><input type=\"hidden\" name=\"mid\" value=\"" + msg.getMid() + "\"/>");
out.println(" <div class=\"msg-comment\"><div class=\"ta-wrapper\"><textarea name=\"body\" rows=\"1\" class=\"reply\" placeholder=\"Написать комментарий\"></textarea></div></div>");
out.println(" </form>");
@@ -200,7 +200,7 @@ public class UserThread {
out.println(" <li id=\"mtoolbar\"><ul>");
out.println(" <li><a href=\"/" + msg.getMid() + "\"><div style=\"background-position: -64px 0\"></div>" + msg.getMid() + "</a></li>");
- if (visitor.getUid() > 0) {
+ if (visitor.getUid() > 0 && !messagesService.isReadonly()) {
if (visitor.getUid() != msg.getUser().getUid()) {
if (messagesService.isSubscribed(visitor.getUid(), msg.getMid())) {
out.println(" <li><a href=\"/post?body=U+%23" + msg.getMid() + "\"><div style=\"background-position: -48px 0\"></div>Подписан</a></li>");
@@ -336,10 +336,10 @@ public class UserThread {
if (msg.getReplyto() > 0) {
out.print(" в ответ на <a href=\"#" + msg.getReplyto() + "\">/" + msg.getReplyto() + "</a>");
}
- if (msg.VisitorCanComment) {
+ if (msg.VisitorCanComment && !messagesService.isReadonly()) {
out.println(" &#183; <a href=\"/post?body=%23" + msg.getMid() + "/" + msg.getRid() + "%20\" class=\"a-thread-comment\">Ответить</a></div>");
out.println(" <div class=\"msg-comment\" style=\"display: none\"></div>");
- } else if (visitor == null) {
+ } else if (visitor.getUid() == 0) {
out.println(" &#183; <a href=\"#\" class=\"a-login\">Ответить</a></div>");
}
@@ -382,7 +382,7 @@ public class UserThread {
if (msg.getReplyto() > 0) {
out.print(" в ответ на <a href=\"#" + msg.getReplyto() + "\">/" + msg.getReplyto() + "</a>");
}
- if (msg.VisitorCanComment) {
+ if (msg.VisitorCanComment && !messagesService.isReadonly()) {
out.println(" &#183; <a href=\"#\" class=\"a-thread-comment\">Ответить</a></div>");
out.println(" <div class=\"msg-comment\" style=\"display: none\"></div>");
} else if (visitor.getUid() == 0) {
diff --git a/juick-www/src/main/static/scripts.js b/juick-www/src/main/static/scripts.js
index d368cacd..8432c18a 100644
--- a/juick-www/src/main/static/scripts.js
+++ b/juick-www/src/main/static/scripts.js
@@ -12,19 +12,24 @@ if (!('remove' in Element.prototype)) { // Firefox <23
NodeList.prototype.forEach = Array.prototype.forEach;
HTMLCollection.prototype.forEach = Array.prototype.forEach;
-
+
+function isReadonly() {
+ return document.getElementById('body').getAttribute('data-readonly');
+}
+
var ws,
pageTitle;
function initWS() {
+ if (isReadonly()) { return }
var content = document.getElementById('content');
if (!content) { return }
var pageMID = content.getAttribute('data-mid');
if (!pageMID) { return }
var url = (window.location.protocol === 'https:' ? 'wss' : 'ws') + ':'
- + (typeof juickDebug !== 'undefined' ?
- '//ws.juick.com/_replies' : ('//ws.juick.com/' + pageMID)),
+ + (typeof juickDebug !== 'undefined' ?
+ '//ws.juick.com/_replies' : ('//ws.juick.com/' + pageMID)),
hash = document.getElementById('body').getAttribute('data-hash');
if (hash) {
@@ -145,12 +150,12 @@ function wsIncomingReply(msg) {
msgComment.style.display = 'none';
msgHeader.appendChild(msgAvatar);
msgHeader.appendChild(msgMenu);
- msgHeader.appendChild(msgTimestamp);
+ msgHeader.appendChild(msgTimestamp);
msgCont.appendChild(msgHeader);
msgCont.appendChild(msgTxt);
msgCont.appendChild(msgLinks);
msgCont.appendChild(msgComment);
- li.appendChild(msgCont);
+ li.appendChild(msgCont);
li.querySelector('.msg-txt').textContent = msg.body;
@@ -400,15 +405,15 @@ function showMessageLinksDialog(mid, rid) {
}
var hlinkenc = encodeURIComponent(hlink),
html = '<div class="dialogshare">Ссылка на сообщение:'
- + '<div onclick="this.selectText()" class="dialogl">' + hlink + '</div>'
- + 'Номер сообщения:'
- + '<div onclick="this.selectText()" class="dialogl">' + mlink + '</div>'
- + 'Поделиться:<ul>'
- + '<li><a href="https://www.facebook.com/sharer/sharer.php?u=' + hlinkenc + '" onclick="return openSocialWindow(this)"></a></li>'
- + '<li><a href="https://twitter.com/intent/tweet?url=' + hlinkenc + '" onclick="return openSocialWindow(this)" style="background-position: -32px 0;"></a></li>'
- + '<li><a href="https://vk.com/share.php?url=' + hlinkenc + '" onclick="return openSocialWindow(this)" style="background-position: -64px 0;"></a></li>'
- + '<li><a href="https://plus.google.com/share?url=' + hlinkenc + '" onclick="return openSocialWindow(this)" style="background-position: -96px 0;"></a></li>'
- + '</ul></div>';
+ + '<div onclick="this.selectText()" class="dialogl">' + hlink + '</div>'
+ + 'Номер сообщения:'
+ + '<div onclick="this.selectText()" class="dialogl">' + mlink + '</div>'
+ + 'Поделиться:<ul>'
+ + '<li><a href="https://www.facebook.com/sharer/sharer.php?u=' + hlinkenc + '" onclick="return openSocialWindow(this)"></a></li>'
+ + '<li><a href="https://twitter.com/intent/tweet?url=' + hlinkenc + '" onclick="return openSocialWindow(this)" style="background-position: -32px 0;"></a></li>'
+ + '<li><a href="https://vk.com/share.php?url=' + hlinkenc + '" onclick="return openSocialWindow(this)" style="background-position: -64px 0;"></a></li>'
+ + '<li><a href="https://plus.google.com/share?url=' + hlinkenc + '" onclick="return openSocialWindow(this)" style="background-position: -96px 0;"></a></li>'
+ + '</ul></div>';
openDialog(html);
}
@@ -507,8 +512,8 @@ function setPopular(e, mid, popular) {
fetch('//api.juick.com/messages/set_popular?mid=' + mid
+ '&popular=' + popular
+ '&hash=' + document.getElementById('body').getAttribute('data-hash'), {
- credentials: 'same-origin'
- })
+ credentials: 'same-origin'
+ })
.then(function () {
e.closest('article').append(resultMessage('OK!'));
});
@@ -518,8 +523,8 @@ function setPopular(e, mid, popular) {
function setPrivacy(e, mid) {
fetch('//api.juick.com/messages/set_privacy?mid=' + mid
+ '&hash=' + document.getElementById('body').getAttribute('data-hash'), {
- credentials: 'same-origin'
- })
+ credentials: 'same-origin'
+ })
.then(function () {
e.closest('article').append(resultMessage('OK!'));
});
@@ -551,50 +556,52 @@ function ready(fn) {
}
ready(function () {
- autosize(document.querySelectorAll('textarea'));
-
- var insertButtons = function (e) {
- var textarea = e.target;
- textarea.classList.add('narrow');
- var att = document.createElement('div');
- att.classList.add('attach-photo');
- att.addEventListener('click', function(e) {
- attachCommentPhoto(e.target);
- });
- textarea.parentNode.insertBefore(att, textarea.nextSibling);
- textarea.parentNode.insertAdjacentHTML('afterend', '<input type="submit" value="OK"/>');
- textarea.removeEventListener('click', insertButtons);
- e.preventDefault();
- };
- document.querySelectorAll('textarea.reply').forEach(function(e) {
- e.addEventListener('click', insertButtons);
- e.addEventListener('keypress', function(e) {
- postformListener(e.target, e);
+ if (!isReadonly()) {
+ autosize(document.querySelectorAll('textarea'));
+
+ var insertButtons = function (e) {
+ var textarea = e.target;
+ textarea.classList.add('narrow');
+ var att = document.createElement('div');
+ att.classList.add('attach-photo');
+ att.addEventListener('click', function (e) {
+ attachCommentPhoto(e.target);
+ });
+ textarea.parentNode.insertBefore(att, textarea.nextSibling);
+ textarea.parentNode.insertAdjacentHTML('afterend', '<input type="submit" value="OK"/>');
+ textarea.removeEventListener('click', insertButtons);
+ e.preventDefault();
+ };
+ document.querySelectorAll('textarea.reply').forEach(function (e) {
+ e.addEventListener('click', insertButtons);
+ e.addEventListener('keypress', function (e) {
+ postformListener(e.target, e);
+ });
});
- });
- var insertPMButtons = function (e) {
- e.target.classList.add('narrowpm');
- e.target.parentNode.insertAdjacentHTML('afterend', '<input type="submit" value="OK"/>');
- e.target.removeEventListener('click', insertPMButtons);
- e.preventDefault();
- };
- document.querySelectorAll('textarea.replypm').forEach(function(e) {
- e.addEventListener('click', insertPMButtons);
- });
+ var insertPMButtons = function (e) {
+ e.target.classList.add('narrowpm');
+ e.target.parentNode.insertAdjacentHTML('afterend', '<input type="submit" value="OK"/>');
+ e.target.removeEventListener('click', insertPMButtons);
+ e.preventDefault();
+ };
+ document.querySelectorAll('textarea.replypm').forEach(function (e) {
+ e.addEventListener('click', insertPMButtons);
+ });
+ }
var content = document.getElementById('content');
if (content) {
var pageMID = content.getAttribute('data-mid');
if (pageMID > 0) {
- document.querySelectorAll('.msg-comments').forEach(function(e) {
+ document.querySelectorAll('.msg-comments').forEach(function (e) {
e.addEventListener('click', function (e) {
var rid = e.target.closest('li').id;
showMoreReplies(e.target, rid);
e.preventDefault();
});
});
- document.querySelectorAll('.a-thread-comment').forEach(function(e) {
+ document.querySelectorAll('.a-thread-comment').forEach(function (e) {
e.addEventListener('click', function (e) {
var rid = e.target.closest('li').id;
showCommentForm(pageMID, rid);
@@ -604,23 +611,25 @@ ready(function () {
}
}
- document.querySelectorAll('.msg-menu a').forEach(function(el) {
- el.addEventListener('click', function(e) {
+ document.querySelectorAll('.msg-menu a').forEach(function (el) {
+ el.addEventListener('click', function (e) {
showMessageLinksDialog(
e.target.closest('section').getAttribute('data-mid'),
parseInt(e.target.closest('li').id)); // rid
e.preventDefault();
});
});
- document.querySelectorAll('.l .a-comment').forEach(function(e) {
- e.addEventListener('click', function (e) {
- showCommentFooter(
- e.target,
- e.target.closest('article').getAttribute('data-mid'));
- e.preventDefault();
+ if (!isReadonly()) {
+ document.querySelectorAll('.l .a-comment').forEach(function (e) {
+ e.addEventListener('click', function (e) {
+ showCommentFooter(
+ e.target,
+ e.target.closest('article').getAttribute('data-mid'));
+ e.preventDefault();
+ });
});
- });
- document.querySelectorAll('.l .a-privacy').forEach(function(e) {
+ }
+ document.querySelectorAll('.l .a-privacy').forEach(function (e) {
e.addEventListener('click', function (e) {
setPrivacy(
e.target,
@@ -628,34 +637,36 @@ ready(function () {
e.preventDefault();
});
});
- document.querySelectorAll('.l .a-popular-plus').forEach(function(e) {
- e.addEventListener('click', function (e) {
- setPopular(
- e.target,
- e.target.closest('article').getAttribute('data-mid'),
- 2);
- e.preventDefault();
+ if (!isReadonly()) {
+ document.querySelectorAll('.l .a-popular-plus').forEach(function (e) {
+ e.addEventListener('click', function (e) {
+ setPopular(
+ e.target,
+ e.target.closest('article').getAttribute('data-mid'),
+ 2);
+ e.preventDefault();
+ });
});
- });
- document.querySelectorAll('.l .a-popular-minus').forEach(function(e) {
- e.addEventListener('click', function (e) {
- setPopular(
- e.target,
- e.target.closest('article').getAttribute('data-mid'),
- -1);
- e.preventDefault();
+ document.querySelectorAll('.l .a-popular-minus').forEach(function (e) {
+ e.addEventListener('click', function (e) {
+ setPopular(
+ e.target,
+ e.target.closest('article').getAttribute('data-mid'),
+ -1);
+ e.preventDefault();
+ });
});
- });
- document.querySelectorAll('.l .a-popular-delete').forEach(function(e) {
- e.addEventListener('click', function (e) {
- setPopular(
- e.target,
- e.target.closest('article').getAttribute('data-mid'),
- -2);
- e.preventDefault();
+ document.querySelectorAll('.l .a-popular-delete').forEach(function (e) {
+ e.addEventListener('click', function (e) {
+ setPopular(
+ e.target,
+ e.target.closest('article').getAttribute('data-mid'),
+ -2);
+ e.preventDefault();
+ });
});
- });
- document.querySelectorAll('.ir a').forEach(function(e) {
+ }
+ document.querySelectorAll('.ir a').forEach(function (e) {
e.addEventListener('click', function (e) {
var fname = e.target.closest('[data-fname]').getAttribute('data-fname');
if (!showPhotoDialog(fname)) {
@@ -663,7 +674,7 @@ ready(function () {
}
});
});
- document.querySelectorAll('.social a').forEach(function(e) {
+ document.querySelectorAll('.social a').forEach(function (e) {
e.addEventListener('click', function (e) {
openSocialWindow(e.target);
e.preventDefault();
@@ -676,7 +687,7 @@ ready(function () {
});
}
- document.querySelectorAll('.l .a-like').forEach(function(e) {
+ document.querySelectorAll('.l .a-like').forEach(function (e) {
e.addEventListener('click', function (e) {
likeMessage(
e.target,
@@ -684,46 +695,48 @@ ready(function () {
e.preventDefault();
});
});
- document.querySelectorAll('.a-login').forEach(function(el) {
- el.addEventListener('click', function(e) {
+ document.querySelectorAll('.a-login').forEach(function (el) {
+ el.addEventListener('click', function (e) {
openDialogLogin();
e.preventDefault();
});
});
- document.querySelectorAll('.attach-photo').forEach(function(el) {
- el.addEventListener('click', function(e) {
+ document.querySelectorAll('.attach-photo').forEach(function (el) {
+ el.addEventListener('click', function (e) {
attachCommentPhoto(e.target);
});
});
var unfoldall = document.getElementById('unfoldall');
if (unfoldall) {
- unfoldall.addEventListener('click', function(e) {
- document.querySelectorAll('#replies>li').forEach(function(e) {
+ unfoldall.addEventListener('click', function (e) {
+ document.querySelectorAll('#replies>li').forEach(function (e) {
e.style.display = 'block';
});
- document.querySelectorAll('#replies .msg-comments').forEach(function(e) {
+ document.querySelectorAll('#replies .msg-comments').forEach(function (e) {
e.style.display = 'none';
});
e.preventDefault();
});
}
- var newMessageBlock = document.getElementById('newmessage');
- if (newMessageBlock) {
- var form = newMessageBlock.parentNode;
- form.addEventListener('submit', newMessage);
- newMessageBlock.querySelector('textarea').addEventListener('click', function(e) {
- var parent = e.target.parentNode;
- parent.querySelector('div').style.display = 'block';
- e.target.style.minHeight = '70px';
- e.target.addEventListener('keypress', function(e) {
- postformListener(e.target, e);
+ if (!isReadonly()) {
+ var newMessageBlock = document.getElementById('newmessage');
+ if (newMessageBlock) {
+ var form = newMessageBlock.parentNode;
+ form.addEventListener('submit', newMessage);
+ newMessageBlock.querySelector('textarea').addEventListener('click', function (e) {
+ var parent = e.target.parentNode;
+ parent.querySelector('div').style.display = 'block';
+ e.target.style.minHeight = '70px';
+ e.target.addEventListener('keypress', function (e) {
+ postformListener(e.target, e);
+ });
});
- });
- newMessageBlock.querySelector('a').addEventListener('click', function(e) {
- attachMessagePhoto(e.target);
- });
- }
- document.querySelectorAll('article').forEach(function(article) {
+ newMessageBlock.querySelector('a').addEventListener('click', function (e) {
+ attachMessagePhoto(e.target);
+ });
+ }
+ }
+ document.querySelectorAll('article').forEach(function (article) {
if (Array.prototype.some.call(
article.querySelectorAll('.u a'),
function (a) {
@@ -733,10 +746,10 @@ ready(function () {
var img = article.querySelector('.ir img');
if (img) {
img.style.opacity = 0.05;
- img.addEventListener('mouseover', function(e) {
+ img.addEventListener('mouseover', function (e) {
e.target.style.opacity = 1;
});
- img.addEventListener('mouseout', function(e) {
+ img.addEventListener('mouseout', function (e) {
e.target.style.opacity = 0.05;
});
}
diff --git a/juick-www/src/main/webapp/WEB-INF/views/partial/navigation.html b/juick-www/src/main/webapp/WEB-INF/views/partial/navigation.html
index c47e8a71..89115b87 100644
--- a/juick-www/src/main/webapp/WEB-INF/views/partial/navigation.html
+++ b/juick-www/src/main/webapp/WEB-INF/views/partial/navigation.html
@@ -24,7 +24,9 @@
</nav>
<nav id="actions">
<ul>
+ {% if not readonly %}
<li><a href="/#post">Написать</a></li>
+ {% endif %}
<li><a href="/{{ visitor.getName() }}">@{{ visitor.getName() }}</a></li>
<li><a href="/logout">Выйти</a></li>
</ul>
diff --git a/juick-www/src/main/webapp/WEB-INF/views/pm_inbox.html b/juick-www/src/main/webapp/WEB-INF/views/pm_inbox.html
index cb55582a..fa339a25 100644
--- a/juick-www/src/main/webapp/WEB-INF/views/pm_inbox.html
+++ b/juick-www/src/main/webapp/WEB-INF/views/pm_inbox.html
@@ -16,7 +16,7 @@
</div>
<div class="msg-txt">{{ msg.getText() | raw }}</div>
-
+ {% if not readonly %}
<form action="/pm/send" method="POST" enctype="multipart/form-data">
<input type="hidden" name="uname" value="{{ msg.getUser().getName() }}"/>
<div class="msg-comment">
@@ -25,7 +25,7 @@
</div>
</div>
</form>
-
+ {% endif %}
</div>
</li>
{% endfor %}
diff --git a/juick-www/src/main/webapp/WEB-INF/views/pm_sent.html b/juick-www/src/main/webapp/WEB-INF/views/pm_sent.html
index 41f3814b..872cd29f 100644
--- a/juick-www/src/main/webapp/WEB-INF/views/pm_sent.html
+++ b/juick-www/src/main/webapp/WEB-INF/views/pm_sent.html
@@ -1,5 +1,6 @@
{% extends "layouts/content" %}
{% block content %}
+{% if not readonly %}
<form action="/pm/send" method="POST" enctype="multipart/form-data">
<div class="newpm">
<div class="newpm-to">To: <input type="text" name="uname" placeholder="username" value="{{ uname }}"/></div>
@@ -7,6 +8,7 @@
<div class="newpm-send"><input type="submit" value="OK"/></div>
</div>
</form>
+{% endif %}
{% if not msgs.isEmpty() %}
<ul id="private-messages">
{% for msg in msgs %}
diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java
index 0fff6af3..986eaed0 100644
--- a/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java
+++ b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java
@@ -33,7 +33,9 @@ public class JuickBot implements StanzaListener, AutoCloseable {
public JuickBot(XMPPServer xmpp) {
this.xmpp = xmpp;
xmpp.addStanzaListener(this);
- broadcastPresence(null);
+ if (!xmpp.messagesService.isReadonly()) {
+ broadcastPresence(null);
+ }
}
private static final String HELPTEXT =
@@ -176,10 +178,14 @@ public class JuickBot implements StanzaListener, AutoCloseable {
reply.setFrom(msg.getTo());
reply.setTo(msg.getFrom());
reply.setType(Message.Type.CHAT);
- if (username.equals("juick")) {
- reply.setBody("Для того, чтобы начать пользоваться сервисом, пожалуйста пройдите быструю регистрацию: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nЕсли у вас уже есть учетная запись на Juick, вы сможете присоединить этот JabberID к ней.\n\nTo start using Juick, please sign up: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nIf you already have an account on Juick, you will be proposed to attach this JabberID to your existing account.");
+ if (xmpp.messagesService.isReadonly()) {
+ reply.setBody("Регистрация временно недоступна\n\nRegistration temporarily unavailable");
} else {
- reply.setBody("Внимание, системное сообщение!\nВаш JabberID не обнаружен в списке доверенных. Для того, чтобы отправить сообщение пользователю " + username + "@juick.com, пожалуйста зарегистрируйте свой JabberID в системе: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nЕсли у вас уже есть учетная запись на Juick, вы сможете присоединить этот JabberID к ней.\n\nWarning, system message!\nYour JabberID is not found in our server's white list. To send a message to " + username + "@juick.com, please sign up: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nIf you already have an account on Juick, you will be proposed to attach this JabberID to your existing account.");
+ if (username.equals("juick")) {
+ reply.setBody("Для того, чтобы начать пользоваться сервисом, пожалуйста пройдите быструю регистрацию: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nЕсли у вас уже есть учетная запись на Juick, вы сможете присоединить этот JabberID к ней.\n\nTo start using Juick, please sign up: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nIf you already have an account on Juick, you will be proposed to attach this JabberID to your existing account.");
+ } else {
+ reply.setBody("Внимание, системное сообщение!\nВаш JabberID не обнаружен в списке доверенных. Для того, чтобы отправить сообщение пользователю " + username + "@juick.com, пожалуйста зарегистрируйте свой JabberID в системе: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nЕсли у вас уже есть учетная запись на Juick, вы сможете присоединить этот JabberID к ней.\n\nWarning, system message!\nYour JabberID is not found in our server's white list. To send a message to " + username + "@juick.com, please sign up: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nIf you already have an account on Juick, you will be proposed to attach this JabberID to your existing account.");
+ }
}
xmpp.sendOut(ClientMessage.from(reply));
return true;
@@ -203,7 +209,7 @@ public class JuickBot implements StanzaListener, AutoCloseable {
}
boolean success = false;
- if (!xmpp.userService.isInBLAny(uid_to, user_from.getUid())) {
+ if (!xmpp.userService.isInBLAny(uid_to, user_from.getUid()) && !xmpp.messagesService.isReadonly()) {
success = xmpp.pmQueriesService.createPM(user_from.getUid(), uid_to, msg.getBody());
}
@@ -283,6 +289,8 @@ public class JuickBot implements StanzaListener, AutoCloseable {
} else if (commandlen == 2 && command.equalsIgnoreCase("BL")) {
commandBLShow(msg, user_from);
return true;
+ } else if (xmpp.messagesService.isReadonly()) {
+ return commandMaintenance(msg.getFrom());
}
return false;
@@ -421,6 +429,16 @@ public class JuickBot implements StanzaListener, AutoCloseable {
xmpp.sendOut(ClientMessage.from(reply));
}
+ private boolean commandMaintenance(Jid jidFrom) {
+ Message reply = new Message();
+ reply.setFrom(xmpp.getJid());
+ reply.setTo(jidFrom);
+ reply.setType(Message.Type.CHAT);
+ reply.setBody("Комментирование временно недоступно");
+ xmpp.sendOut(ClientMessage.from(reply));
+ return true;
+ }
+
@Override
public void stanzaReceived(Stanza xmlValue) {
if (xmlValue instanceof Presence) {
@@ -454,6 +472,8 @@ public class JuickBot implements StanzaListener, AutoCloseable {
@Override
public void close() throws Exception {
- broadcastPresence(Presence.Type.UNAVAILABLE);
+ if (!xmpp.messagesService.isReadonly()) {
+ broadcastPresence(Presence.Type.UNAVAILABLE);
+ }
}
}