aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-02-13 22:29:32 +0300
committerGravatar Vitaly Takmazov2017-02-13 23:58:25 +0300
commitb3ac09ede10854dd277989d7296416c34916eeb1 (patch)
tree1ad6fefb4b776111f9089c6a212d471489ccc1f7
parent150736c9874f7433b3b08a219635b43ed5b79a04 (diff)
juick-xmpp: handle user vcards
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/XMPPConnection.java25
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 -> {