aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/juick/api
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2014-03-20 02:36:35 +0700
committerGravatar Ugnich Anton2014-03-20 02:36:35 +0700
commitb9de1e4cf886ee5b0fbd7025e2cf0fee6166d2ce (patch)
tree5a05c97ead9ec4ffbbaca24e22391aef0b69aff4 /src/java/com/juick/api
parentebbd16e1553d25dcd1135c4b3a3a9279f4509844 (diff)
Messages.doSetPopular crosspost
Diffstat (limited to 'src/java/com/juick/api')
-rw-r--r--src/java/com/juick/api/Main.java2
-rw-r--r--src/java/com/juick/api/Messages.java34
2 files changed, 33 insertions, 3 deletions
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\"}");
}
}