diff options
author | Vitaly Takmazov | 2018-03-07 14:53:23 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-03-13 08:12:18 +0300 |
commit | 1f5869fcfe8c537d223b750754025cb2937d4bad (patch) | |
tree | adb9e8f12e41eb4f2659ea4079c05729d42f33c1 /juick-www/src/main | |
parent | c25f908aa587a60912f7350806e54de2b7f3dc04 (diff) |
drop replies tree
Diffstat (limited to 'juick-www/src/main')
7 files changed, 56 insertions, 203 deletions
diff --git a/juick-www/src/main/java/com/juick/www/controllers/Messages.java b/juick-www/src/main/java/com/juick/www/controllers/Messages.java index c83bb356..11dafda3 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/Messages.java +++ b/juick-www/src/main/java/com/juick/www/controllers/Messages.java @@ -506,8 +506,8 @@ public class Messages { protected String threadAction(ModelMap model, @PathVariable String uname, @PathVariable int mid, - @CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie, - @RequestParam(required = false, value = "view") String paramView) { + @CookieValue(name = "sape_cookie", + required = false, defaultValue = StringUtils.EMPTY) String sapeCookie) { com.juick.User visitor = UserUtils.getCurrentUser(); if (!messagesService.canViewThread(mid, visitor.getUid())) { @@ -533,29 +533,12 @@ public class Messages { } model.addAttribute("msg", msg); - boolean listview = false; - if (paramView != null) { - if (paramView.equals("list")) { - listview = true; - if (visitor.getUid() > 0) { - userService.setUserOptionInt(visitor.getUid(), "repliesview", 1); - } - } else if (paramView.equals("tree") && visitor.getUid() > 0) { - userService.setUserOptionInt(visitor.getUid(), "repliesview", 0); - } - } else if (visitor.getUid() > 0 && userService.getUserOptionInt(visitor.getUid(), "repliesview", 0) == 1) { - listview = true; - } - model.addAttribute("listview", listview); String title = msg.getUser().getName() + ": " + msg.getTagsString(); model.addAttribute("title", title); model.addAttribute("visitor", visitor); String headers = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"@" + msg.getUser().getName() + "\" href=\"//rss.juick.com/" + msg.getUser().getName() + "/blog\"/>"; String pageUrl = "https://juick.com/" + msg.getUser().getName() + "/" + msg.getMid(); - if (paramView != null) { - headers += "<link rel=\"canonical\" href=\"" + pageUrl + "\"/>"; - } if (msg.Hidden) { headers += "<meta name=\"robots\" content=\"noindex\"/>"; } diff --git a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java index b492f121..14af2539 100644 --- a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java +++ b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java @@ -35,8 +35,10 @@ public class FormatMessageFilter implements Filter { if (input instanceof Message) { Message msg = (Message) input; boolean isCode = msg.getTags().stream().anyMatch(t -> t.getName().equals("code")); - String formattedMessage = isCode ? MessageUtils.formatMessageCode(StringUtils.defaultString(msg.getText())) - : MessageUtils.formatMessage(StringUtils.defaultString(msg.getText())); + String msgTxt = msg.getRid() > 0 ? String.format("@%s, %s", msg.getTo().getName(), StringUtils.defaultString(msg.getText())) + : StringUtils.defaultString(msg.getText()); + String formattedMessage = isCode ? MessageUtils.formatMessageCode(msgTxt) + : MessageUtils.formatMessage(msgTxt); return new SafeString(formattedMessage); } throw new IllegalArgumentException("invalid input"); diff --git a/juick-www/src/main/resources/templates/views/macros/tree.html b/juick-www/src/main/resources/templates/views/macros/tree.html deleted file mode 100644 index 71ffd74b..00000000 --- a/juick-www/src/main/resources/templates/views/macros/tree.html +++ /dev/null @@ -1,57 +0,0 @@ -{% macro tree(replies, visitor, level, margin, hidden) %} -{% for msg in replies %} - {% if msg.replyto == level %} - <li id="{{ msg.rid }}" style="margin-left: {{ margin }}px;{% if hidden %}display: none;{% endif %}" class="msg"> - <div class="msg-cont"> - <div class="msg-header"> -{% if not msg.user.banned %} - <a href="/{{ msg.user.name }}/">{{ msg.user.name }}</a> - <div class="msg-avatar"><a href="/{{ msg.user.name }}/"> - <img src="//i.juick.com/a/{{ msg.user.uid }}.png" alt="{{ msg.user.name }}"/></a> - </div> -{% else %} - [удалено]: - <div class="msg-avatar"> - <img src="//i.juick.com/av-96.png"/> - </div> -{% endif %} - <div class="msg-ts"> - <a href="/{{ msg.mid }}#{{ msg.rid }}"> - <time datetime="{{ msg.timestamp | timestamp | date('yyyy-MM-dd HH:mm:ss') }}Z" - title="{{ msg.timestamp | timestamp | date('yyyy-MM-dd HH:mm:ss') }} GMT"> - {{ msg.timestamp | prettyTime }} - </time> - </a> - </div> - </div> - <div class="msg-txt">{{ msg | formatMessage }}</div> - {% if msg.AttachmentType is not empty %} - <div class="msg-media"> - <a href="//i.juick.com/p/{{ msg.mid }}-{{ msg.rid }}.{{ msg.AttachmentType }}" data-fname="{{ msg.mid }}-{{ msg.rid }}.{{ msg.AttachmentType }}"> - <img src="//i.juick.com/photos-512/{{ msg.mid }}-{{ msg.rid }}.{{ msg.AttachmentType }}" alt=""/> - </a> - </div> - {% endif %} - <div class="msg-links">/{{ msg.rid }} -{% if msg.replyto > 0 %} - {{ i18n("messages","reply.inReplyTo") }} <a href="#{{ msg.replyto }}">/{{ msg.replyto }}</a> -{% endif %} -{% if msg.VisitorCanComment %} - · <a href="/post?body=%23{{ msg.mid }}/{{ msg.rid }}%20" class="a-thread-comment">{{ i18n("messages","reply.reply") }}</a></div> - <div class="msg-comment-target msg-comment-hidden"></div> -{% elseif visitor.uid == 0 %} - · <a href="#" class="a-login">{{ i18n("messages","reply.reply") }}</a></div> -{% endif %} - -{% if level == 0 and msg.childsCount > 1 and replies.size() > 10 %} - <div class="msg-comments"><a href="#">{{ msg | formatReplies }}</a></div> -{% endif %} - </li> - {% if (level == 0 and msg.childsCount > 1 and replies.size() > 10) %} - {{ tree(msg.childs, visitor, msg.rid, margin + 20, true) }} - {% elseif (msg.childsCount > 0) %} - {{ tree(msg.childs, visitor, msg.rid, margin + 20, hidden) }} - {% endif %} - {% endif %} -{% endfor %} -{% endmacro %}
\ No newline at end of file diff --git a/juick-www/src/main/resources/templates/views/partial/thread_list.html b/juick-www/src/main/resources/templates/views/partial/thread_list.html deleted file mode 100644 index f273dec7..00000000 --- a/juick-www/src/main/resources/templates/views/partial/thread_list.html +++ /dev/null @@ -1,49 +0,0 @@ -{% for msg in replies %} -<li id="{{ msg.rid }}" class="msg"> - <div class="msg-cont"> - <div class="msg-header"> - {% if not msg.user.banned %} - <a href="/{{ msg.user.name }}/">{{ msg.user.name }}</a> - <div class="msg-avatar"><a href="/{{ msg.user.name }}/"> - <img src="//i.juick.com/a/{{ msg.user.uid }}.png" alt="{{ msg.user.name }}"/></a> - </div> - {% else %} - [удалено]: - <div class="msg-avatar"> - <img src="//i.juick.com/av-96.png"/> - </div> - {% endif %} - <div class="msg-ts"> - <a href="/{{ msg.mid }}#{{ msg.rid }}"> - <time datetime="{{ msg.timestamp | timestamp | date('yyyy-MM-dd HH:mm:ss') }}Z" - title="{{ msg.timestamp | timestamp | date('yyyy-MM-dd HH:mm:ss') }} GMT"> - {{ msg.timestamp | prettyTime }} - </time> - </a> - </div> - </div> - <div class="msg-txt">{{ msg | formatMessage }}</div> - {% if msg.AttachmentType is not empty %} - <div class="msg-media"> - <a href="//i.juick.com/p/{{ msg.mid }}-{{ msg.rid }}.{{ msg.AttachmentType }}" data-fname="{{ msg.mid }}-{{ msg.rid }}.{{ msg.AttachmentType }}"> - <img src="//i.juick.com/photos-512/{{ msg.mid }}-{{ msg.rid }}.{{ msg.AttachmentType }}" alt=""/> - </a> - </div> - {% endif %} - <div class="msg-links">/{{ msg.rid }} - {% if msg.replyto > 0 %} - {{ i18n("messages","reply.inReplyTo") }} <a href="#{{ msg.replyto }}">/{{ msg.replyto }}</a> - {% endif %} - {% if msg.VisitorCanComment %} - · <a href="/post?body=%23{{ msg.mid }}/{{ msg.rid }}%20" class="a-thread-comment">{{ i18n("messages","reply.reply") }}</a> - </div> - <div class="msg-comment-target msg-comment-hidden"></div> - {% elseif visitor.uid == 0 %} - · <a href="#" class="a-login">{{ i18n("messages","reply.reply") }}</a> - </div> - {% else %} - </div> - {% endif %} - </div> -</li> -{% endfor %}
\ No newline at end of file diff --git a/juick-www/src/main/resources/templates/views/partial/thread_tree.html b/juick-www/src/main/resources/templates/views/partial/thread_tree.html deleted file mode 100644 index f207b8e0..00000000 --- a/juick-www/src/main/resources/templates/views/partial/thread_tree.html +++ /dev/null @@ -1,2 +0,0 @@ -{% import "views/macros/tree" %} -{{ tree(replies, visitor, 0, 0, false) }}
\ No newline at end of file diff --git a/juick-www/src/main/resources/templates/views/thread.html b/juick-www/src/main/resources/templates/views/thread.html index 2115f442..ae429365 100644 --- a/juick-www/src/main/resources/templates/views/thread.html +++ b/juick-www/src/main/resources/templates/views/thread.html @@ -108,25 +108,59 @@ </li> </ul> <div class="title2"> - <div class="title2-right"> - {% if listview %} - <a href="?view=tree" rel="nofollow">{{ i18n("messages","replies.showAsTree") }}</a> - {% else %} - {% if foldable %} - <span id="unfoldall"><a href="#">{{ i18n("messages","replies.unfoldAll") }}</a> · </span> - {% endif %} - <a href="?view=list" rel="nofollow">{{ i18n("messages","replies.showAsList") }}</a> - {% endif %} - </div> <h2>{{ i18n("messages","reply.replies") }} ({{ replies.size() }})</h2> </div> <ul id="replies"> - {% if (listview) %} - {% include "views/partial/thread_list" %} - {% else %} - {% include "views/partial/thread_tree" %} - {% endif %} + {% for msg in replies %} + <li id="{{ msg.rid }}" class="msg"> + <div class="msg-cont"> + <div class="msg-header"> + {% if not msg.user.banned %} + <a href="/{{ msg.user.name }}/">{{ msg.user.name }}</a> + <div class="msg-avatar"><a href="/{{ msg.user.name }}/"> + <img src="//i.juick.com/a/{{ msg.user.uid }}.png" alt="{{ msg.user.name }}"/></a> + </div> + {% else %} + [удалено]: + <div class="msg-avatar"> + <img src="//i.juick.com/av-96.png"/> + </div> + {% endif %} + <div class="msg-ts"> + <a href="/{{ msg.mid }}#{{ msg.rid }}"> + <time datetime="{{ msg.timestamp | timestamp | date('yyyy-MM-dd HH:mm:ss') }}Z" + title="{{ msg.timestamp | timestamp | date('yyyy-MM-dd HH:mm:ss') }} GMT"> + {{ msg.timestamp | prettyTime }} + </time> + </a> + </div> + </div> + <div class="msg-txt">{{ msg | formatMessage }}</div> + {% if msg.AttachmentType is not empty %} + <div class="msg-media"> + <a href="//i.juick.com/p/{{ msg.mid }}-{{ msg.rid }}.{{ msg.AttachmentType }}" data-fname="{{ msg.mid }}-{{ msg.rid }}.{{ msg.AttachmentType }}"> + <img src="//i.juick.com/photos-512/{{ msg.mid }}-{{ msg.rid }}.{{ msg.AttachmentType }}" alt=""/> + </a> + </div> + {% endif %} + <div class="msg-links">/{{ msg.rid }} + {% if msg.replyto > 0 %} + {{ i18n("messages","reply.inReplyTo") }} <a href="#{{ msg.replyto }}">/{{ msg.replyto }}</a> + {% endif %} + {% if msg.VisitorCanComment %} + · <a href="/post?body=%23{{ msg.mid }}/{{ msg.rid }}%20" class="a-thread-comment">{{ i18n("messages","reply.reply") }}</a> + </div> + <div class="msg-comment-target msg-comment-hidden"></div> + {% elseif visitor.uid == 0 %} + · <a href="#" class="a-login">{{ i18n("messages","reply.reply") }}</a> + </div> + {% else %} + </div> + {% endif %} + </div> + </li> + {% endfor %} </ul> {% endblock %} {% block "column" %} diff --git a/juick-www/src/main/static/scripts.js b/juick-www/src/main/static/scripts.js index 588e4fdb..c6293266 100644 --- a/juick-www/src/main/static/scripts.js +++ b/juick-www/src/main/static/scripts.js @@ -187,11 +187,6 @@ function wsShutdown() { } } -function isTreeMode() { - // relies on UserThread.printReplies implementation TODO keep this in cookie or something - return document.querySelector('.title2-right > a').href.match(/\?view=(\w+)/)[1] == 'list'; -} - function wsIncomingReply(msg) { let content = document.getElementById('content'); if (!content) { return; } @@ -234,15 +229,7 @@ function wsIncomingReply(msg) { killy.embedLinksToX(li.querySelector('.msg-cont'), '.msg-links', '.msg-txt a'); - if (isTreeMode() && (msg.replyto > 0)) { - let p = document.getElementById(msg.replyto); - let m = parseInt(p.style.marginLeft) + 20; - while (p.nextElementSibling && (parseInt(p.nextElementSibling.style.marginLeft) >= m)) { p = p.nextElementSibling; } - li.style.marginLeft = m + 'px'; - p.parentNode.insertBefore(li, p.nextSibling); - } else { - document.getElementById('replies').appendChild(li); - } + document.getElementById('replies').appendChild(li); updateRepliesCounter(); } @@ -309,29 +296,6 @@ function newMessage(evt) { } } -function showMoreReplies(el, id) { - var foldedReplies = el.closest('li').querySelector('.msg-comments'); - if (!foldedReplies) { return; } - foldedReplies.style.display = 'none'; - - var replies = document.querySelectorAll('#replies>li'), - flagshow = 0, - i = 0; - for (; i < replies.length; i += 1) { - if (flagshow == 1) { - if (replies[i].style.display == 'none') { - replies[i].style.display = 'block'; - } else { - break; - } - } - if (replies[i].id == id) { - flagshow = 1; - } - } - return false; -} - function showCommentForm(mid, rid) { let reply = document.getElementById(rid); let formTarget = reply.querySelector('div.msg-cont .msg-comment-target'); @@ -422,19 +386,6 @@ function attachMessagePhoto(div) { } } -function unfoldReply() { - var anchor = window.location.hash.substring(1); - if ((0 + anchor) > 0) { - var el = document.getElementById(anchor); - if (!el) { return; } - while (el.style.display === 'none') { - el = el.previousElementSibling; - } - showMoreReplies(el, el.getAttribute('id')); - window.location.replace(window.location.hash); - } -} - function showMessageLinksDialog(mid, rid) { let hlink = window.location.protocol + '//juick.com/' + mid; let mlink = '#' + mid; @@ -667,13 +618,6 @@ ready(function () { var pageMID = content.getAttribute('data-mid'); if (pageMID > 0) { document.querySelectorAll('li.msg').forEach(li => { - let showMoreBtn = li.querySelector('.msg-comments'); - if (showMoreBtn) { - showMoreBtn.addEventListener('click', function (e) { - showMoreReplies(e.target, li.id); - e.preventDefault(); - }); - } let showReplyFormBtn = li.querySelector('.a-thread-comment'); if (showReplyFormBtn) { showReplyFormBtn.addEventListener('click', function (e) { @@ -784,9 +728,7 @@ ready(function () { article.classList.add('nsfw'); } }); - unfoldReply(); initWS(); - window.addEventListener('hashchange', unfoldReply); window.addEventListener('pagehide', wsShutdown); |