From 36c8ec33c09fbfd0f82a5a4121ef63ed1ec77457 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Mon, 27 Jan 2014 06:21:29 +0700 Subject: Popular on the main page --- src/java/com/juick/http/www/Home.java | 34 ++++++++++---------------- src/java/com/juick/http/www/Main.java | 12 +++------ src/java/com/juick/http/www/PageTemplates.java | 8 +++--- 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/src/java/com/juick/http/www/Home.java b/src/java/com/juick/http/www/Home.java index 029f76ad..5ef43858 100644 --- a/src/java/com/juick/http/www/Home.java +++ b/src/java/com/juick/http/www/Home.java @@ -17,10 +17,8 @@ */ package com.juick.http.www; -import com.juick.json.Users; import com.juick.server.AdsQueries; import com.juick.server.MessagesQueries; -import com.juick.server.PMQueries; import java.io.IOException; import java.io.PrintWriter; import java.net.URLEncoder; @@ -63,24 +61,28 @@ public class Home { if (paramSearch != null) { title = rb.getString("Search") + ": " + Utils.encodeHTML(paramSearch); mids = MessagesQueries.getSearch(sql, sqlSearch, Utils.encodeSphinx(paramSearch), paramBefore); - } else if (paramShow == null || paramShow.equals("my")) { + } else if (paramShow == null || paramShow.equals("top")) { + title = rb.getString("Popular"); + mids = MessagesQueries.getPopular(sql, paramBefore); + } else if (paramShow.equals("my") && visitor != null) { title = rb.getString("My feed"); mids = MessagesQueries.getMyFeed(sql, visitor.UID, paramBefore); - } else if (paramShow.equals("private")) { + } else if (paramShow.equals("private") && visitor != null) { title = rb.getString("Private"); mids = MessagesQueries.getPrivate(sql, visitor.UID, paramBefore); - } else if (paramShow.equals("discuss")) { + } else if (paramShow.equals("discuss") && visitor != null) { title = rb.getString("Discussions"); mids = MessagesQueries.getDiscussions(sql, visitor.UID, paramBefore); - } else if (paramShow.equals("recommended")) { + } else if (paramShow.equals("recommended") && visitor != null) { title = rb.getString("Recommended"); mids = MessagesQueries.getRecommended(sql, visitor.UID, paramBefore); - } else if (paramShow.equals("top")) { - title = rb.getString("Popular"); - mids = MessagesQueries.getPopular(sql, paramBefore); } else if (paramShow.equals("all")) { title = rb.getString("Last messages"); - mids = MessagesQueries.getAll(sql, visitor.UID, paramBefore); + if (visitor != null) { + mids = MessagesQueries.getAll(sql, visitor.UID, paramBefore); + } else { + mids = MessagesQueries.getAll(sql, 0, paramBefore); + } } else { response.sendError(404); return; @@ -92,16 +94,6 @@ public class Home { PageTemplates.pageHead(out, title, null); PageTemplates.pageNavigation(out, locale, visitor, null); - ArrayList lastconv = PMQueries.getPMLastConversationsUsers(sql, visitor.UID, 10); - String lastConvJSON = Users.arrayToString(lastconv); - - out.println(""); - out.println("
"); out.println("
"); out.println("
"); @@ -112,7 +104,7 @@ public class Home { if (mids.size() > 0) { int ad_mid = 0; - if (paramShow == null || paramShow.equals("top") || paramShow.equals("all")) { + if (visitor != null && (paramShow == null || paramShow.equals("top") || paramShow.equals("all"))) { ad_mid = AdsQueries.getAdMID(sql, visitor.UID); if (ad_mid > 0 && mids.indexOf(ad_mid) == -1) { diff --git a/src/java/com/juick/http/www/Main.java b/src/java/com/juick/http/www/Main.java index 998fb4f3..59065341 100644 --- a/src/java/com/juick/http/www/Main.java +++ b/src/java/com/juick/http/www/Main.java @@ -143,28 +143,24 @@ public class Main extends HttpServlet implements Stream.StreamListener { if (uri.equals("/")) { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - if (visitor == null) { - login.doGetLoginForm(sql, request, response); - } else { - home.doGet(sql, sqlSearch, request, response, visitor); - } + home.doGet(sql, sqlSearch, request, response, visitor); } else if (uri.equals("/post")) { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); if (visitor != null) { pagesNewMessage.doGetNewMessage(sql, request, response, visitor); } else { - Utils.sendTemporaryRedirect(response, "/"); + Utils.sendTemporaryRedirect(response, "/login"); } } else if (uri.equals("/login")) { if (request.getQueryString() == null) { - Utils.sendPermanentRedirect(response, "/"); + login.doGetLoginForm(sql, request, response); } else { login.doGetLogin(sql, request, response); } } else if (uri.startsWith("/pm/")) { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); if (visitor == null) { - login.doGetLoginForm(sql, request, response); + Utils.sendTemporaryRedirect(response, "/login"); } else { if (uri.equals("/pm/inbox")) { pm.doGetInbox(sql, request, response, visitor); diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index 73910321..16a00d24 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -74,7 +74,7 @@ public class PageTemplates { out.println("
"); out.println(""); out.println("
"); @@ -180,12 +180,12 @@ public class PageTemplates { out.println("
"); out.println(" "); out.println("
"); -- cgit v1.2.3