Search in sources :

Example 6 with Avatar

use of net.sf.kraken.avatars.Avatar in project Openfire by igniterealtime.

the class XMPPSession method constructCurrentLegacyPresencePacket.

/**
     * Returns a (legacy/Smack-based) Presence stanza that represents the
     * current presence of this session. The Presence includes relevant Mode,
     * Status and VCardUpdate information.
     * 
     * This method uses the fields {@link TransportSession#presence} and
     * {@link TransportSession#verboseStatus} to generate the result.
     * 
     * @return A Presence packet representing the current presence state of this
     *         session.
     */
public Presence constructCurrentLegacyPresencePacket() {
    final org.jivesoftware.smack.packet.Presence presence = new org.jivesoftware.smack.packet.Presence(org.jivesoftware.smack.packet.Presence.Type.available);
    final Presence.Mode pMode = ((XMPPTransport) getTransport()).convertGatewayStatusToXMPP(this.presence);
    if (pMode != null) {
        presence.setMode(pMode);
    }
    if (verboseStatus != null && verboseStatus.trim().length() > 0) {
        presence.setStatus(verboseStatus);
    }
    final Avatar avatar = getAvatar();
    if (avatar != null) {
        final VCardUpdateExtension ext = new VCardUpdateExtension();
        ext.setPhotoHash(avatar.getLegacyIdentifier());
        presence.addExtension(ext);
    }
    return presence;
}
Also used : Presence(org.jivesoftware.smack.packet.Presence) VCardUpdateExtension(net.sf.kraken.protocols.xmpp.packet.VCardUpdateExtension) org.jivesoftware.smack(org.jivesoftware.smack) Presence(org.jivesoftware.smack.packet.Presence) Avatar(net.sf.kraken.avatars.Avatar)

Example 7 with Avatar

use of net.sf.kraken.avatars.Avatar in project Openfire by igniterealtime.

the class XMPPPresenceHandler method handlePresenceMode.

/**
	 * Handles incoming presence stanzas that relate to presence status / mode
	 * changes. Ignores others.
	 * 
	 * @param presence
	 *            the stanza
	 */
private void handlePresenceMode(final org.jivesoftware.smack.packet.Presence presence) {
    if (!session.getBuddyManager().isActivated()) {
        session.getBuddyManager().storePendingStatus(session.getTransport().convertIDToJID(presence.getFrom()), ((XMPPTransport) session.getTransport()).convertXMPPStatusToGateway(presence.getType(), presence.getMode()), presence.getStatus());
    } else {
        // TODO: Need to handle resources and priorities!
        try {
            final XMPPBuddy xmppBuddy = session.getBuddyManager().getBuddy(session.getTransport().convertIDToJID(presence.getFrom()));
            Log.debug("XMPP: Presence changed detected type " + presence.getType() + " and mode " + presence.getMode() + " for " + presence.getFrom());
            xmppBuddy.setPresenceAndStatus(((XMPPTransport) session.getTransport()).convertXMPPStatusToGateway(presence.getType(), presence.getMode()), presence.getStatus());
            if (JiveGlobals.getBooleanProperty("plugin.gateway." + session.getTransport().getType() + ".avatars", true)) {
                PacketExtension pe = presence.getExtension("x", NameSpace.VCARD_TEMP_X_UPDATE);
                if (pe != null) {
                    DefaultPacketExtension dpe = (DefaultPacketExtension) pe;
                    String hash = dpe.getValue("photo");
                    final String from = presence.getFrom();
                    if (hash != null) {
                        Avatar curAvatar = xmppBuddy.getAvatar();
                        if (curAvatar == null || !curAvatar.getLegacyIdentifier().equals(hash)) {
                            new Thread() {

                                @Override
                                public void run() {
                                    VCard vcard = new VCard();
                                    try {
                                        vcard.load(session.conn, from);
                                        xmppBuddy.setAvatar(new Avatar(xmppBuddy.getJID(), from, vcard.getAvatar()));
                                    } catch (XMPPException e) {
                                        Log.debug("XMPP: Failed to load XMPP avatar: ", e);
                                    } catch (IllegalArgumentException e) {
                                        Log.debug("XMPP: Got null avatar, ignoring.");
                                    }
                                }
                            }.start();
                        }
                    }
                }
            }
        } catch (NotFoundException e) {
            Log.debug("XMPP: Received presence notification for contact that's not in the buddy manager of user " + session.getJID() + ". GTalk is known to do this occasionally: " + presence.getFrom());
        // We cannot add this buddy to the buddy manager, as that would result into an auto-accept of the contact sending the data.
        }
    }
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) NotFoundException(org.jivesoftware.util.NotFoundException) XMPPException(org.jivesoftware.smack.XMPPException) VCard(org.jivesoftware.smackx.packet.VCard) Avatar(net.sf.kraken.avatars.Avatar)

Example 8 with Avatar

use of net.sf.kraken.avatars.Avatar in project Openfire by igniterealtime.

