From b3ac09ede10854dd277989d7296416c34916eeb1 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 13 Feb 2017 22:29:32 +0300 Subject: juick-xmpp: handle user vcards --- .../java/com/juick/components/XMPPConnection.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'juick-xmpp/src') 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 54165b26..471e2c81 100644 --- a/juick-xmpp/src/main/java/com/juick/components/XMPPConnection.java +++ b/juick-xmpp/src/main/java/com/juick/components/XMPPConnection.java @@ -1,6 +1,7 @@ package com.juick.components; import com.juick.User; +import com.juick.server.helpers.UserInfo; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; @@ -14,7 +15,9 @@ 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; +import rocks.xmpp.core.stanza.model.client.ClientIQ; import rocks.xmpp.core.stanza.model.client.ClientMessage; +import rocks.xmpp.core.stanza.model.errors.Condition; import rocks.xmpp.extensions.component.accept.ExternalComponent; import rocks.xmpp.extensions.filetransfer.FileTransfer; import rocks.xmpp.extensions.filetransfer.FileTransferManager; @@ -80,7 +83,27 @@ public class XMPPConnection implements AutoCloseable { router.addIQHandler(VCard.class, new AbstractIQHandler(IQ.Type.GET) { @Override protected IQ processRequest(IQ iq) { - return iq.createResult(vCard); + if (iq.getTo().equals(xmpp.getJid()) || iq.getTo().asBareJid().equals(xmpp.getJid().asBareJid()) + || iq.getTo().asBareJid().toEscapedString().equals(xmpp.getJid().getDomain())) { + return iq.createResult(vCard); + } + User user = xmpp.userService.getUserByName(iq.getTo().getLocal()); + if (user.getUid() > 0) { + UserInfo info = xmpp.userService.getUserInfo(user); + VCard userVCard = new VCard(); + userVCard.setFormattedName(info.getFullName()); + userVCard.setNickname(user.getName()); + try { + userVCard.setPhoto(new VCard.Image(new URI("http://i.juick.com/a/" + user.getUid() + ".png"))); + if (info.getUrl() != null) { + userVCard.setUrl(new URL(info.getUrl())); + } + } catch (MalformedURLException | URISyntaxException e) { + logger.warn("url exception", e); + } + return iq.createResult(userVCard); + } + return iq.createError(Condition.BAD_REQUEST); } }); router.addInboundMessageListener(e -> { -- cgit v1.2.3