From 150736c9874f7433b3b08a219635b43ed5b79a04 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 13 Feb 2017 15:53:06 +0300 Subject: juick-xmpp: vcard handler --- .../java/com/juick/components/XMPPConnection.java | 21 +++++++++++++++++++++ juick-xmpp/src/main/resources/juick.png | Bin 0 -> 2324 bytes 2 files changed, 21 insertions(+) create mode 100644 juick-xmpp/src/main/resources/juick.png (limited to 'juick-xmpp/src/main') 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 Binary files /dev/null and b/juick-xmpp/src/main/resources/juick.png differ -- cgit v1.2.3