public BuddyInfo _addBuddyIfNecessary(String buddyName) {
BuddyInfo buddyInfo = null;
if (_connected && _conn != null) {
Screenname buddy = new Screenname(buddyName);
BuddyInfoManager buddyInfoManager = _conn.getBuddyInfoManager();
buddyInfo = buddyInfoManager.getBuddyInfo(buddy);
boolean isOnBuddyList = false;
if (buddyInfo != null) {
isOnBuddyList = buddyInfo.isOnBuddyList();
}
if (!isOnBuddyList) {
SsiService ssiService = _conn.getSsiService();
MutableBuddyList buddyList = ssiService.getBuddyList();
List groups = buddyList.getGroups();
if (groups.size() == 0) {
buddyList.addGroup("Buddies");
groups = buddyList.getGroups();
}
MutableGroup group = (MutableGroup) groups.get(0);
group.addBuddy(buddyName);
for (int attempt = 0; attempt < 10 && !buddyInfo.isOnBuddyList(); attempt++) {
try {
Thread.sleep(100);
}
catch (Throwable t) {
// ignore
}
buddyInfo = buddyInfoManager.getBuddyInfo(buddy);
}
}
}
return buddyInfo;
}