diff options
Diffstat (limited to 'juick-xmpp/src/main/java/com')
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/XMPPConnection.java | 25 |
1 files changed, 24 insertions, 1 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 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 -> { |