Search in sources :

Example 1 with MsnMessenger

use of net.sf.jml.MsnMessenger in project Openfire by igniterealtime.

the class MSNListener method contactListInitCompleted.

/**
     * Contact list initialization has completed.
     */
public void contactListInitCompleted(MsnMessenger messenger) {
    for (MsnGroup msnGroup : messenger.getContactList().getGroups()) {
        Log.debug("MSN: Got group " + msnGroup);
        getSession().storeGroup(msnGroup);
    }
    for (MsnContact msnContact : messenger.getContactList().getContacts()) {
        Log.debug("MSN: Got contact " + msnContact);
        if (msnContact.isInList(MsnList.FL) && msnContact.getEmail() != null) {
            final MSNBuddy buddy = new MSNBuddy(getSession().getBuddyManager(), msnContact);
            getSession().getBuddyManager().storeBuddy(buddy);
            if (JiveGlobals.getBooleanProperty("plugin.gateway.msn.avatars", true)) {
                final MsnObject msnAvatar = msnContact.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);
                }
            }
        }
    }
    getSession().syncUsers();
}
Also used : MsnObject(net.sf.jml.MsnObject) DisplayPictureRetrieveWorker(net.sf.jml.message.p2p.DisplayPictureRetrieveWorker) MsnGroup(net.sf.jml.MsnGroup) 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) MsnMessenger(net.sf.jml.MsnMessenger) MsnObject(net.sf.jml.MsnObject) MsnContact(net.sf.jml.MsnContact)

Example 2 with MsnMessenger

use of net.sf.jml.MsnMessenger 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

IOException (java.io.IOException)2 DisplayPictureListener (net.sf.jml.DisplayPictureListener)2 MsnMessenger (net.sf.jml.MsnMessenger)2 MsnObject (net.sf.jml.MsnObject)2 IncorrectPasswordException (net.sf.jml.exception.IncorrectPasswordException)2 LoginException (net.sf.jml.exception.LoginException)2 MsgNotSendException (net.sf.jml.exception.MsgNotSendException)2 MsnProtocolException (net.sf.jml.exception.MsnProtocolException)2 UnknownMessageException (net.sf.jml.exception.UnknownMessageException)2 UnsupportedProtocolException (net.sf.jml.exception.UnsupportedProtocolException)2 DisplayPictureRetrieveWorker (net.sf.jml.message.p2p.DisplayPictureRetrieveWorker)2 Avatar (net.sf.kraken.avatars.Avatar)2 NotFoundException (org.jivesoftware.util.NotFoundException)2 MsnContact (net.sf.jml.MsnContact)1 MsnGroup (net.sf.jml.MsnGroup)1