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();
}
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());
}
}
}
}
Aggregations