aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src/main
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-02-13 15:53:06 +0300
committerGravatar Vitaly Takmazov2017-02-13 17:03:20 +0300
commit150736c9874f7433b3b08a219635b43ed5b79a04 (patch)
tree2cc1e7775ec33a1e21ed9003b7d6421e7aa108b4 /juick-xmpp/src/main
parent0ad9a927646d1f63868317fe2ebf7131ebe28b22 (diff)
juick-xmpp: vcard handler
Diffstat (limited to 'juick-xmpp/src/main')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/XMPPConnection.java21
-rw-r--r--juick-xmpp/src/main/resources/juick.pngbin0 -> 2324 bytes
2 files changed, 21 insertions, 0 deletions
diff --git a/juick-xmpp/src/main/java/com/juick/components/XMPPConnection.java b/juick-xmpp/src/main/java/com/juick/components/XMPPConnection.java
index f76595a1..54165b26 100644
--- a/juick-xmpp/src/main/java/com/juick/components/XMPPConnection.java
+++ b/juick-xmpp/src/main/java/com/juick/components/XMPPConnection.java
@@ -3,12 +3,14 @@ package com.juick.components;
import com.juick.User;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import rocks.xmpp.addr.Jid;
import rocks.xmpp.core.XmppException;
+import rocks.xmpp.core.stanza.AbstractIQHandler;
import rocks.xmpp.core.stanza.model.IQ;
import rocks.xmpp.core.stanza.model.Message;
import rocks.xmpp.core.stanza.model.Stanza;
@@ -20,6 +22,7 @@ import rocks.xmpp.extensions.nick.model.Nickname;
import rocks.xmpp.extensions.oob.model.x.OobX;
import rocks.xmpp.extensions.ping.PingManager;
import rocks.xmpp.extensions.receipts.MessageDeliveryReceiptsManager;
+import rocks.xmpp.extensions.vcard.temp.model.VCard;
import rocks.xmpp.util.XmppUtils;
import javax.annotation.PostConstruct;
@@ -29,8 +32,10 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.io.IOException;
import java.io.StringWriter;
+import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -62,6 +67,22 @@ public class XMPPConnection implements AutoCloseable {
MessageDeliveryReceiptsManager messageDeliveryReceiptsManager =
router.getManager(MessageDeliveryReceiptsManager.class);
messageDeliveryReceiptsManager.setEnabled(true);
+ VCard vCard = new VCard();
+ vCard.setFormattedName("Juick");
+ try {
+ vCard.setUrl(new URL("http://juick.com/"));
+ vCard.setPhoto(new VCard.Image("image/png", IOUtils.toByteArray(getClass().getClassLoader().getResource("juick.png"))));
+ } catch (MalformedURLException e) {
+ logger.error("invalid url", e);
+ } catch (IOException e) {
+ logger.warn("invalid resource", e);
+ }
+ router.addIQHandler(VCard.class, new AbstractIQHandler(IQ.Type.GET) {
+ @Override
+ protected IQ processRequest(IQ iq) {
+ return iq.createResult(vCard);
+ }
+ });
router.addInboundMessageListener(e -> {
Message message = e.getMessage();
Jid jid = message.getTo();
diff --git a/juick-xmpp/src/main/resources/juick.png b/juick-xmpp/src/main/resources/juick.png
new file mode 100644
index 00000000..c85ef2c4
--- /dev/null
+++ b/juick-xmpp/src/main/resources/juick.png
Binary files differ