From 3b92419424bf770c6199b821ba0b7e98c7b1bd99 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Fri, 2 Nov 2012 18:33:10 +0700 Subject: BL-sensible comment form --- src/java/com/juick/http/www/PageTemplates.java | 134 ++++++++++--------------- 1 file changed, 55 insertions(+), 79 deletions(-) (limited to 'src/java/com/juick/http/www/PageTemplates.java') diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index ba5665ed..41646e30 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -17,6 +17,7 @@ */ package com.juick.http.www; +import com.juick.server.MessagesQueries; import com.juick.server.UserQueries; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; @@ -161,15 +162,14 @@ public class PageTemplates { out.println(""); } - public static String formatTags(String tags) { + public static String formatTags(ArrayList tags) { String ret = ""; - String tagsarr[] = tags.split(" "); - for (int i = 0; i < tagsarr.length; i++) { - String tag = tagsarr[i]; + for (int i = 0; i < tags.size(); i++) { + String tag = tags.get(i); tag = tag.replaceAll("<", "<"); tag = tag.replaceAll(">", ">"); try { - ret += " *" + tag + ""; + ret += " *" + tag + ""; } catch (UnsupportedEncodingException e) { } } @@ -277,85 +277,61 @@ public class PageTemplates { public static void printMessages(PrintWriter out, Connection sql, ArrayList mids, com.juick.User visitor, Locale locale) { ResourceBundle rb = ResourceBundle.getBundle("Global", 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_txt.repliesby,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 IN (" + Utils.convertArray2String(mids) + ") ORDER BY messages.message_id DESC"); - rs = stmt.executeQuery(); - rs.beforeFirst(); - while (rs.next()) { - int mid = rs.getInt(1); - int uid = rs.getInt(2); - String uname = rs.getString(3); - String tags = rs.getString(4); - String txt = rs.getString(7); - // timediff - // timestamp - // replies - // 11 repliesby - // attach - // pid - // pname - // lat - // lon - - boolean cancomment = visitor != null; - - tags = (tags != null) ? formatTags(tags) : ""; - if (rs.getInt(5) == 1) { - tags += " *readonly"; - if (visitor != null && visitor.UID != uid) { - cancomment = false; - } - } - switch (rs.getInt(6)) { - case 2: - tags += " *public"; - break; - case -1: - tags += " *friends"; - break; - case -2: - tags += " *private"; - break; - } + ArrayList msgs = MessagesQueries.getMessages(sql, mids); - txt = formatMessage(txt); + ArrayList blUIDs = new ArrayList(20); + for (int i = 0; i < mids.size(); i++) { + blUIDs.add(msgs.get(i).User.UID); + } + blUIDs = UserQueries.checkBL(sql, visitor.UID, blUIDs); - out.println("
  • "); - out.println("
    \""
    "); - out.println(" "); - out.println("
    @" + uname + ":" + tags + "
    "); - if (rs.getString(14) != null) { - out.println("
    " + rs.getString(14) + "
    "); - } - out.println("
    " + txt + "
    "); - - if (rs.getString(12) != null) { - if (rs.getString(12).equals("jpg")) { - out.println("
    \"\"/
    "); - } else { - out.println("
    \"\"/
    "); - } - } + for (int i = 0; i < msgs.size(); i++) { + com.juick.Message msg = msgs.get(i); + + String tags = msg.Tags.isEmpty() ? "" : formatTags(msg.Tags); + if (msg.ReadOnly) { + tags += " *readonly"; + } + switch (msg.Privacy) { + case 2: + tags += " *public"; + break; + case -1: + tags += " *friends"; + break; + case -2: + tags += " *private"; + break; + } + + out.println("
  • "); + out.println("
    \""
    "); + out.println(" "); + out.println(" "); + if (msg.Place != null) { + out.println("
    " + msg.Place.name + "
    "); + } + out.println("
    " + formatMessage(msg.Text) + "
    "); - if (rs.getInt(10) > 0) { - String repliesby = rs.getString(11); - if (repliesby == null) { - repliesby = "..."; - } - out.println("
    " + formatReplies(rs.getInt(10), locale) + " " + rb.getString("(replies) by") + " " + repliesby + "
    "); - } else if (cancomment) { - out.println("
    "); - out.println("
    "); - out.println("
    "); + if (msg.AttachmentType != null) { + if (msg.AttachmentType.equals("jpg")) { + out.println("
    \"\"/
    "); + } else { + out.println("
    \"\"/
    "); } - out.println("
  • "); } - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(rs, stmt); + + msg.ReadOnly |= blUIDs.contains(msg.User.UID); + + if (msg.Replies > 0) { + String repliesby = (msg.RepliesBy != null) ? msg.RepliesBy : "..."; + out.println("
    " + formatReplies(msg.Replies, locale) + " " + rb.getString("(replies) by") + " " + repliesby + "
    "); + } else if (visitor != null && (msg.ReadOnly == false || visitor.UID == msg.User.UID)) { + out.println("
    "); + out.println("
    "); + out.println("
    "); + } + out.println(" "); } } } -- cgit v1.2.3