aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/juick')
-rw-r--r--src/java/com/juick/http/www/PageTemplates.java40
-rw-r--r--src/java/com/juick/http/www/User.java14
-rw-r--r--src/java/com/juick/http/www/UserThread.java280
3 files changed, 182 insertions, 152 deletions
diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java
index 41646e30..2ec42e42 100644
--- a/src/java/com/juick/http/www/PageTemplates.java
+++ b/src/java/com/juick/http/www/PageTemplates.java
@@ -48,17 +48,18 @@ public class PageTemplates {
private static SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
private static SimpleDateFormat sdfSimple = new SimpleDateFormat("d MMM");
private static SimpleDateFormat sdfFull = new SimpleDateFormat("d MMM yyyy");
+ private static SimpleDateFormat sdfJS = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss");
public static void pageHead(PrintWriter out, String title, String headers) {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println(" <title>" + title + "</title>");
- out.println(" <link rel=\"stylesheet\" href=\"//static.juick.com/style3.2012110200.css\"/>");
+ out.println(" <link rel=\"stylesheet\" href=\"//static.juick.com/style3.2012110404.css\"/>");
out.println(" <link rel=\"icon\" type=\"image/png\" href=\"//static.juick.com/favicon.png\"/>");
out.println(" <script type=\"text/javascript\" src=\"//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js\" defer=\"defer\"></script>");
out.println(" <script type=\"text/javascript\" src=\"//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js\" defer=\"defer\" async=\"async\"></script>");
- out.println(" <script type=\"text/javascript\" src=\"//static.juick.com/scripts3.2012102203.js\" defer=\"defer\"></script>");
+ out.println(" <script type=\"text/javascript\" src=\"//static.juick.com/scripts3.2012110400.js\" defer=\"defer\"></script>");
if (headers != null) {
out.println(headers);
}
@@ -77,14 +78,12 @@ public class PageTemplates {
out.println(" </form>");
out.println(" <ul id=\"nav-right\">");
if (user != null) {
- out.println(" <li><a href=\"/post\">" + rb.getString("Post") + "</a></li>");
- out.println(" <li><a href=\"#\" onclick=\"$('#nav-menu').toggle(); return false\"><img src=\"//i.juick.com/as/" + user.UID + ".png\" alt=\"" + user.UName + "\"/>" + user.UName + "</a><ul id=\"nav-menu\">");
- out.println(" <li><a href=\"/" + user.UName + "/\">" + rb.getString("Blog") + "</a></li>");
- out.println(" <li><a href=\"/settings\">" + rb.getString("Settings") + "</a></li>");
- out.println(" <li><a href=\"/logout\">" + rb.getString("Logout") + "</a></li>");
- out.println(" </ul></li>");
+ out.println(" <li><a href=\"/post\" class=\"wide\">" + rb.getString("Post") + "</a></li>");
+ out.println(" <li><a href=\"/" + user.UName + "\" class=\"wide\"><img src=\"//i.juick.com/as/" + user.UID + ".png\" alt=\"" + user.UName + "\"/>" + user.UName + "</a></li>");
+ out.println(" <li><a href=\"/settings\"><div class=\"ico24\" style=\"background-position: 0 11px\"></div></a></li>");
+ out.println(" <li><a href=\"/logout\"><div class=\"ico24\" style=\"background-position: -24px 11px\"></div></a></li>");
} else {
- out.println(" <li><a href=\"/login\">" + rb.getString("Login") + "</a></li>");
+ out.println(" <li><a href=\"/login\" class=\"wide\">" + rb.getString("Login") + "</a></li>");
}
out.println(" </ul>");
out.println("</div>");
@@ -205,6 +204,19 @@ public class PageTemplates {
}
}
+ public static String formatJSLocalTime(String ts) {
+ try {
+ Date date = sdfSQL.parse(ts);
+ return "<script type=\"text/javascript\">"
+ + "var d=new Date(" + date.getTime() + ");"
+ + "document.write(d.getDate()+'.'+(d.getMonth()+1)+'.'+d.getFullYear()+' '+d.getHours()+':'+d.getMinutes());"
+ + "</script>";
+ } catch (ParseException e) {
+ System.err.print(e);
+ }
+ return "";
+ }
+
public static String formatReplies(int replies, Locale loc) {
return replies + " repl" + (replies % 10 == 1 ? "y" : "ies");
}
@@ -280,10 +292,12 @@ public class PageTemplates {
ArrayList<com.juick.Message> msgs = MessagesQueries.getMessages(sql, mids);
ArrayList<Integer> blUIDs = new ArrayList<Integer>(20);
- for (int i = 0; i < mids.size(); i++) {
- blUIDs.add(msgs.get(i).User.UID);
+ if (visitor != null) {
+ for (int i = 0; i < mids.size(); i++) {
+ blUIDs.add(msgs.get(i).User.UID);
+ }
+ blUIDs = UserQueries.checkBL(sql, visitor.UID, blUIDs);
}
- blUIDs = UserQueries.checkBL(sql, visitor.UID, blUIDs);
for (int i = 0; i < msgs.size(); i++) {
com.juick.Message msg = msgs.get(i);
@@ -306,7 +320,7 @@ public class PageTemplates {
out.println(" <li id=\"msg-" + msg.MID + "\" class=\"msg\">");
out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.User.UName + "/\"><img src=\"//i.juick.com/a/" + msg.User.UID + ".png\" alt=\"" + msg.User.UName + "\"/></a></div>");
- out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.User.UName + "/" + msg.MID + "\" title=\"" + msg.TimestampString + "\">" + formatDate(msg.TimeAgo, msg.TimestampString, locale) + "</a></div>");
+ out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.User.UName + "/" + msg.MID + "\" title=\"" + msg.TimestampString + " GMT\">" + formatDate(msg.TimeAgo, msg.TimestampString, locale) + "</a></div>");
out.println(" <div class=\"msg-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:" + tags + "</div>");
if (msg.Place != null) {
out.println(" <div class=\"msg-place\">" + msg.Place.name + "</div>");
diff --git a/src/java/com/juick/http/www/User.java b/src/java/com/juick/http/www/User.java
index f1896837..de0375f3 100644
--- a/src/java/com/juick/http/www/User.java
+++ b/src/java/com/juick/http/www/User.java
@@ -145,7 +145,7 @@ public class User {
try {
PageTemplates.pageHead(out, "@" + user.UName + ": " + rb.getString("(Menu) Tags"), null);
PageTemplates.pageNavigation(out, locale, visitor);
- PageTemplates.pageUserTitle(out, sql, locale, user, visitor);
+ //PageTemplates.pageUserTitle(out, sql, locale, user, visitor);
out.println("<div id=\"topwrapper\">");
out.println("<div id=\"wrapper\">");
@@ -172,7 +172,7 @@ public class User {
try {
PageTemplates.pageHead(out, "@" + user.UName + ": " + rb.getString("(Stats) I read"), null);
PageTemplates.pageNavigation(out, locale, visitor);
- PageTemplates.pageUserTitle(out, sql, locale, user, visitor);
+ //PageTemplates.pageUserTitle(out, sql, locale, user, visitor);
out.println("<div id=\"topwrapper\">");
out.println("<div id=\"wrapper\">");
@@ -270,17 +270,17 @@ public class User {
if (visitor != null && visitor.UID > 0 && visitor.UID != user.UID) {
out.println(" <ul id=\"ctoolbar\">");
if (UserQueries.isSubscribed(sql, visitor.UID, user.UID)) {
- out.println(" <li><a href=\"/post?body=U+%40" + user.UName + "\"><div style=\"background-position: -48px 0\"></div></a></li>");
+ out.println(" <li><a href=\"/post?body=U+%40" + user.UName + "\" title=\"" + rb.getString("(UToolbar) Subcribed") + "\"><div style=\"background-position: -48px 0\"></div></a></li>");
} else {
- out.println(" <li><a href=\"/post?body=S+%40" + user.UName + "\"><div style=\"background-position: -16px 0\"></div></a></li>");
+ out.println(" <li><a href=\"/post?body=S+%40" + user.UName + "\" title=\"" + rb.getString("(UToolbar) Subcribe") + "\"><div style=\"background-position: -16px 0\"></div></a></li>");
}
if (UserQueries.isInBL(sql, visitor.UID, user.UID)) {
- out.println(" <li><a href=\"/post?body=BL+%40" + user.UName + "\"><div style=\"background-position: -96px 0\"></div></a></li>");
+ out.println(" <li><a href=\"/post?body=BL+%40" + user.UName + "\" title=\"" + rb.getString("(UToolbar) Unblock") + "\"><div style=\"background-position: -96px 0\"></div></a></li>");
} else {
- out.println(" <li><a href=\"/post?body=BL+%40" + user.UName + "\"><div style=\"background-position: -80px 0\"></div></a></li>");
+ out.println(" <li><a href=\"/post?body=BL+%40" + user.UName + "\" title=\"" + rb.getString("(UToolbar) Block") + "\"><div style=\"background-position: -80px 0\"></div></a></li>");
}
if (!UserQueries.isInBL(sql, user.UID, visitor.UID)) {
- out.println(" <li><a href=\"/post?body=PM+%40" + user.UName + "\"><div style=\"background-position: -112px 0\"></div></a></li>");
+ out.println(" <li><a href=\"/post?body=PM+%40" + user.UName + "\" title=\"" + rb.getString("(UToolbar) Private") + "\"><div style=\"background-position: -112px 0\"></div></a></li>");
}
out.println(" </ul>");
} else {
diff --git a/src/java/com/juick/http/www/UserThread.java b/src/java/com/juick/http/www/UserThread.java
index ec3412f3..a0bb3a86 100644
--- a/src/java/com/juick/http/www/UserThread.java
+++ b/src/java/com/juick/http/www/UserThread.java
@@ -22,11 +22,7 @@ import com.juick.server.UserQueries;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.servlet.ServletException;
@@ -70,14 +66,14 @@ public class UserThread {
try {
PageTemplates.pageHead(out, title, null);
PageTemplates.pageNavigation(out, locale, visitor);
- PageTemplates.pageUserTitle(out, sql, locale, user, visitor);
+ //PageTemplates.pageUserTitle(out, sql, locale, user, visitor);
out.println("<div id=\"topwrapper\">");
out.println("<div id=\"wrapper\">");
out.println("<div id=\"content\" style=\"margin-left: 0; width: 100%\">");
- printMessage(out, sql, MID, visitor, locale);
- printReplies(out, sql, MID, visitor, locale, listview);
+ com.juick.Message msg = printMessage(out, sql, MID, visitor, locale);
+ printReplies(out, sql, msg, visitor, locale, listview);
out.println("</div>");
out.println("</div>");
@@ -89,154 +85,163 @@ public class UserThread {
}
}
- public static void printMessage(PrintWriter out, Connection sql, int mid, com.juick.User visitor, Locale locale) {
+ public static com.juick.Message printMessage(PrintWriter out, Connection sql, int mid, com.juick.User visitor, Locale locale) {
ResourceBundle rb = ResourceBundle.getBundle("Global", locale);
ResourceBundle rbthread = ResourceBundle.getBundle("UserThread", locale);
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement("SELECT STRAIGHT_JOIN messages.message_id,messages.user_id,users.nick,messages_txt.tags,messages.readonly,messages.privacy,messages_txt.txt,TIMESTAMPDIFF(MINUTE,messages.ts,NOW()),messages.ts,messages.replies,messages.attach,messages.place_id,places.name,messages.lat,messages.lon FROM ((messages INNER JOIN messages_txt ON messages.message_id=messages_txt.message_id) INNER JOIN users ON messages.user_id=users.id) LEFT JOIN places ON messages.place_id=places.place_id WHERE messages.message_id=?");
- stmt.setInt(1, mid);
- rs = stmt.executeQuery();
- if (rs.first()) {
- int uid = rs.getInt(2);
- String uname = rs.getString(3);
- String tags = rs.getString(4);
- String txt = rs.getString(7);
- // timediff
- // timestamp
- // replies
- // attach
- // pid
- // pname
- // lat
- // lon
-
- boolean cancomment = visitor != null;
-
- tags = (tags != null) ? PageTemplates.formatTags(new ArrayList<String>(Arrays.asList(tags.split(" ")))) : "";
- if (rs.getInt(5) == 1) {
- tags += " *readonly";
- cancomment = false;
- }
- switch (rs.getInt(6)) {
- case 2:
- tags += " *public";
- break;
- case -1:
- tags += " *friends";
- break;
- case -2:
- tags += " *private";
- break;
- }
+ com.juick.Message msg = MessagesQueries.getMessage(sql, mid);
- txt = PageTemplates.formatMessage(txt);
+ msg.VisitorCanComment = visitor != null;
- out.println("<ul>");
- out.println(" <li id=\"msg-" + mid + "\" class=\"msg msgthread\">");
-
- out.println(" <div class=\"msg-avatar\"><a href=\"/" + uname + "/\"><img src=\"//i.juick.com/a/" + uid + ".png\" alt=\"" + uname + "\"/></a></div>");
- out.println(" <div class=\"msg-ts\"><a href=\"/" + uname + "/" + mid + "\" title=\"" + rs.getString(9) + "\">" + PageTemplates.formatDate(rs.getInt(8), rs.getString(9), locale) + "</a></div>");
- out.println(" <div class=\"msg-header\"><a href=\"/" + uname + "/\">@" + uname + "</a>:" + tags + "</div>");
- if (rs.getString(13) != null) {
- out.println(" <div class=\"msg-place\">" + rs.getString(14) + "</div>");
- }
- out.println(" <div class=\"msg-txt\">" + txt + "</div>");
+ String tags = (msg.Tags.isEmpty()) ? "" : PageTemplates.formatTags(msg.Tags);
+ if (msg.ReadOnly) {
+ tags += " *readonly";
+ msg.VisitorCanComment = false;
+ }
+ switch (msg.Privacy) {
+ case 2:
+ tags += " *public";
+ break;
+ case -1:
+ tags += " *friends";
+ break;
+ case -2:
+ tags += " *private";
+ break;
+ }
- if (rs.getString(11) != null) {
- if (rs.getString(11).equals("jpg")) {
- out.println(" <div class=\"msg-media\"><a href=\"//i.juick.com/p/" + mid + ".jpg\"><img src=\"//i.juick.com/photos-512/" + mid + ".jpg\" alt=\"\"/></a></div>");
- } else {
- out.println(" <div class=\"msg-media\"><div id=\"video-" + mid + "\"><a href=\"//i.juick.com/video/" + mid + ".mp4\" onclick=\"inlinevideo(" + mid + "); return false\"><img src=\"//i.juick.com/thumbs/" + mid + ".jpg\" alt=\"\"/></a></div></div>");
- }
- }
+ out.println("<ul>");
+ out.println(" <li id=\"msg-" + mid + "\" class=\"msg msgthread\">");
+ out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.User.UName + "/\"><img src=\"//i.juick.com/a/" + msg.User.UID + ".png\" alt=\"" + msg.User.UName + "\"/></a></div>");
+ out.println(" <div class=\"msg-ts\">" + PageTemplates.formatJSLocalTime(msg.TimestampString) + "</div>");
+ out.println(" <div class=\"msg-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:" + tags + "</div>");
+ if (msg.Place != null && msg.Place.pid > 0) {
+ out.println(" <div class=\"msg-place\">" + msg.Place.name + "</div>");
+ }
+ out.println(" <div class=\"msg-txt\">" + PageTemplates.formatMessage(msg.Text) + "</div>");
- boolean visitorInBL = UserQueries.isInBL(sql, uid, visitor.UID);
+ if (msg.AttachmentType != null) {
+ if (msg.AttachmentType.equals("jpg")) {
+ out.println(" <div class=\"msg-media\"><a href=\"//i.juick.com/p/" + mid + ".jpg\"><img src=\"//i.juick.com/photos-512/" + mid + ".jpg\" alt=\"\"/></a></div>");
+ } else {
+ out.println(" <div class=\"msg-media\"><div id=\"video-" + mid + "\"><a href=\"//i.juick.com/video/" + mid + ".mp4\" onclick=\"inlinevideo(" + mid + "); return false\"><img src=\"//i.juick.com/thumbs/" + mid + ".jpg\" alt=\"\"/></a></div></div>");
+ }
+ }
+ boolean visitorInBL = false;
+ if (visitor != null) {
+ if (visitor.UID == msg.User.UID) {
+ msg.VisitorCanComment = true;
+ } else {
+ visitorInBL = UserQueries.isInBL(sql, msg.User.UID, visitor.UID);
if (visitorInBL) {
- cancomment = false;
- }
- if (visitor != null && visitor.UID == uid) {
- cancomment = true;
+ msg.VisitorCanComment = false;
}
+ }
+ }
- if (cancomment) {
- out.println(" <form action=\"/post\" method=\"POST\" enctype=\"multipart/form-data\"><input type=\"hidden\" name=\"mid\" value=\"" + mid + "\"/>");
- out.println(" <div class=\"msg-comment\"><textarea name=\"body\" rows=\"1\" class=\"reply\" placeholder=\"" + rb.getString("Add a comment") + "\" onkeypress=\"postformListener(this.form,event)\"></textarea></div>");
- out.println(" </form>");
- }
+ if (msg.VisitorCanComment) {
+ out.println(" <form action=\"/post\" method=\"POST\" enctype=\"multipart/form-data\"><input type=\"hidden\" name=\"mid\" value=\"" + mid + "\"/>");
+ out.println(" <div class=\"msg-comment\"><textarea name=\"body\" rows=\"1\" class=\"reply\" placeholder=\"" + rb.getString("Add a comment") + "\" onkeypress=\"postformListener(this.form,event)\"></textarea></div>");
+ out.println(" </form>");
+ }
- ArrayList<String> recomm = MessagesQueries.getMessageRecommendations(sql, mid);
- if (!recomm.isEmpty()) {
- out.print(" <div class=\"" + (cancomment ? "msg-recomms" : "msg-comments") + "\">" + rb.getString("Recommended by") + " (" + recomm.size() + "): ");
- for (int i = 0; i < recomm.size(); i++) {
- if (i > 0) {
- out.print(", ");
- }
- out.print("<a href=\"/" + recomm.get(i) + "/\">@" + recomm.get(i) + "</a>");
- }
+ ArrayList<String> recomm = MessagesQueries.getMessageRecommendations(sql, mid);
+ if (!recomm.isEmpty()) {
+ out.print(" <div class=\"" + (msg.VisitorCanComment ? "msg-recomms" : "msg-comments") + "\">" + rb.getString("Recommended by") + " (" + recomm.size() + "): ");
+ for (int i = 0; i < recomm.size(); i++) {
+ if (i > 0) {
+ out.print(", ");
}
+ out.print("<a href=\"/" + recomm.get(i) + "/\">@" + recomm.get(i) + "</a>");
+ }
+ }
- out.println(" </li>");
- out.println(" <li class=\"mtoolbar\"><ul>");
- out.println(" <li><a href=\"/" + mid + "\"><div style=\"background-position: -64px 0\"></div>" + mid + "</a></li>");
- if (visitor != null) {
- if (visitor.UID != uid) {
- if (MessagesQueries.isSubscribed(sql, visitor.UID, mid)) {
- out.println(" <li><a href=\"/post?body=U+%23" + mid + "\"><div style=\"background-position: -48px 0\"></div>" + rbthread.getString("(MToolbar) Subcribed") + "</a></li>");
- } else {
- out.println(" <li><a href=\"/post?body=S+%23" + mid + "\"><div style=\"background-position: -16px 0\"></div>" + rbthread.getString("(MToolbar) Subcribe") + "</a></li>");
- }
- if (!visitorInBL) {
- out.println(" <li><a href=\"/post?body=%21+%23" + mid + "\"><div style=\"background-position: -32px 0\"></div>" + rbthread.getString("(MToolbar) Recommend") + "</a></li>");
- }
- } else {
- out.println(" <li><a href=\"/post?body=D+%23" + mid + "\"><div style=\"background-position: 0\"></div>" + rbthread.getString("(MToolbar) Delete") + "</a></li>");
- }
+ out.println(" </li>");
+ out.println(" <li class=\"mtoolbar\"><ul>");
+ out.println(" <li><a href=\"/" + mid + "\"><div style=\"background-position: -64px 0\"></div>" + mid + "</a></li>");
+ if (visitor != null) {
+ if (visitor.UID != msg.User.UID) {
+ if (MessagesQueries.isSubscribed(sql, visitor.UID, mid)) {
+ out.println(" <li><a href=\"/post?body=U+%23" + mid + "\"><div style=\"background-position: -48px 0\"></div>" + rbthread.getString("(MToolbar) Subcribed") + "</a></li>");
+ } else {
+ out.println(" <li><a href=\"/post?body=S+%23" + mid + "\"><div style=\"background-position: -16px 0\"></div>" + rbthread.getString("(MToolbar) Subcribe") + "</a></li>");
+ }
+ if (!visitorInBL) {
+ out.println(" <li><a href=\"/post?body=%21+%23" + mid + "\"><div style=\"background-position: -32px 0\"></div>" + rbthread.getString("(MToolbar) Recommend") + "</a></li>");
}
- out.println(" </ul></li>");
- out.println("</ul>");
+ } else {
+ out.println(" <li><a href=\"/post?body=D+%23" + mid + "\"><div style=\"background-position: 0\"></div>" + rbthread.getString("(MToolbar) Delete") + "</a></li>");
}
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
}
+ out.println(" </ul></li>");
+ out.println("</ul>");
+ return msg;
}
- public static void printReplies(PrintWriter out, Connection sql, int mid, com.juick.User visitor, Locale locale, boolean listview) {
+ public static void printReplies(PrintWriter out, Connection sql, com.juick.Message msg, com.juick.User visitor, Locale locale, boolean listview) {
ResourceBundle rbuser = ResourceBundle.getBundle("User", locale);
- ArrayList<com.juick.Message> replies = MessagesQueries.getReplies(sql, mid);
+ ArrayList<com.juick.Message> replies = MessagesQueries.getReplies(sql, msg.MID);
+ ArrayList<Integer> blUIDs = new ArrayList<Integer>();
for (int i = 0; i < replies.size(); i++) {
- com.juick.Message msg = replies.get(i);
- if (msg.ReplyTo > 0) {
+ com.juick.Message reply = replies.get(i);
+ if (reply.User.UID != msg.User.UID && !blUIDs.contains(reply.User.UID)) {
+ blUIDs.add(reply.User.UID);
+ }
+ if (reply.ReplyTo > 0) {
boolean added = false;
for (int n = 0; n < replies.size(); n++) {
- if (replies.get(n).RID == msg.ReplyTo) {
- replies.get(n).childs.add(msg);
+ if (replies.get(n).RID == reply.ReplyTo) {
+ replies.get(n).childs.add(reply);
added = true;
break;
}
}
if (!added) {
- msg.ReplyTo = 0;
+ reply.ReplyTo = 0;
}
}
}
if (!replies.isEmpty()) {
+ if (visitor != null && msg.User.UID == visitor.UID) {
+ for (int i = 0; i < replies.size(); i++) {
+ replies.get(i).VisitorCanComment = true;
+ }
+ } else if (visitor != null && msg.VisitorCanComment) {
+ blUIDs = UserQueries.checkBL(sql, visitor.UID, blUIDs);
+ for (int i = 0; i < replies.size(); i++) {
+ com.juick.Message reply = replies.get(i);
+ reply.VisitorCanComment = reply.User.UID == visitor.UID || !blUIDs.contains(reply.User.UID);
+ }
+ } else {
+ for (int i = 0; i < replies.size(); i++) {
+ replies.get(i).VisitorCanComment = false;
+ }
+ }
+
+ boolean foldable = false;
+ if (replies.size() > 10) {
+ for (int i = 0; i < replies.size() - 1; i++) {
+ if (replies.get(i).getChildsCount() > 1) {
+ foldable = true;
+ break;
+ }
+ }
+ }
out.println("<div class=\"title2\">");
out.print(" <div class=\"title2-right\">");
if (listview) {
out.print("<a href=\"?view=tree\">" + rbuser.getString("View as tree") + "</a>");
} else {
- out.print("<span id=\"unfoldall\"><a href=\"#\" onclick=\"$('#replies>li').show(); $('#replies .msg-comments').hide(); $('#unfoldall').hide(); return false\">" + rbuser.getString("Expand all") + "</a> &#183; </span><a href=\"?view=list\">" + rbuser.getString("View as list") + "</a>");
+ if (foldable) {
+ out.print("<span id=\"unfoldall\"><a href=\"#\" onclick=\"$('#replies>li').show(); $('#replies .msg-comments').hide(); $('#unfoldall').hide(); return false\">" + rbuser.getString("Expand all") + "</a> &#183; </span>");
+ }
+ out.print("<a href=\"?view=list\">" + rbuser.getString("View as list") + "</a>");
}
out.print("</div>");
out.println(" <h2>" + rbuser.getString("Replies") + " (" + replies.size() + ")</h2>");
@@ -246,18 +251,18 @@ public class UserThread {
if (listview) {
printList(out, replies, locale);
} else {
- printTree(out, replies, 0, 0, locale);
+ printTree(out, replies, 0, 0, false, locale);
}
out.println("</ul>");
- }
- for (int i = 0; i < replies.size(); i++) {
- replies.get(i).cleanupChilds();
+ for (int i = 0; i < replies.size(); i++) {
+ replies.get(i).cleanupChilds();
+ }
+ replies.clear();
}
- replies.clear();
}
- public static void printTree(PrintWriter out, ArrayList<com.juick.Message> replies, int ReplyTo, int margin, Locale locale) {
+ public static void printTree(PrintWriter out, ArrayList<com.juick.Message> replies, int ReplyTo, int margin, boolean hidden, Locale locale) {
ResourceBundle rb = ResourceBundle.getBundle("Global", locale);
if (margin > 420) {
@@ -273,7 +278,10 @@ public class UserThread {
out.print("border: 0;");
}
if (margin > 0) {
- out.print("margin-left: " + margin + "px;display:none;");
+ out.print("margin-left: " + margin + "px;");
+ }
+ if (hidden) {
+ out.print("display:none;");
}
out.println("\">");
if (msg.AttachmentType != null) {
@@ -284,20 +292,26 @@ public class UserThread {
}
}
out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.User.UName + "/\"><img src=\"//i.juick.com/a/" + msg.User.UID + ".png\" alt=\"" + msg.User.UName + "\"/></a></div>");
- out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.MID + "#" + msg.RID + "\" title=\"" + msg.TimestampString + "\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString, locale) + "</a></div>");
+ out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.MID + "#" + msg.RID + "\" title=\"" + msg.TimestampString + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString, locale) + "</a></div>");
out.println(" <div class=\"msg-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:</div>");
out.println(" <div class=\"msg-txt\">" + PageTemplates.formatMessage(msg.Text) + "</div>");
- out.println(" <div class=\"msg-links\"><a href=\"#\" onclick=\"return showCommentForm(" + msg.MID + "," + msg.RID + ")\">" + rb.getString("Comment") + "</a></div>");
- out.println(" <div class=\"msg-comment\" style=\"display: none\"></div>");
- if (ReplyTo == 0) {
- int childs = msg.getChildsCount() - 1;
- if (childs > 0) {
- out.println(" <div class=\"msg-comments\"><a href=\"#\" onclick=\"return showMoreReplies(" + msg.RID + ")\">" + PageTemplates.formatReplies(childs, locale) + " more</a></div>");
- }
+ if (msg.VisitorCanComment) {
+ out.println(" <div class=\"msg-links\"><a href=\"#\" onclick=\"return showCommentForm(" + msg.MID + "," + msg.RID + ")\">" + rb.getString("Comment") + "</a></div>");
+ out.println(" <div class=\"msg-comment\" style=\"display: none\"></div>");
+ }
+
+ int childs = msg.getChildsCount();
+ if (ReplyTo == 0 && childs > 1 && replies.size() > 10) {
+ out.println(" <div class=\"msg-comments\"><a href=\"#\" onclick=\"return showMoreReplies(" + msg.RID + ")\">" + PageTemplates.formatReplies(childs, locale) + " more</a></div>");
+
}
out.println(" </li>");
- printTree(out, replies, msg.RID, margin + 20, locale);
+ if (ReplyTo == 0 && childs > 1 && replies.size() > 10) {
+ printTree(out, msg.childs, msg.RID, margin + 20, true, locale);
+ } else if (childs > 0) {
+ printTree(out, msg.childs, msg.RID, margin + 20, hidden, locale);
+ }
}
}
}
@@ -317,15 +331,17 @@ public class UserThread {
}
}
out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.User.UName + "/\"><img src=\"//i.juick.com/a/" + msg.User.UID + ".png\"></a></div>");
- out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.MID + "#" + msg.RID + "\" title=\"" + msg.TimestampString + "\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString, locale) + "</a></div>");
+ out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.MID + "#" + msg.RID + "\" title=\"" + msg.TimestampString + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString, locale) + "</a></div>");
out.println(" <div class=\"msg-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:</div>");
out.println(" <div class=\"msg-txt\">" + PageTemplates.formatMessage(msg.Text) + "</div>");
out.print(" <div class=\"msg-links\">/" + msg.RID);
if (msg.ReplyTo > 0) {
out.print(" " + rb.getString("in reply to") + " <a href=\"#" + msg.ReplyTo + "\">/" + msg.ReplyTo + "</a>");
}
- out.println(" &#183; <a href=\"#\" onclick=\"return showCommentForm(" + msg.MID + "," + msg.RID + ")\">" + rb.getString("Comment") + "</a></div>");
- out.println(" <div class=\"msg-comment\" style=\"display: none\"></div>");
+ if (msg.VisitorCanComment) {
+ out.println(" &#183; <a href=\"#\" onclick=\"return showCommentForm(" + msg.MID + "," + msg.RID + ")\">" + rb.getString("Comment") + "</a></div>");
+ out.println(" <div class=\"msg-comment\" style=\"display: none\"></div>");
+ }
out.println(" </li>");
}
}