From c2d316449f85bd2b74ae9ffaa3d08b7a5ee282cf Mon Sep 17 00:00:00 2001
From: Alex Bitney
Date: Sun, 7 Feb 2016 00:00:41 +0200
Subject: added tags when posting new message added templates engine (rythm
engine) and moved something to it.
WARNING: textext plugin does not work when minimized, and also I fixed bug in it.
---
src/main/java/com/juick/http/www/User.java | 73 +++++++++++++++++++-----------
1 file changed, 47 insertions(+), 26 deletions(-)
(limited to 'src/main/java/com/juick/http/www/User.java')
diff --git a/src/main/java/com/juick/http/www/User.java b/src/main/java/com/juick/http/www/User.java
index 1f2b7dc0..5d06045c 100644
--- a/src/main/java/com/juick/http/www/User.java
+++ b/src/main/java/com/juick/http/www/User.java
@@ -17,25 +17,21 @@
*/
package com.juick.http.www;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.JSONSerializer;
import com.juick.Tag;
import com.juick.server.Endpoints;
import com.juick.server.MessagesQueries;
import com.juick.server.TagQueries;
import com.juick.server.UserQueries;
-import com.juick.xmpp.Stream;
import org.apache.commons.lang3.tuple.Pair;
+import org.json.JSONArray;
+import org.json.JSONObject;
import org.springframework.jdbc.core.JdbcTemplate;
import java.io.IOException;
import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
-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.List;
import java.util.stream.Collectors;
import javax.servlet.ServletException;
@@ -183,7 +179,7 @@ public class User {
pageUserColumn(out, sql, user, visitor);
out.println("");
- out.println("" + pageUserTags(sql, user, visitor, 0) + "
");
+ out.println("" + pageUserTags(sql, user, 0) + "
");
out.println("");
PageTemplates.pageFooter(request, out, visitor, false);
@@ -306,12 +302,16 @@ public class User {
out.println("
Блог");
out.println(" Рекомендации");
out.println(" Фотографии");
+ if (visitor != null && visitor.getUID() == user.getUID()) {
+ out.println(" Мои комментарии");
+ out.println(" Неотвеченные");
+ }
out.println(" ");
out.println("
");
out.println(" ");
- out.println(" " + pageUserTags(sql, user, visitor, 20) + "...
");
+ out.println(" " + pageUserTags(sql, user, 20) + "...
");
out.println("
");
out.println(" ");
out.println(" - Я читаю: " + UserQueries.getStatsIRead(sql, user.getUID()) + "
");
@@ -337,7 +337,28 @@ public class User {
out.println("");
}
- public static String pageUserTags(JdbcTemplate sql, com.juick.User user, com.juick.User visitor, int cnt) {
+ public static String pageUserTags(JdbcTemplate sql, com.juick.User user, int cnt) {
+ List tags = getUserTags(sql, user, cnt);
+
+ int maxUsageCnt = tags.size() > 0 ? tags.stream().mapToInt(tag -> tag.UsageCnt).max().getAsInt() : 1;
+
+ return tags.stream().map(tag -> "" + tag.Name + "")
+ .collect(Collectors.joining(" "));
+
+ /*
+ todo:
+ if (tags[i].UsageCnt > maxUsageCnt / 3 * 2) {
+ ret += "" + tag + " ";
+ } else if (tags[i].UsageCnt > maxUsageCnt / 3) {
+ ret += "" + tag + " ";
+ } else {
+ ret += tag + " ";
+ }
+ }*/
+ }
+
+ public static List getUserTags(JdbcTemplate sql, com.juick.User user, int cnt) {
List tags;
if (cnt > 0) {
tags = sql.query("SELECT tags.name AS name,COUNT(DISTINCT messages_tags.message_id) AS cnt " +
@@ -361,22 +382,22 @@ public class User {
return t;
}), user.getUID());
}
+ return tags;
+ }
- int maxUsageCnt = tags.size() > 0 ? tags.stream().mapToInt(tag -> tag.UsageCnt).max().getAsInt() : 1;
-
- return tags.stream().map(tag -> "" + tag.Name + "")
- .collect(Collectors.joining(" "));
-
- /*
- todo:
- if (tags[i].UsageCnt > maxUsageCnt / 3 * 2) {
- ret += "" + tag + " ";
- } else if (tags[i].UsageCnt > maxUsageCnt / 3) {
- ret += "" + tag + " ";
- } else {
- ret += tag + " ";
+ public void doMyTagsJson(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws IOException {
+ com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
+ if (visitor != null) {
+ List userTags = getUserTags(sql, visitor, 200);
+ JSONArray arr = new JSONArray();
+ for (Tag userTag : userTags) {
+ arr.put(userTag.Name);
}
- }*/
+ response.setContentType("text/json");
+ response.setCharacterEncoding("UTF-8");
+ response.getOutputStream().write(arr.toString().getBytes("UTF-8"));
+ } else {
+ response.sendError(404);
+ }
}
}
--
cgit v1.2.3