the class MSNListener method contactStatusChanged.

/**
     * A friend for this user has changed status.
     */
public void contactStatusChanged(MsnMessenger messenger, MsnContact friend) {
    if (!friend.isInList(MsnList.FL) || friend.getEmail() == null) {
        // Not in our buddy list, don't care, or null email address.  We need that.
        return;
    }
    if (getSession().getBuddyManager().isActivated()) {
        try {
            final MSNBuddy buddy = getSession().getBuddyManager().getBuddy(getSession().getTransport().convertIDToJID(friend.getEmail().toString()));
            buddy.setPresenceAndStatus(((MSNTransport) getSession().getTransport()).convertMSNStatusToXMPP(friend.getStatus()), friend.getPersonalMessage());
            buddy.setMsnContact(friend);
            if (JiveGlobals.getBooleanProperty("plugin.gateway.msn.avatars", true)) {
                final MsnObject msnAvatar = friend.getAvatar();
                if (msnAvatar != null && (buddy.getAvatar() == null || !buddy.getAvatar().getLegacyIdentifier().equals(msnAvatar.getSha1c()))) {
                    try {
                        messenger.retrieveDisplayPicture(msnAvatar, new DisplayPictureListener() {

                            public void notifyMsnObjectRetrieval(MsnMessenger messenger, DisplayPictureRetrieveWorker worker, MsnObject msnObject, ResultStatus result, byte[] resultBytes, Object context) {
                                Log.debug("MSN: Got avatar retrieval result: " + result);
                                // Check for the value
                                if (result == ResultStatus.GOOD) {
                                    try {
                                        Log.debug("MSN: Found avatar of length " + resultBytes.length);
                                        Avatar avatar = new Avatar(buddy.getJID(), msnAvatar.getSha1c(), resultBytes);
                                        buddy.setAvatar(avatar);
                                    } catch (IllegalArgumentException e) {
                                        Log.debug("MSN: Got null avatar, ignoring.");
                                    }
                                }
                            }
                        });
                    } catch (Exception e) {
                        Log.debug("MSN: Unable to retrieve MSN avatar: ", e);
                    }
                } else if (buddy.getAvatar() != null && msnAvatar == null) {
                    buddy.setAvatar(null);
                }
            }
        } catch (NotFoundException e) {
            // Not in our contact list.  Ignore.
            Log.debug("MSN: Received presense notification for contact we don't care about: " + friend.getEmail().toString());
        }
    } else {
        getSession().getBuddyManager().storePendingStatus(getSession().getTransport().convertIDToJID(friend.getEmail().toString()), ((MSNTransport) getSession().getTransport()).convertMSNStatusToXMPP(friend.getStatus()), friend.getPersonalMessage());
    }
}
Also used : MsnObject(net.sf.jml.MsnObject) MsnMessenger(net.sf.jml.MsnMessenger) NotFoundException(org.jivesoftware.util.NotFoundException) MsnObject(net.sf.jml.MsnObject) DisplayPictureRetrieveWorker(net.sf.jml.message.p2p.DisplayPictureRetrieveWorker) Avatar(net.sf.kraken.avatars.Avatar) UnknownMessageException(net.sf.jml.exception.UnknownMessageException) MsgNotSendException(net.sf.jml.exception.MsgNotSendException) IncorrectPasswordException(net.sf.jml.exception.IncorrectPasswordException) NotFoundException(org.jivesoftware.util.NotFoundException) UnsupportedProtocolException(net.sf.jml.exception.UnsupportedProtocolException) IOException(java.io.IOException) MsnProtocolException(net.sf.jml.exception.MsnProtocolException) LoginException(net.sf.jml.exception.LoginException) DisplayPictureListener(net.sf.jml.DisplayPictureListener)

Aggregations

Avatar (net.sf.kraken.avatars.Avatar)8 NotFoundException (org.jivesoftware.util.NotFoundException)7 MessageDigest (java.security.MessageDigest)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)3 IOException (java.io.IOException)2 DisplayPictureListener (net.sf.jml.DisplayPictureListener)2 MsnMessenger (net.sf.jml.MsnMessenger)2 VCardUpdateExtension (net.sf.kraken.protocols.xmpp.packet.VCardUpdateExtension)2 org.jivesoftware.smack (org.jivesoftware.smack)2 Presence (org.jivesoftware.smack.packet.Presence)2 VCard (org.jivesoftware.smackx.packet.VCard)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 List (java.util.List)1 ByteBlock (net.kano.joscar.ByteBlock)1 SnacCommand (net.kano.joscar.flapcmd.SnacCommand)1 SnacRequestAdapter (net.kano.joscar.snac.SnacRequestAdapter)1 SnacRequestTimeoutEvent (net.kano.joscar.snac.SnacRequestTimeoutEvent)1 SnacResponseEvent (net.kano.joscar.snac.SnacResponseEvent)1 ExtraInfoBlock (net.kano.joscar.snaccmd.ExtraInfoBlock)1