aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/juick/http/www/UserThread.java
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2012-11-02 18:33:10 +0700
committerGravatar Ugnich Anton2012-11-02 18:33:10 +0700
commit3b92419424bf770c6199b821ba0b7e98c7b1bd99 (patch)
tree56051d952599dc13a8c26d94fd9f4ac6d1d44651 /src/java/com/juick/http/www/UserThread.java
parentb895a6e7a29193754a97e33b6af8bd66f1006fc4 (diff)
BL-sensible comment form
Diffstat (limited to 'src/java/com/juick/http/www/UserThread.java')
-rw-r--r--src/java/com/juick/http/www/UserThread.java77
1 files changed, 32 insertions, 45 deletions
diff --git a/src/java/com/juick/http/www/UserThread.java b/src/java/com/juick/http/www/UserThread.java
index d90d7e94..ec3412f3 100644
--- a/src/java/com/juick/http/www/UserThread.java
+++ b/src/java/com/juick/http/www/UserThread.java
@@ -26,6 +26,7 @@ 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;
@@ -76,7 +77,6 @@ public class UserThread {
out.println("<div id=\"content\" style=\"margin-left: 0; width: 100%\">");
printMessage(out, sql, MID, visitor, locale);
-
printReplies(out, sql, MID, visitor, locale, listview);
out.println("</div>");
@@ -115,7 +115,7 @@ public class UserThread {
boolean cancomment = visitor != null;
- tags = (tags != null) ? PageTemplates.formatTags(tags) : "";
+ tags = (tags != null) ? PageTemplates.formatTags(new ArrayList<String>(Arrays.asList(tags.split(" ")))) : "";
if (rs.getInt(5) == 1) {
tags += " *readonly";
cancomment = false;
@@ -153,6 +153,15 @@ public class UserThread {
}
}
+ boolean visitorInBL = UserQueries.isInBL(sql, uid, visitor.UID);
+
+ if (visitorInBL) {
+ cancomment = false;
+ }
+ if (visitor != null && visitor.UID == uid) {
+ cancomment = true;
+ }
+
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>");
@@ -180,7 +189,9 @@ public class UserThread {
} else {
out.println(" <li><a href=\"/post?body=S+%23" + mid + "\"><div style=\"background-position: -16px 0\"></div>" + rbthread.getString("(MToolbar) Subcribe") + "</a></li>");
}
- out.println(" <li><a href=\"/post?body=%21+%23" + mid + "\"><div style=\"background-position: -32px 0\"></div>" + rbthread.getString("(MToolbar) Recommend") + "</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>");
}
@@ -198,48 +209,24 @@ public class UserThread {
public static void printReplies(PrintWriter out, Connection sql, int mid, com.juick.User visitor, Locale locale, boolean listview) {
ResourceBundle rbuser = ResourceBundle.getBundle("User", locale);
- ArrayList<com.juick.Message> replies = new ArrayList<com.juick.Message>();
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement("SELECT replies.reply_id,replies.replyto,replies.user_id,users.nick,replies.txt,TIMESTAMPDIFF(MINUTE,replies.ts,NOW()),replies.ts,replies.attach FROM replies INNER JOIN users ON replies.user_id=users.id WHERE replies.message_id=? ORDER BY replies.reply_id ASC");
- stmt.setInt(1, mid);
- rs = stmt.executeQuery();
- rs.beforeFirst();
- while (rs.next()) {
- com.juick.Message msg = new com.juick.Message();
- msg.MID = mid;
- msg.RID = rs.getInt(1);
- msg.ReplyTo = rs.getInt(2);
- msg.User = new com.juick.User();
- msg.User.UID = rs.getInt(3);
- msg.User.UName = rs.getString(4);
- msg.Text = PageTemplates.formatMessage(rs.getString(5));
- msg.MinutesAgo = rs.getInt(6);
- msg.TimestampString = rs.getString(7);
- msg.AttachmentType = rs.getString(8);
-
- replies.add(msg);
-
- if (msg.ReplyTo > 0) {
- boolean added = false;
- for (int i = 0; i < replies.size(); i++) {
- if (replies.get(i).RID == msg.ReplyTo) {
- replies.get(i).childs.add(msg);
- added = true;
- break;
- }
- }
- if (!added) {
- msg.ReplyTo = 0;
+ ArrayList<com.juick.Message> replies = MessagesQueries.getReplies(sql, mid);
+
+ for (int i = 0; i < replies.size(); i++) {
+ com.juick.Message msg = replies.get(i);
+ if (msg.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);
+ added = true;
+ break;
}
}
+ if (!added) {
+ msg.ReplyTo = 0;
+ }
}
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
}
if (!replies.isEmpty()) {
@@ -297,9 +284,9 @@ 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.MinutesAgo, msg.TimestampString, locale) + "</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-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:</div>");
- out.println(" <div class=\"msg-txt\">" + msg.Text + "</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) {
@@ -330,9 +317,9 @@ 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.MinutesAgo, msg.TimestampString, locale) + "</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-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:</div>");
- out.println(" <div class=\"msg-txt\">" + msg.Text + "</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>");