Commit a3879ced authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[GATE-91] Refactored yahoo roster handling a tad to take care of duplicate key issues.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@5957 b35dd754-fafc-0310-a699-88a17e54d16e
parent 6ca240d6
...@@ -856,7 +856,7 @@ public abstract class BaseTransport implements Component, RosterEventListener, P ...@@ -856,7 +856,7 @@ public abstract class BaseTransport implements Component, RosterEventListener, P
gwitem.setAskStatus(RosterItem.ASK_NONE); gwitem.setAskStatus(RosterItem.ASK_NONE);
changed = true; changed = true;
} }
// This could probably be simplified, for not I'm going with brute force logic. // This could probably be simplified, for now I'm going with brute force logic.
// gnickname is null, nickname is null, leave // gnickname is null, nickname is null, leave
// gnickname is not null, nickname is null, set gnickname to null // gnickname is not null, nickname is null, set gnickname to null
// gnickname is null, nickname is not null, set gnickname to nickname // gnickname is null, nickname is not null, set gnickname to nickname
...@@ -886,8 +886,6 @@ public abstract class BaseTransport implements Component, RosterEventListener, P ...@@ -886,8 +886,6 @@ public abstract class BaseTransport implements Component, RosterEventListener, P
// Create new roster item for the gateway service or legacy contact. Only // Create new roster item for the gateway service or legacy contact. Only
// roster items related to the gateway service will be persistent. Roster // roster items related to the gateway service will be persistent. Roster
// items of legacy users are never persisted in the DB. // items of legacy users are never persisted in the DB.
// RosterItem gwitem =
// roster.createRosterItem(contactjid, true, contactjid.getNode() == null);
RosterItem gwitem = RosterItem gwitem =
roster.createRosterItem(contactjid, true, false); roster.createRosterItem(contactjid, true, false);
gwitem.setSubStatus(RosterItem.SUB_BOTH); gwitem.setSubStatus(RosterItem.SUB_BOTH);
......
...@@ -170,21 +170,44 @@ public class YahooSession extends TransportSession { ...@@ -170,21 +170,44 @@ public class YahooSession extends TransportSession {
* Syncs up the yahoo roster with the jabber roster. * Syncs up the yahoo roster with the jabber roster.
*/ */
public void syncUsers() { public void syncUsers() {
List<TransportBuddy> legacyusers = new ArrayList<TransportBuddy>(); // First we need to get a good mapping of users to what groups they are in.
HashMap<String,ArrayList<String>> userToGroups = new HashMap<String,ArrayList<String>>();
for (YahooGroup group : yahooSession.getGroups()) { for (YahooGroup group : yahooSession.getGroups()) {
for (Enumeration e = group.getMembers().elements(); e.hasMoreElements();) { for (Enumeration e = group.getMembers().elements(); e.hasMoreElements();) {
YahooUser user = (YahooUser)e.nextElement(); YahooUser user = (YahooUser)e.nextElement();
PseudoRosterItem rosterItem = pseudoRoster.getItem(user.getId()); ArrayList<String> groups;
String nickname = null; if (userToGroups.containsKey(user.getId())) {
if (rosterItem != null) { groups = userToGroups.get(user.getId());
nickname = rosterItem.getNickname(); }
else {
groups = new ArrayList<String>();
} }
if (nickname == null) { if (!groups.contains(group.getName())) {
nickname = user.getId(); groups.add(group.getName());
} }
legacyusers.add(new TransportBuddy(user.getId(), nickname, group.getName())); userToGroups.put(user.getId(), groups);
}
}
// Now we will run through the entire list of users and set up our sync group.
List<TransportBuddy> legacyusers = new ArrayList<TransportBuddy>();
for (Object userObj : yahooSession.getUsers().values()) {
YahooUser user = (YahooUser)userObj;
PseudoRosterItem rosterItem = pseudoRoster.getItem(user.getId());
String nickname = null;
if (rosterItem != null) {
nickname = rosterItem.getNickname();
}
if (nickname == null) {
nickname = user.getId();
}
if (userToGroups.containsKey(user.getId())) {
legacyusers.add(new TransportBuddy(user.getId(), nickname, userToGroups.get(user.getId()).get(0)));
}
else {
legacyusers.add(new TransportBuddy(user.getId(), nickname, null));
} }
} }
// Lets try the actual sync.
try { try {
getTransport().syncLegacyRoster(getJID(), legacyusers); getTransport().syncLegacyRoster(getJID(), legacyusers);
} }
......
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