Commit 1a150de5 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[GATE-49] Work done on retrieval of ICQ nicknames.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@7182 b35dd754-fafc-0310-a699-88a17e54d16e
parent 8ada8bb6
......@@ -21,6 +21,7 @@ import net.kano.joscar.snaccmd.*;
import net.kano.joscar.snaccmd.icq.OfflineMsgIcqCmd;
import net.kano.joscar.snaccmd.icq.OfflineMsgDoneCmd;
import net.kano.joscar.snaccmd.icq.OfflineMsgIcqAckCmd;
import net.kano.joscar.snaccmd.icq.MetaShortInfoCmd;
import net.kano.joscar.snaccmd.conn.*;
import net.kano.joscar.snaccmd.icbm.*;
import net.kano.joscar.snaccmd.loc.*;
......@@ -151,5 +152,10 @@ public class BOSConnection extends BasicFlapConnection {
else if (cmd instanceof OfflineMsgDoneCmd) {
request(new OfflineMsgIcqAckCmd(oscarSession.getUIN(), (int)oscarSession.nextIcqId()));
}
else if (cmd instanceof MetaShortInfoCmd) {
MetaShortInfoCmd msic = (MetaShortInfoCmd)cmd;
Log.debug("RECEIVED META SHORT INFO: "+msic);
oscarSession.updateRosterNickname(String.valueOf(msic.getUIN()), msic.getNickname());
}
}
}
......@@ -30,6 +30,7 @@ import net.kano.joscar.snaccmd.loc.SetInfoCmd;
import net.kano.joscar.snaccmd.InfoData;
import net.kano.joscar.snaccmd.CapabilityBlock;
import net.kano.joscar.snaccmd.icq.OfflineMsgIcqRequest;
import net.kano.joscar.snaccmd.icq.MetaShortInfoRequest;
import net.kano.joscar.ssiitem.BuddyItem;
import net.kano.joscar.ssiitem.GroupItem;
import org.jivesoftware.util.Log;
......@@ -471,7 +472,20 @@ public class OSCARSession extends TransportSession {
if (nickname == null) {
nickname = buddy.getScreenname();
}
try {
Integer buddyUIN = Integer.parseInt(buddy.getScreenname());
if (nickname.equalsIgnoreCase(buddy.getScreenname())) {
Log.debug("REQUESTING SHORT INFO FOR "+buddy.getScreenname());
request(new MetaShortInfoRequest(getUIN(), (int)nextIcqId(), buddyUIN));
}
}
catch (NumberFormatException e) {
// Not an ICQ number then ;D
}
if (nickname == null) {
nickname = buddy.getScreenname();
}
int groupid = buddy.getGroupId();
String groupname = null;
if (groupid != 0 && groups.containsKey(groupid)) {
......@@ -549,8 +563,17 @@ public class OSCARSession extends TransportSession {
}
}
/**
* Retrieves the next ICQ id number and increments the counter.
* @return The next ICQ id number.
*/
public long nextIcqId() { return icqSeqNum.next(); }
/**
* Retrieves a UIN in integer format for the session.
*
* @return The UIN in integer format.
*/
public int getUIN() {
try {
return Integer.parseInt(getRegistration().getUsername());
......@@ -560,4 +583,29 @@ public class OSCARSession extends TransportSession {
}
}
/**
* Updates roster nickname information about a contact.
*
* @param sn Screenname/UIN of contact
* @param nickname New nickname
*/
public void updateRosterNickname(String sn, String nickname) {
BuddyItem buddy = buddies.get(sn);
if (buddy == null) { return; }
int groupid = buddy.getGroupId();
String groupname = null;
if (groupid != 0 && groups.containsKey(groupid)) {
String newgroupname = groups.get(groupid).getGroupName();
if (newgroupname.length() > 0) {
groupname = newgroupname;
}
}
try {
getTransport().addOrUpdateRosterItem(getJID(), getTransport().convertIDToJID(sn), nickname, groupname);
}
catch (UserNotFoundException e) {
Log.error("Contact not found while updating nickname.");
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment