From 1f5869fcfe8c537d223b750754025cb2937d4bad Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 7 Mar 2018 14:53:23 +0300 Subject: drop replies tree --- .../java/com/juick/www/controllers/Messages.java | 21 +------ .../extension/filters/FormatMessageFilter.java | 6 +- .../resources/templates/views/macros/tree.html | 57 ------------------- .../templates/views/partial/thread_list.html | 49 ----------------- .../templates/views/partial/thread_tree.html | 2 - .../src/main/resources/templates/views/thread.html | 64 +++++++++++++++++----- juick-www/src/main/static/scripts.js | 60 +------------------- .../src/test/java/com/juick/www/WebAppTests.java | 4 +- 8 files changed, 58 insertions(+), 205 deletions(-) delete mode 100644 juick-www/src/main/resources/templates/views/macros/tree.html delete mode 100644 juick-www/src/main/resources/templates/views/partial/thread_list.html delete mode 100644 juick-www/src/main/resources/templates/views/partial/thread_tree.html (limited to 'juick-www') 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 = ""; String pageUrl = "https://juick.com/" + msg.getUser().getName() + "/" + msg.getMid(); - if (paramView != null) { - headers += ""; - } if (msg.Hidden) { headers += ""; } 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 %} -
  • -
    -
    -{% if not msg.user.banned %} - {{ msg.user.name }} -
    - {{ msg.user.name }} -
    -{% else %} - [удалено]: -
    - -
    -{% endif %} - -
    -
    {{ msg | formatMessage }}
    - {% if msg.AttachmentType is not empty %} -
    - - - -
    - {% endif %} - -
    -{% elseif visitor.uid == 0 %} - ·
    -{% endif %} - -{% if level == 0 and msg.childsCount > 1 and replies.size() > 10 %} -
    {{ msg | formatReplies }}
    -{% endif %} -
  • - {% 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 %} -
  • -
    -
    - {% if not msg.user.banned %} - {{ msg.user.name }} -
    - {{ msg.user.name }} -
    - {% else %} - [удалено]: -
    - -
    - {% endif %} - -
    -
    {{ msg | formatMessage }}
    - {% if msg.AttachmentType is not empty %} -
    - - - -
    - {% endif %} - -
    - {% elseif visitor.uid == 0 %} - · -
    - {% else %} - - {% endif %} - -
  • -{% 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 @@
    -
    - {% if listview %} - {{ i18n("messages","replies.showAsTree") }} - {% else %} - {% if foldable %} - {{ i18n("messages","replies.unfoldAll") }} · - {% endif %} - {{ i18n("messages","replies.showAsList") }} - {% endif %} -

    {{ i18n("messages","reply.replies") }} ({{ replies.size() }})

    {% 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); diff --git a/juick-www/src/test/java/com/juick/www/WebAppTests.java b/juick-www/src/test/java/com/juick/www/WebAppTests.java index 57094c37..726a4612 100644 --- a/juick-www/src/test/java/com/juick/www/WebAppTests.java +++ b/juick-www/src/test/java/com/juick/www/WebAppTests.java @@ -191,7 +191,7 @@ public class WebAppTests { assertThat(threadPage.getWebResponse().getStatusCode(), equalTo(404)); } @Test - public void repliesTree() throws IOException { + public void repliesList() throws IOException { int mid = messagesService.createMessage(ugnich.getUid(), "hello", null, null); IntStream.range(1, 15).forEach(i -> messagesService.createReply(mid, i-1, freefd.getUid(), String.valueOf(i-1), null )); @@ -203,7 +203,7 @@ public class WebAppTests { StyleElement display = e.getStyleElement("display"); return display == null || !display.getValue().equals("none"); }).count(); - assertThat(visibleItems, equalTo(1L)); + assertThat(visibleItems, equalTo(14L)); } @Test public void userShouldNotSeeReplyButtonToBannedUser() throws Exception { -- cgit v1.2.3