Search in sources :

Example 1 with MsnGroup

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

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

the class MSNSession method syncContactGroups.

/**
     * Given a legacy contact and a list of groups, makes sure that the list is in sync with
     * the actual group list.
     *
     * @param contact Email address of contact.
     * @param groups List of groups contact should be in.
     */
public void syncContactGroups(Email contact, List<String> groups) {
    MsnContact msnContact = null;
    try {
        MSNBuddy msnBuddy = getBuddyManager().getBuddy(getTransport().convertIDToJID(contact.getEmailAddress()));
        msnContact = msnBuddy.getMsnContact();
    } catch (NotFoundException e) {
        Log.debug("MSN: Buddy not found in buddy manager: " + contact.getEmailAddress());
    }
    if (msnContact == null) {
        return;
    }
    if (groups != null && !groups.isEmpty()) {
        // Create groups that do not currently exist.
        for (String group : groups) {
            if (!msnGroups.containsKey(group)) {
                Log.debug("MSN: Group " + group + " is a new group, creating.");
                msnMessenger.addGroup(group);
                // Ok, short circuit here, we need to wait for this group to be added.  We'll be back.
                storePendingGroup(group, contact);
                return;
            }
        }
        // Make sure contact belongs to groups that we want.
        for (String group : groups) {
            Log.debug("MSN: Found " + contact + " should belong to group " + group);
            MsnGroup msnGroup = msnGroups.get(group);
            if (msnGroup != null && !msnContact.belongGroup(msnGroup)) {
                Log.debug("MSN: " + contact + " does not belong to " + group + ", copying.");
                msnMessenger.copyFriend(contact, msnGroup.getGroupId());
            }
        }
        // Now we will clean up groups that we should no longer belong to.
        for (MsnGroup msnGroup : msnContact.getBelongGroups()) {
            Log.debug("MSN: Found " + contact + " belongs to group " + msnGroup.getGroupName());
            if (!groups.contains(msnGroup.getGroupName())) {
                Log.debug("MSN: " + contact + " should not belong to " + msnGroup.getGroupName() + ", removing.");
                msnMessenger.removeFriend(contact, msnGroup.getGroupId());
            }
        }
    }
}
Also used : NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) MsnContact(net.sf.jml.MsnContact) MsnGroup(net.sf.jml.MsnGroup)

Aggregations

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