From 796c55d1591acc0188c0c269409d914f0dce12c5 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Sat, 2 Nov 2013 03:25:18 +0700 Subject: Ad messages --- src/java/com/juick/http/www/Discover.java | 16 ++++++++++++++-- src/java/com/juick/http/www/Home.java | 17 +++++++++++++++-- src/java/com/juick/http/www/PageTemplates.java | 19 ++++++++++++++++--- src/java/com/juick/http/www/User.java | 6 +++--- src/java/com/juick/http/www/UserThread.java | 3 ++- 5 files changed, 50 insertions(+), 11 deletions(-) (limited to 'src/java/com') diff --git a/src/java/com/juick/http/www/Discover.java b/src/java/com/juick/http/www/Discover.java index a9ae360a..62822ee4 100644 --- a/src/java/com/juick/http/www/Discover.java +++ b/src/java/com/juick/http/www/Discover.java @@ -17,6 +17,7 @@ */ package com.juick.http.www; +import com.juick.server.AdsQueries; import com.juick.server.MessagesQueries; import com.juick.server.TagQueries; import java.io.IOException; @@ -110,13 +111,24 @@ public class Discover { out.println("
"); if (mids.size() > 0) { + int ad_mid = 0; + if (visitor != null && paramShow == null && paramTag == 0 && paramSearch == null) { + ad_mid = AdsQueries.getAdMID(sql, visitor.UID); + if (ad_mid > 0 && mids.indexOf(ad_mid) == -1) { + mids.add(0, ad_mid); + AdsQueries.logAdMID(sql, visitor.UID, ad_mid); + } else { + ad_mid = 0; + } + } + out.println(""); } if (visitor != null) { - if (mids.size() == 20) { + if (mids.size() >= 20) { String nextpage = "?before=" + mids.get(mids.size() - 1); if (paramShow != null) { nextpage += "&show=" + paramShow; diff --git a/src/java/com/juick/http/www/Home.java b/src/java/com/juick/http/www/Home.java index d2500993..2705d953 100644 --- a/src/java/com/juick/http/www/Home.java +++ b/src/java/com/juick/http/www/Home.java @@ -18,6 +18,7 @@ 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; @@ -94,12 +95,24 @@ public class Home { out.println("
"); if (mids.size() > 0) { + int ad_mid = 0; + if (paramShow == null || paramShow.equals("top")) { + ad_mid = AdsQueries.getAdMID(sql, visitor.UID); + + if (ad_mid > 0 && mids.indexOf(ad_mid) == -1) { + mids.add(0, ad_mid); + AdsQueries.logAdMID(sql, visitor.UID, ad_mid); + } else { + ad_mid = 0; + } + } + out.println(""); } - if (mids.size() == 20) { + if (mids.size() >= 20) { String nextpage = "?before=" + mids.get(mids.size() - 1); if (paramShow != null) { nextpage += "&show=" + paramShow; diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index d63cb5f5..c7118277 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -357,11 +357,20 @@ public class PageTemplates { return msg; } - public static void printMessages(PrintWriter out, Connection sql, com.juick.User user, ArrayList mids, com.juick.User visitor, Locale locale, int YandexID) { + public static void printMessages(PrintWriter out, Connection sql, com.juick.User user, ArrayList mids, com.juick.User visitor, Locale locale, int YandexID, int ad_mid) { ResourceBundle rb = ResourceBundle.getBundle("Global", locale); ArrayList msgs = MessagesQueries.getMessages(sql, mids); + for (int i = 0; i < msgs.size(); i++) { + com.juick.Message msg = msgs.get(i); + if (msg.MID == ad_mid) { + msgs.remove(i); + msgs.add(0, msg); + break; + } + } + ArrayList blUIDs = new ArrayList(20); if (visitor != null) { for (int i = 0; i < msgs.size(); i++) { @@ -372,7 +381,7 @@ public class PageTemplates { for (int i = 0; i < msgs.size(); i++) { - if (i == 1 && YandexID > 0) { + if (i == 1 && YandexID > 0 && ad_mid == 0) { out.println("
  • "); out.println("