diff options
author | Ugnich Anton | 2014-04-24 01:29:12 +0700 |
---|---|---|
committer | Ugnich Anton | 2014-04-24 01:29:12 +0700 |
commit | 0b3c15851c0fbad3ee63cf0df298186a26d2a462 (patch) | |
tree | ef5a750def2821e8d56eae6563737e8773d12b50 /src/java/com/juick/http/www/NewMessage.java | |
parent | 69453d196eb1dcc928c628c7ca32ba2f69ea22ea (diff) |
Recommendations
Diffstat (limited to 'src/java/com/juick/http/www/NewMessage.java')
-rw-r--r-- | src/java/com/juick/http/www/NewMessage.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/java/com/juick/http/www/NewMessage.java b/src/java/com/juick/http/www/NewMessage.java index 79b087eb..fb5e6784 100644 --- a/src/java/com/juick/http/www/NewMessage.java +++ b/src/java/com/juick/http/www/NewMessage.java @@ -26,6 +26,7 @@ import com.juick.xmpp.JID; import com.juick.xmpp.Message; import com.juick.xmpp.Stream; import com.juick.xmpp.extensions.JuickMessage; +import com.juick.xmpp.extensions.JuickUser; import com.juick.xmpp.extensions.Nickname; import com.juick.xmpp.extensions.XOOB; import java.io.IOException; @@ -336,4 +337,38 @@ public class NewMessage { Utils.sendTemporaryRedirect(response, "/" + msg.User.UName + "/" + mid + "#" + ridnew); } + + public void doPostRecomm(Connection sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException { + int mid = Utils.parseInt(request.getParameter("mid"), 0); + if (mid == 0) { + response.sendError(400); + return; + } + com.juick.Message msg = MessagesQueries.getMessage(sql, mid); + if (msg == null) { + response.sendError(404); + return; + } + if (msg.User.UID == visitor.UID) { + response.sendError(403); + return; + } + + boolean res = MessagesQueries.recommendMessage(sql, mid, visitor.UID); + + if (res) { + Message xmsg = new Message(); + xmsg.from = new JID("juick", "juick.com", null); + xmsg.to = new JID("recomm", "s2s.juick.com", null); + JuickMessage jmsg = new JuickMessage(); + jmsg.MID = mid; + jmsg.User = new JuickUser(visitor); + xmsg.addChild(jmsg); + xmpp.send(xmsg); + + Utils.replyJSON(request, response, "{\"status\":\"ok\"}"); + } else { + response.sendError(500); + } + } } |