use of net.kano.joscar.ssiitem.BuddyItem in project Openfire by igniterealtime.
the class OSCARBuddy method populateGroupList.
/**
* Runs through group id list, matching to finished collection of groups to get names.
*/
public void populateGroupList() {
List<String> groupList = new ArrayList<String>();
final SSIHierarchy ssi = ((OSCARSession) this.getManager().getSession()).getSsiHierarchy();
for (BuddyItem buddyItem : buddyItems.values()) {
try {
// resolve the group name that matches the ID in the buddy item.
final int groupID = buddyItem.getGroupId();
final String groupName = ssi.getGroupName(groupID);
groupList.add(groupName);
} catch (Exception e) {
// Hrm, unknown group. Don't include.
}
}
setGroups(groupList);
}
use of net.kano.joscar.ssiitem.BuddyItem in project Openfire by igniterealtime.
the class SSIHierarchy method syncContactGroupsAndNickname.
/**
* Synchronizes the basic characteristics of one contact, including:
* <ul>
* <li>the list of groups a contact is a member of</li>
* <li>nicknames</li>
* </ul>
*
* As an OSCAR contact must be in at least one group, a default group is
* used if the provided group list is empty or <tt>null</tt>.
*
* @param contact
* Screen name/UIN of the contact.
* @param nickname
* Nickname of the contact (should not be <tt>null</tt>)
* @param grouplist
* List of groups the contact should be a member of.
* @see SSIHierarchy#getDefaultGroup()
*/
public void syncContactGroupsAndNickname(String contact, String nickname, List<String> grouplist) {
if (grouplist == null) {
grouplist = new ArrayList<String>();
}
if (grouplist.isEmpty()) {
Log.debug("No groups provided for the sync of contact " + contact + ". Using default group.");
grouplist.add(getDefaultGroup());
}
Log.debug("Syncing contact = " + contact + ", nickname = " + nickname + ", grouplist = " + grouplist);
OSCARBuddy oscarBuddy = null;
try {
final JID jid = parent.getTransport().convertIDToJID(contact);
oscarBuddy = parent.getBuddyManager().getBuddy(jid);
Log.debug("Found related oscarbuddy: " + oscarBuddy);
} catch (NotFoundException e) {
Log.debug("Didn't find related oscarbuddy. One will be created.");
}
//TODO: Should we do a premodcmd here and postmodcmd at the end and not have separate ones?
// Stored 'removed' list of buddy items for later use
final List<BuddyItem> freeBuddyItems = new ArrayList<BuddyItem>();
// We'll keep the buddy items around for potential modification instead of deletion.
if (oscarBuddy != null) {
for (BuddyItem buddy : oscarBuddy.getBuddyItems()) {
// if (buddy.getScreenname().equalsIgnoreCase(contact)) {
if (!groups.containsKey(buddy.getGroupId())) {
// Well this is odd, a group we don't know about? Nuke it.
Log.debug("Removing " + buddy + " because of unknown group");
freeBuddyItems.add(buddy);
// request(new DeleteItemsCmd(buddy.toSsiItem()));
// oscarBuddy.removeBuddyItem(buddy.getGroupId(), true);
} else if (!grouplist.contains(groups.get(buddy.getGroupId()).getGroupName())) {
Log.debug("Removing " + buddy + " because not in list of groups");
freeBuddyItems.add(buddy);
// request(new DeleteItemsCmd(buddy.toSsiItem()));
// oscarBuddy.removeBuddyItem(buddy.getGroupId(), true);
} else {
// nothing to delete? lets update Aliases then.
if (buddy.getAlias() == null || !buddy.getAlias().equals(nickname)) {
Log.debug("Updating alias for " + buddy);
buddy.setAlias(nickname);
request(new PreModCmd());
request(new ModifyItemsCmd(buddy.toSsiItem()));
request(new PostModCmd());
updateHighestId(buddy);
oscarBuddy.tieBuddyItem(buddy, true);
}
}
// }
}
}
// Now, lets take the known good list of groups and add whatever is missing on the server.
for (String group : grouplist) {
Integer groupId = getGroupIdOrCreateNew(group);
if (isMemberOfGroup(groupId, contact)) {
// Already a member, moving on
continue;
}
Integer newBuddyId = 1;
if (highestBuddyIdPerGroup.containsKey(groupId)) {
newBuddyId = getNextBuddyId(groupId);
}
if (freeBuddyItems.size() > 0) {
// Moving a freed buddy item
// TODO: This isn't working.. why? Returns RESULT_ID_TAKEN
// BuddyItem buddy = freeBuddyItems.remove(0);
// if (oscarBuddy != null) {
// oscarBuddy.removeBuddyItem(buddy.getGroupId(), false);
// }
// buddy.setGroupid(groupId);
// buddy.setId(newBuddyId);
// buddy.setAlias(nickname);
// request(new ModifyItemsCmd(buddy.toSsiItem()));
// if (oscarBuddy == null) {
// oscarBuddy = new OSCARBuddy(getBuddyManager(), buddy);
// // TODO: translate this
// request(new BuddyAuthRequest(contact, "Automated add request on behalf of user."));
// }
// else {
// oscarBuddy.tieBuddyItem(buddy, false);
// }
request(new PreModCmd());
BuddyItem buddy = freeBuddyItems.remove(0);
BuddyItem newBuddy = new BuddyItem(buddy);
newBuddy.setGroupid(groupId);
newBuddy.setId(newBuddyId);
newBuddy.setAlias(nickname);
request(new DeleteItemsCmd(buddy.toSsiItem()));
if (oscarBuddy != null) {
oscarBuddy.removeBuddyItem(buddy.getGroupId(), false);
}
request(new CreateItemsCmd(newBuddy.toSsiItem()));
if (oscarBuddy == null) {
oscarBuddy = new OSCARBuddy(parent.getBuddyManager(), newBuddy);
// TODO: translate this
request(new BuddyAuthRequest(contact, "Automated add request on behalf of user."));
} else {
oscarBuddy.tieBuddyItem(newBuddy, false);
}
request(new PostModCmd());
} else {
// Creating a new buddy item
final BuddyItem newBuddy = new BuddyItem(contact, groupId, newBuddyId);
newBuddy.setAlias(nickname);
updateHighestId(newBuddy);
// TODO: Should we be doing this for AIM too?
if (parent.getTransport().getType().equals(TransportType.icq)) {
newBuddy.setAwaitingAuth(true);
}
request(new PreModCmd());
request(new CreateItemsCmd(newBuddy.toSsiItem()));
request(new PostModCmd());
if (oscarBuddy == null) {
oscarBuddy = new OSCARBuddy(parent.getBuddyManager(), newBuddy);
// TODO: translate this
request(new BuddyAuthRequest(contact, "Automated add request on behalf of user."));
} else {
oscarBuddy.tieBuddyItem(newBuddy, true);
}
}
}
// Now, lets remove any leftover buddy items that we're no longer using.
for (BuddyItem buddy : freeBuddyItems) {
request(new DeleteItemsCmd(buddy.toSsiItem()));
if (oscarBuddy != null) {
oscarBuddy.removeBuddyItem(buddy.getGroupId(), false);
}
}
// Lastly, lets store the final buddy item after we've modified it, making sure to update groups first.
if (oscarBuddy != null) {
// oscarBuddy.populateGroupList();
parent.getBuddyManager().storeBuddy(oscarBuddy);
}
}
use of net.kano.joscar.ssiitem.BuddyItem in project Openfire by igniterealtime.
the class BOSConnection method handleSnacResponse.
@Override
protected void handleSnacResponse(SnacResponseEvent e) {
super.handleSnacResponse(e);
// Log.debug("OSCAR bos snac response received: "+e);
SnacCommand cmd = e.getSnacCommand();
if (cmd instanceof LocRightsCmd) {
request(new SetInfoCmd(new InfoData("oscargateway", null, getMainSession().getCapabilities(), null)));
request(new MyInfoRequest());
} else if (cmd instanceof ParamInfoCmd) {
ParamInfoCmd pic = (ParamInfoCmd) cmd;
ParamInfo info = pic.getParamInfo();
request(new SetParamInfoCmd(new ParamInfo(0, info.getFlags() | ParamInfo.FLAG_TYPING_NOTIFICATION, 8000, info.getMaxSenderWarning(), info.getMaxReceiverWarning(), 0)));
} else if (cmd instanceof ServiceRedirect) {
ServiceRedirect sr = (ServiceRedirect) cmd;
getMainSession().connectToService(sr.getSnacFamily(), sr.getRedirectHost(), sr.getCookie());
} else if (cmd instanceof SsiDataCmd) {
SsiDataCmd sdc = (SsiDataCmd) cmd;
List<SsiItem> items = sdc.getItems();
for (SsiItem item : items) {
SsiItemObj obj = itemFactory.getItemObj(item);
if (obj instanceof BuddyItem) {
BuddyItem bi = (BuddyItem) obj;
Log.debug("OSCAR: got buddy item " + bi);
getMainSession().getSsiHierarchy().gotBuddy(bi);
} else if (obj instanceof GroupItem) {
GroupItem gi = (GroupItem) obj;
Log.debug("OSCAR: got group item " + gi);
getMainSession().getSsiHierarchy().gotGroup(gi);
} else if (obj instanceof IconItem) {
IconItem ii = (IconItem) obj;
Log.debug("OSCAR: got icon item " + ii);
getMainSession().getSsiHierarchy().gotIconItem(ii);
} else if (obj instanceof VisibilityItem) {
VisibilityItem vi = (VisibilityItem) obj;
Log.debug("OSCAR: got visibility item " + vi);
getMainSession().getSsiHierarchy().gotVisibilityItem(vi);
} else {
Log.debug("OSCAR: got item we're not handling " + obj);
}
}
if (sdc.getLastModDate() != 0) {
request(new ActivateSsiCmd());
clientReady();
getMainSession().setLoginStatus(TransportLoginStatus.LOGGED_IN);
getMainSession().gotCompleteSSI();
}
} else if (cmd instanceof OfflineMsgIcqCmd) {
OfflineMsgIcqCmd omic = (OfflineMsgIcqCmd) cmd;
String sn = String.valueOf(omic.getFromUIN());
Date whenSent = omic.getDate();
ByteBlock block = omic.getIcqData();
final int len = LEBinaryTools.getUShort(block, 12) - 1;
String msg = OscarTools.getString(block.subBlock(14, len), null);
msg = StringUtils.unescapeFromXML(OscarTools.stripHtml(msg));
// TODO: Translate offline message note
getMainSession().getTransport().sendOfflineMessage(getMainSession().getJID(), getMainSession().getTransport().convertIDToJID(sn), msg, whenSent, "Offline Message");
} else if (cmd instanceof OfflineMsgDoneCmd) {
request(new OfflineMsgIcqAckCmd(getMainSession().getUIN(), (int) getMainSession().nextIcqId()));
} else if (cmd instanceof MetaShortInfoCmd) {
// MetaShortInfoCmd msic = (MetaShortInfoCmd)cmd;
// Log.debug("RECEIVED META SHORT INFO: "+msic);
// getMainSession().updateRosterNickname(String.valueOf(msic.getUIN()), msic.getNickname());
} else if (cmd instanceof AuthReplyCmd) {
AuthReplyCmd ar = (AuthReplyCmd) cmd;
if (ar.isAccepted()) {
Presence p = new Presence();
p.setType(Presence.Type.subscribed);
p.setTo(getMainSession().getJID());
p.setFrom(getMainSession().getTransport().convertIDToJID(ar.getSender()));
getMainSession().getTransport().sendPacket(p);
} else {
Presence p = new Presence();
p.setType(Presence.Type.unsubscribed);
p.setTo(getMainSession().getJID());
p.setFrom(getMainSession().getTransport().convertIDToJID(ar.getSender()));
getMainSession().getTransport().sendPacket(p);
}
} else if (cmd instanceof AuthFutureCmd) {
AuthFutureCmd af = (AuthFutureCmd) cmd;
Presence p = new Presence();
p.setType(Presence.Type.subscribe);
p.setTo(getMainSession().getJID());
p.setFrom(getMainSession().getTransport().convertIDToJID(af.getUin()));
getMainSession().getTransport().sendPacket(p);
} else if (cmd instanceof SnacError) {
SnacError se = (SnacError) cmd;
if (se.getErrorCode() == SnacError.CODE_REFUSED_BY_CLIENT) {
getMainSession().getTransport().sendMessage(getMainSession().getJID(), getMainSession().getTransport().getJID(), LocaleUtils.getLocalizedString("gateway.aim.msgrefused", "kraken"));
}
//TODO: Tons more errors that can be caught. Gotta catch 'em all! =) (please don't sue me Nintendo)
}
}
use of net.kano.joscar.ssiitem.BuddyItem in project Openfire by igniterealtime.
the class BOSConnection method handleSnacPacket.
@Override
protected void handleSnacPacket(SnacPacketEvent e) {
// Log.debug("OSCAR bos snac packet received: "+e);
super.handleSnacPacket(e);
SnacCommand cmd = e.getSnacCommand();
if (cmd instanceof ServerReadyCmd) {
request(new ParamInfoRequest());
request(new LocRightsRequest());
request(new SsiRightsRequest());
request(new SsiDataRequest());
} else if (cmd instanceof BuddyAddedYouCmd) {
BuddyAddedYouCmd bay = (BuddyAddedYouCmd) cmd;
Presence p = new Presence();
p.setType(Presence.Type.subscribe);
p.setTo(getMainSession().getJID());
p.setFrom(getMainSession().getTransport().convertIDToJID(bay.getUin()));
getMainSession().getTransport().sendPacket(p);
} else if (cmd instanceof BuddyAuthRequest) {
BuddyAuthRequest bar = (BuddyAuthRequest) cmd;
Presence p = new Presence();
p.setType(Presence.Type.subscribe);
p.setTo(getMainSession().getJID());
p.setFrom(getMainSession().getTransport().convertIDToJID(bar.getScreenname()));
getMainSession().getTransport().sendPacket(p);
// Auto-accept auth request. (for now)
// TODO: Evaluate handling this in a non-automated fashion.
request(new AuthReplyCmd(bar.getScreenname(), null, true));
} else if (cmd instanceof AuthReplyCmd) {
AuthReplyCmd ar = (AuthReplyCmd) cmd;
if (ar.isAccepted()) {
Presence p = new Presence();
p.setType(Presence.Type.subscribed);
p.setTo(getMainSession().getJID());
p.setFrom(getMainSession().getTransport().convertIDToJID(ar.getSender()));
getMainSession().getTransport().sendPacket(p);
} else {
Presence p = new Presence();
p.setType(Presence.Type.unsubscribed);
p.setTo(getMainSession().getJID());
p.setFrom(getMainSession().getTransport().convertIDToJID(ar.getSender()));
getMainSession().getTransport().sendPacket(p);
}
} else if (cmd instanceof ModifyItemsCmd) {
ModifyItemsCmd mic = (ModifyItemsCmd) cmd;
List<SsiItem> items = mic.getItems();
for (SsiItem item : items) {
SsiItemObj obj = itemFactory.getItemObj(item);
if (obj instanceof BuddyItem) {
BuddyItem bi = (BuddyItem) obj;
Log.debug("AIM got buddy item " + bi);
getMainSession().getSsiHierarchy().gotBuddy(bi);
} else if (obj instanceof GroupItem) {
GroupItem gi = (GroupItem) obj;
Log.debug("AIM got group item " + gi);
getMainSession().getSsiHierarchy().gotGroup(gi);
}
}
}
}
use of net.kano.joscar.ssiitem.BuddyItem in project Openfire by igniterealtime.
the class OSCARSession method gotCompleteSSI.
/**
* Apparently we now have the entire list, lets sync.
*/
void gotCompleteSSI() {
ArrayList<Integer> nicknameRequests = new ArrayList<Integer>();
TransportBuddyManager<OSCARBuddy> manager = getBuddyManager();
for (OSCARBuddy buddy : manager.getBuddies()) {
String nickname = buddy.getNickname();
buddy.populateGroupList();
for (BuddyItem buddyItem : buddy.getBuddyItems()) {
if (buddyItem.isAwaitingAuth()) {
buddy.setAskType(RosterItem.ASK_SUBSCRIBE);
buddy.setSubType(RosterItem.SUB_NONE);
}
try {
if (nickname.equalsIgnoreCase(buddyItem.getScreenname())) {
Integer buddyUIN = Integer.parseInt(buddyItem.getScreenname());
Log.debug("REQUESTING SHORT INFO FOR " + buddyUIN);
nicknameRequests.add(buddyUIN);
}
} catch (NumberFormatException e) {
// Not an ICQ number then ;D
}
}
}
try {
getTransport().syncLegacyRoster(getJID(), getBuddyManager().getBuddies());
} catch (UserNotFoundException e) {
Log.debug("Unable to sync oscar contact list for " + getJID(), e);
}
getBuddyManager().activate();
request(new SetInfoCmd(InfoData.forCapabilities(getCapabilities())));
// if (JiveGlobals.getBooleanProperty("plugin.gateway."+getTransport().getType()+".avatars", true) && getAvatar() != null) {
// if (storedIconInfo == null || !StringUtils.encodeHex(storedIconInfo.getIconInfo().getData().toByteArray()).equals(getAvatar().getLegacyIdentifier())) {
// try {
// updateLegacyAvatar(getAvatar().getMimeType(), Base64.decode(getAvatar().getImageData()));
// }
// catch (NotFoundException e) {
// // No avatar found, moving on
// }
// }
// }
updateStatus(getPresence(), getVerboseStatus());
ssiHierarchy.setVisibilityFlag(VisibilityItem.MASK_DISABLE_RECENT_BUDDIES);
if (getTransport().getType().equals(TransportType.icq)) {
request(new OfflineMsgIcqRequest(getUIN(), (int) nextIcqId()));
}
if (JiveGlobals.getBooleanProperty("plugin.gateway." + getTransport().getType() + ".mailnotifications", true)) {
request(new ServiceRequest(MailCheckCmd.FAMILY_MAILCHECK));
}
for (Integer uin : nicknameRequests) {
MetaShortInfoRequest req = new MetaShortInfoRequest(getUIN(), (int) nextIcqId(), uin);
Log.debug("Doing a MetaShortInfoRequest for " + uin + " as " + req);
request(req);
}
}
Aggregations