From b9de1e4cf886ee5b0fbd7025e2cf0fee6166d2ce Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Thu, 20 Mar 2014 02:36:35 +0700 Subject: Messages.doSetPopular crosspost --- src/java/com/juick/api/Main.java | 2 +- src/java/com/juick/api/Messages.java | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'src/java') diff --git a/src/java/com/juick/api/Main.java b/src/java/com/juick/api/Main.java index c4fe911e..71b70839 100644 --- a/src/java/com/juick/api/Main.java +++ b/src/java/com/juick/api/Main.java @@ -167,7 +167,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { response.sendError(401); } } else if (uri.equals("/messages/set_popular") && vuid == 1) { - messages.doSetPopular(request, response); + messages.doSetPopular(request, response, xmpp); } else { response.sendError(404); } diff --git a/src/java/com/juick/api/Messages.java b/src/java/com/juick/api/Messages.java index 3aeede68..b7d0891e 100644 --- a/src/java/com/juick/api/Messages.java +++ b/src/java/com/juick/api/Messages.java @@ -1,6 +1,10 @@ package com.juick.api; import com.juick.server.MessagesQueries; +import com.juick.xmpp.JID; +import com.juick.xmpp.Message; +import com.juick.xmpp.Stream; +import com.juick.xmpp.extensions.JuickMessage; import java.io.IOException; import java.sql.Connection; import java.util.ArrayList; @@ -37,12 +41,38 @@ public class Messages { } } - public void doSetPopular(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + public void doSetPopular(HttpServletRequest request, HttpServletResponse response, Stream xmpp) throws ServletException, IOException { int mid = Utils.parseInt(request.getParameter("mid"), 0); int popular = Utils.parseInt(request.getParameter("popular"), 0); if (mid > 0) { - MessagesQueries.setMessagePopular(sql, mid, popular); + boolean ret = MessagesQueries.setMessagePopular(sql, mid, popular); + + if (ret && popular == 2) { + try { + com.juick.Message m = MessagesQueries.getMessage(sql, mid); + if (m != null) { + Message msg = new Message(); + msg.from = new JID("juick", "juick.com", null); + msg.to = new JID(null, "crosspost.juick.com", null); + JuickMessage jmsg = new JuickMessage(m); + jmsg.User.UID = 11574; + msg.childs.add(jmsg); + + msg.to.Username = "twitter"; + xmpp.send(msg); + msg.to.Username = "fb"; + xmpp.send(msg); + msg.to.Username = "vk"; + xmpp.send(msg); + } else { + throw new Exception("Message not found"); + } + } catch (Exception e) { + System.err.println("SETPOPULAR ERROR: " + e.toString()); + } + } + Main.replyJSON(request, response, "{\"status\":\"ok\"}"); } } -- cgit v1.2.3