diff options
author | Vitaly Takmazov | 2016-11-15 14:51:36 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-11-15 14:51:36 +0300 |
commit | 1c65b6d29c0fc69d861ffa0e624f73981b62cca6 (patch) | |
tree | eb0eea5841ba6114f9e21ed081d27e2988eba7e8 /juick-www/src/main/java/com/juick/www/NewMessage.java | |
parent | 51d9de02265d6cc9d6045d79497d2a987ae2f7f7 (diff) |
juick-www: ugnich xmpp -> babbler
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/NewMessage.java')
-rw-r--r-- | juick-www/src/main/java/com/juick/www/NewMessage.java | 102 |
1 files changed, 49 insertions, 53 deletions
diff --git a/juick-www/src/main/java/com/juick/www/NewMessage.java b/juick-www/src/main/java/com/juick/www/NewMessage.java index 310ede73..29c834d6 100644 --- a/juick-www/src/main/java/com/juick/www/NewMessage.java +++ b/juick-www/src/main/java/com/juick/www/NewMessage.java @@ -19,19 +19,17 @@ package com.juick.www; import com.juick.Tag; import com.juick.server.*; -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 net.coobird.thumbnailator.Thumbnails; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.math.NumberUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.jdbc.core.JdbcTemplate; +import rocks.xmpp.addr.Jid; +import rocks.xmpp.core.session.XmppSession; +import rocks.xmpp.core.stanza.model.Message; +import rocks.xmpp.extensions.nick.model.Nickname; +import rocks.xmpp.extensions.oob.model.x.OobX; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -39,6 +37,8 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLEncoder; import java.nio.file.Files; @@ -148,7 +148,7 @@ public class NewMessage { out.println("</p>"); } - public void doPostMessage(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException { + public void doPostMessage(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, XmppSession xmpp, com.juick.User visitor) throws ServletException, IOException { String body = request.getParameter("body"); if (body == null || body.length() < 1 || body.length() > 4096) { response.sendError(400); @@ -201,16 +201,12 @@ public class NewMessage { SubscriptionsQueries.subscribeMessage(sql, mid, visitor.getUid()); Message xmsg = new Message(); - xmsg.from = new JID("juick", "juick.com", null); - xmsg.type = Message.Type.chat; - xmsg.thread = "juick-" + mid; - - JuickMessage jmsg = new JuickMessage(MessagesQueries.getMessage(sql, mid)); - xmsg.addChild(jmsg); - - Nickname nick = new Nickname(); - nick.Nickname = "@" + jmsg.getUser().getName(); - xmsg.addChild(nick); + xmsg.setFrom(Jid.of("juick@juick.com")); + xmsg.setType(Message.Type.CHAT); + xmsg.setThread("juick-" + mid); + com.juick.Message jmsg = MessagesQueries.getMessage(sql, mid); + xmsg.addExtension(jmsg); + xmsg.addExtension(new Nickname("@" + jmsg.getUser().getName())); if (attachmentFName != null) { String fname = mid + "." + attachmentType; @@ -226,9 +222,11 @@ public class NewMessage { .toFile(Paths.get(imgDir, "ps", fname).toFile()); body = attachmentURL + "\n" + body; - XOOB xoob = new XOOB(); - xoob.URL = attachmentURL; - xmsg.addChild(xoob); + try { + xmsg.addExtension(new OobX(new URI(attachmentURL))); + } catch (URISyntaxException e) { + logger.warn("invalid uri: " + attachmentURL, e); + } } if (xmpp != null) { @@ -236,25 +234,23 @@ public class NewMessage { for (String tag : tagsArr) { tagsStr2 += " *" + tag; } - xmsg.body = "@" + jmsg.getUser().getName() + ":" + tagsStr2 + "\n" + body + "\n\n#" + mid + " http://juick.com/" + mid; + xmsg.setBody("@" + jmsg.getUser().getName() + ":" + tagsStr2 + "\n" + body + "\n\n#" + mid + " http://juick.com/" + mid); - xmsg.to = new JID("juick", "s2s.juick.com", null); + xmsg.setTo(Jid.of("juick@s2s.juick.com")); xmpp.send(xmsg); - xmsg.to.Host = "ws.juick.com"; + xmsg.setTo(Jid.of("juick@ws.juick.com")); xmpp.send(xmsg); - xmsg.to.Host = "push.juick.com"; + xmsg.setTo(Jid.of("juick@push.juick.com")); xmpp.send(xmsg); - xmsg.to.Host = "crosspost.juick.com"; - xmsg.to.Username = "twitter"; + xmsg.setTo(Jid.of("twitter@crosspost.juick.com")); xmpp.send(xmsg); - xmsg.to.Username = "fb"; + xmsg.setTo(Jid.of("fb@crosspost.juick.com")); xmpp.send(xmsg); - xmsg.to.Host = "nologin.ru"; - xmsg.to.Username = "jubo"; + xmsg.setTo(Jid.of("jubo@nologin.ru")); xmpp.send(xmsg); } else { logger.warn("XMPP unavailable"); @@ -308,7 +304,7 @@ public class NewMessage { } } - public void doPostComment(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException { + public void doPostComment(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, XmppSession xmpp, com.juick.User visitor) throws ServletException, IOException { int mid = NumberUtils.toInt(request.getParameter("mid"), 0); if (mid == 0) { response.sendError(400); @@ -367,21 +363,18 @@ public class NewMessage { SubscriptionsQueries.subscribeMessage(sql, mid, visitor.getUid()); Message xmsg = new Message(); - xmsg.from = new JID("juick", "juick.com", null); - xmsg.type = Message.Type.chat; - xmsg.thread = "juick-" + mid; + xmsg.setFrom(Jid.of("juick@juick.com")); + xmsg.setType(Message.Type.CHAT); + xmsg.setThread("juick-" + mid); - JuickMessage jmsg = new JuickMessage(MessagesQueries.getReply(sql, mid, ridnew)); - xmsg.addChild(jmsg); + com.juick.Message jmsg = MessagesQueries.getReply(sql, mid, ridnew); + xmsg.addExtension(jmsg); String quote = reply != null ? reply.getText() : msg.getText(); if (quote.length() >= 50) { quote = quote.substring(0, 47) + "..."; } - - Nickname nick = new Nickname(); - nick.Nickname = "@" + jmsg.getUser().getName(); - xmsg.addChild(nick); + xmsg.addExtension(new Nickname("@" + jmsg.getUser().getName())); if (attachmentFName != null) { String fname = mid + "-" + ridnew + "." + attachmentType; @@ -397,22 +390,25 @@ public class NewMessage { .toFile(Paths.get(imgDir, "ps", fname).toFile()); body = attachmentURL + "\n" + body; - XOOB xoob = new XOOB(); - xoob.URL = attachmentURL; - xmsg.addChild(xoob); + try { + xmsg.addExtension(new OobX(new URI(attachmentURL))); + } catch (URISyntaxException e) { + logger.warn("invalid uri: " + attachmentURL, e); + } } if (xmpp != null) { - xmsg.body = "Reply by @" + jmsg.getUser().getName() + ":\n>" + quote + "\n" + body + "\n\n#" + mid + "/" + ridnew + " http://juick.com/" + mid + "#" + ridnew; + xmsg.setBody("Reply by @" + jmsg.getUser().getName() + ":\n>" + quote + "\n" + body + "\n\n#" + + mid + "/" + ridnew + " http://juick.com/" + mid + "#" + ridnew); - xmsg.to = new JID("juick", "s2s.juick.com", null); + xmsg.setTo(Jid.of("juick@s2s.juick.com")); xmpp.send(xmsg); - xmsg.to.Host = "ws.juick.com"; + xmsg.setTo(Jid.of("juick@ws.juick.com")); xmpp.send(xmsg); - xmsg.to.Host = "push.juick.com"; + xmsg.setTo(Jid.of("juick@push.juick.com")); xmpp.send(xmsg); } else { logger.warn("XMPP unavailable"); @@ -421,7 +417,7 @@ public class NewMessage { Utils.sendTemporaryRedirect(response, "/" + msg.getUser().getName() + "/" + mid + "#" + ridnew); } - public void doPostRecomm(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException { + public void doPostRecomm(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, XmppSession xmpp, com.juick.User visitor) throws ServletException, IOException { int mid = NumberUtils.toInt(request.getParameter("mid"), 0); if (mid == 0) { response.sendError(400); @@ -442,12 +438,12 @@ public class NewMessage { if (res) { if (xmpp != null) { 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(); + xmsg.setFrom(Jid.of("juick@juick.com")); + xmsg.setTo(Jid.of("recomm@s2s.juick.com")); + com.juick.Message jmsg = new com.juick.Message(); jmsg.setMid(mid); - jmsg.setUser(new JuickUser(visitor)); - xmsg.addChild(jmsg); + jmsg.setUser(visitor); + xmsg.addExtension(jmsg); xmpp.send(xmsg); } else { logger.warn("XMPP unavailable"); |