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

[GATE-3] Big improvements in handling of adding/removing legacy contacts. ...

[GATE-3] Big improvements in handling of adding/removing legacy contacts.  Still a bunch more things that need to be done though.  Getting there.  [love the slew of new handlers gato!]

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5215 b35dd754-fafc-0310-a699-88a17e54d16e
parent ec358a61
...@@ -308,11 +308,13 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -308,11 +308,13 @@ public abstract class BaseTransport implements Component, RosterEventListener {
} }
else if (packet.getType() == Presence.Type.subscribe) { else if (packet.getType() == Presence.Type.subscribe) {
// User wants to add someone to their legacy roster. // User wants to add someone to their legacy roster.
session.addContact(packet.getTo()); // TODO: experimenting with doing this a different way
//session.addContact(packet.getTo());
} }
else if (packet.getType() == Presence.Type.unsubscribe) { else if (packet.getType() == Presence.Type.unsubscribe) {
// User wants to remove someone from their legacy roster. // User wants to remove someone from their legacy roster.
session.removeContact(packet.getTo()); // TODO: experimenting with doing this a different way
//session.removeContact(packet.getTo());
} }
else { else {
// Anything else we will ignore for now. // Anything else we will ignore for now.
...@@ -1172,7 +1174,17 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -1172,7 +1174,17 @@ public abstract class BaseTransport implements Component, RosterEventListener {
* @see org.jivesoftware.wildfire.roster.RosterEventListener#contactUpdated(org.jivesoftware.wildfire.roster.Roster, org.jivesoftware.wildfire.roster.RosterItem) * @see org.jivesoftware.wildfire.roster.RosterEventListener#contactUpdated(org.jivesoftware.wildfire.roster.Roster, org.jivesoftware.wildfire.roster.RosterItem)
*/ */
public void contactUpdated(Roster roster, RosterItem item) { public void contactUpdated(Roster roster, RosterItem item) {
// TODO: do nothing for now if (!item.getJid().getDomain().equals(this.getJID().getDomain())) {
// Not ours, not our problem.
return;
}
try {
TransportSession session = sessionManager.getSession(roster.getUsername());
session.updateContact(item);
}
catch (NotFoundException e) {
// Well we just don't care then.
}
} }
/** /**
...@@ -1181,8 +1193,17 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -1181,8 +1193,17 @@ public abstract class BaseTransport implements Component, RosterEventListener {
* @see org.jivesoftware.wildfire.roster.RosterEventListener#contactAdded(org.jivesoftware.wildfire.roster.Roster, org.jivesoftware.wildfire.roster.RosterItem) * @see org.jivesoftware.wildfire.roster.RosterEventListener#contactAdded(org.jivesoftware.wildfire.roster.Roster, org.jivesoftware.wildfire.roster.RosterItem)
*/ */
public void contactAdded(Roster roster, RosterItem item) { public void contactAdded(Roster roster, RosterItem item) {
// Don't care if (!item.getJid().getDomain().equals(this.getJID().getDomain())) {
// TODO: Evaluate how we -could- use this.. like what if roster is edited not via xmpp client? // Not ours, not our problem.
return;
}
try {
TransportSession session = sessionManager.getSession(roster.getUsername());
session.addContact(item);
}
catch (NotFoundException e) {
// Well we just don't care then.
}
} }
/** /**
...@@ -1191,8 +1212,17 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -1191,8 +1212,17 @@ public abstract class BaseTransport implements Component, RosterEventListener {
* @see org.jivesoftware.wildfire.roster.RosterEventListener#contactDeleted(org.jivesoftware.wildfire.roster.Roster, org.jivesoftware.wildfire.roster.RosterItem) * @see org.jivesoftware.wildfire.roster.RosterEventListener#contactDeleted(org.jivesoftware.wildfire.roster.Roster, org.jivesoftware.wildfire.roster.RosterItem)
*/ */
public void contactDeleted(Roster roster, RosterItem item) { public void contactDeleted(Roster roster, RosterItem item) {
// Don't care if (!item.getJid().getDomain().equals(this.getJID().getDomain())) {
// TODO: Evaluate how we -could- use this.. like what if roster is edited not via xmpp client? // Not ours, not our problem.
return;
}
try {
TransportSession session = sessionManager.getSession(roster.getUsername());
session.removeContact(item);
}
catch (NotFoundException e) {
//
}
} }
/** /**
......
...@@ -12,6 +12,7 @@ package org.jivesoftware.wildfire.gateway; ...@@ -12,6 +12,7 @@ package org.jivesoftware.wildfire.gateway;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.jivesoftware.wildfire.user.UserNotFoundException; import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.wildfire.roster.RosterItem;
import java.util.TreeMap; import java.util.TreeMap;
...@@ -237,16 +238,23 @@ public abstract class TransportSession implements Runnable { ...@@ -237,16 +238,23 @@ public abstract class TransportSession implements Runnable {
/** /**
* Adds a legacy contact to the legacy service. * Adds a legacy contact to the legacy service.
* *
* @param jid JID associated with the legacy contact. * @param item Roster item associated with the legacy contact.
*/ */
public abstract void addContact(JID jid); public abstract void addContact(RosterItem item);
/** /**
* Removes a legacy contact from the legacy service. * Removes a legacy contact from the legacy service.
* *
* @param jid JID associated with the legacy contact. * @param item Roster item associated with the legacy contact.
*/ */
public abstract void removeContact(JID jid); public abstract void removeContact(RosterItem item);
/**
* Updates a legacy contact on the legacy service.
*
* @param item Roster item associated with the legacy contact.
*/
public abstract void updateContact(RosterItem item);
/** /**
* Sends an outgoing message through the legacy serivce. * Sends an outgoing message through the legacy serivce.
......
...@@ -14,6 +14,7 @@ import java.util.*; ...@@ -14,6 +14,7 @@ import java.util.*;
import org.jivesoftware.util.NotFoundException; import org.jivesoftware.util.NotFoundException;
import org.jivesoftware.wildfire.SessionManager; import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.user.UserNotFoundException; import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
...@@ -86,6 +87,21 @@ public class TransportSessionManager { ...@@ -86,6 +87,21 @@ public class TransportSessionManager {
return session; return session;
} }
/**
* retrieves the session instance for a given user.
*
* @param username Username of the instance to be retrieved.
* @throws NotFoundException if the given username is not found.
* @return TransportSession instance requested.
*/
public TransportSession getSession(String username) throws NotFoundException {
TransportSession session = activeSessions.get(XMPPServer.getInstance().createJID(username, null));
if (session == null) {
throw new NotFoundException("Could not find session requested.");
}
return session;
}
/** /**
* Stores a new session instance with the legacy service. * Stores a new session instance with the legacy service.
* *
......
...@@ -17,6 +17,7 @@ import org.jivesoftware.wildfire.gateway.Registration; ...@@ -17,6 +17,7 @@ import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession; import org.jivesoftware.wildfire.gateway.TransportSession;
import org.jivesoftware.wildfire.gateway.TransportBuddy; import org.jivesoftware.wildfire.gateway.TransportBuddy;
import org.jivesoftware.wildfire.user.UserNotFoundException; import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.wildfire.roster.RosterItem;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
...@@ -158,19 +159,26 @@ public class MSNSession extends TransportSession { ...@@ -158,19 +159,26 @@ public class MSNSession extends TransportSession {
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#addContact(org.xmpp.packet.JID) * @see org.jivesoftware.wildfire.gateway.TransportSession#addContact(org.jivesoftware.wildfire.roster.RosterItem)
*/ */
public void addContact(JID jid) { public void addContact(RosterItem item) {
// @todo check jabber group and use it // @todo check jabber group and use it
msnMessenger.addFriend(Email.parseStr(getTransport().convertJIDToID(jid)), getTransport().convertJIDToID(jid)); msnMessenger.addFriend(Email.parseStr(getTransport().convertJIDToID(item.getJid())), getTransport().convertJIDToID(item.getJid()));
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#removeContact(org.xmpp.packet.JID) * @see org.jivesoftware.wildfire.gateway.TransportSession#removeContact(org.jivesoftware.wildfire.roster.RosterItem)
*/ */
public void removeContact(JID jid) { public void removeContact(RosterItem item) {
// @todo check jabber group and use it // @todo check jabber group and use it
msnMessenger.removeFriend(Email.parseStr(getTransport().convertJIDToID(jid)), false); msnMessenger.removeFriend(Email.parseStr(getTransport().convertJIDToID(item.getJid())), false);
}
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#updateContact(org.jivesoftware.wildfire.roster.RosterItem)
*/
public void updateContact(RosterItem item) {
// TODO: Implement this
} }
/** /**
......
...@@ -32,6 +32,7 @@ import org.jivesoftware.wildfire.gateway.Registration; ...@@ -32,6 +32,7 @@ import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportBuddy; import org.jivesoftware.wildfire.gateway.TransportBuddy;
import org.jivesoftware.wildfire.gateway.TransportSession; import org.jivesoftware.wildfire.gateway.TransportSession;
import org.jivesoftware.wildfire.user.UserNotFoundException; import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.wildfire.roster.RosterItem;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
...@@ -111,9 +112,9 @@ public class OSCARSession extends TransportSession { ...@@ -111,9 +112,9 @@ public class OSCARSession extends TransportSession {
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#addContact(org.xmpp.packet.JID) * @see org.jivesoftware.wildfire.gateway.TransportSession#addContact(org.jivesoftware.wildfire.roster.RosterItem)
*/ */
public void addContact(JID jid) { public void addContact(RosterItem item) {
Integer groupId = -1; Integer groupId = -1;
for (GroupItem g : groups.values()) { for (GroupItem g : groups.values()) {
...@@ -137,23 +138,30 @@ public class OSCARSession extends TransportSession { ...@@ -137,23 +138,30 @@ public class OSCARSession extends TransportSession {
} }
highestBuddyIdPerGroup.put(groupId, newBuddyId); highestBuddyIdPerGroup.put(groupId, newBuddyId);
BuddyItem newBuddy = new BuddyItem(getTransport().convertJIDToID(jid), newBuddyId, groupId); BuddyItem newBuddy = new BuddyItem(getTransport().convertJIDToID(item.getJid()), newBuddyId, groupId);
request(new CreateItemsCmd(new SsiItem[] { newBuddy.toSsiItem() })); request(new CreateItemsCmd(new SsiItem[] { newBuddy.toSsiItem() }));
buddies.put(groupId+"."+newBuddyId, newBuddy); buddies.put(groupId+"."+newBuddyId, newBuddy);
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#removeContact(org.xmpp.packet.JID) * @see org.jivesoftware.wildfire.gateway.TransportSession#removeContact(org.jivesoftware.wildfire.roster.RosterItem)
*/ */
public void removeContact(JID jid) { public void removeContact(RosterItem item) {
for (BuddyItem i : buddies.values()) { for (BuddyItem i : buddies.values()) {
if (i.getScreenname().equals(getTransport().convertJIDToID(jid))) { if (i.getScreenname().equals(getTransport().convertJIDToID(item.getJid()))) {
request(new DeleteItemsCmd(new SsiItem[] { i.toSsiItem() })); request(new DeleteItemsCmd(new SsiItem[] { i.toSsiItem() }));
buddies.remove(i.getGroupId()+"."+i.getId()); buddies.remove(i.getGroupId()+"."+i.getId());
} }
} }
} }
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#updateContact(org.jivesoftware.wildfire.roster.RosterItem)
*/
public void updateContact(RosterItem item) {
// TODO: Implement this
}
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#sendMessage(org.xmpp.packet.JID, String) * @see org.jivesoftware.wildfire.gateway.TransportSession#sendMessage(org.xmpp.packet.JID, String)
*/ */
......
...@@ -21,6 +21,7 @@ import org.jivesoftware.wildfire.gateway.Registration; ...@@ -21,6 +21,7 @@ import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportBuddy; import org.jivesoftware.wildfire.gateway.TransportBuddy;
import org.jivesoftware.wildfire.gateway.TransportSession; import org.jivesoftware.wildfire.gateway.TransportSession;
import org.jivesoftware.wildfire.user.UserNotFoundException; import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.wildfire.roster.RosterItem;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
import ymsg.network.LoginRefusedException; import ymsg.network.LoginRefusedException;
...@@ -191,31 +192,38 @@ public class YahooSession extends TransportSession { ...@@ -191,31 +192,38 @@ public class YahooSession extends TransportSession {
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#addContact(org.xmpp.packet.JID) * @see org.jivesoftware.wildfire.gateway.TransportSession#addContact(org.jivesoftware.wildfire.roster.RosterItem)
*/ */
public void addContact(JID jid) { public void addContact(RosterItem item) {
// @todo check jabber group and use it // @todo check jabber group and use it
try { try {
yahooSession.addFriend(jid.getNode(), "Yahoo Transport"); yahooSession.addFriend(item.getJid().getNode(), "Yahoo Transport");
} }
catch (IOException e) { catch (IOException e) {
Log.error("Failed to send message to yahoo user."); Log.error("Failed to add yahoo user.");
} }
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#removeContact(org.xmpp.packet.JID) * @see org.jivesoftware.wildfire.gateway.TransportSession#removeContact(org.jivesoftware.wildfire.roster.RosterItem)
*/ */
public void removeContact(JID jid) { public void removeContact(RosterItem item) {
// @todo check jabber group and use it // @todo check jabber group and use it
try { try {
yahooSession.removeFriend(jid.getNode(), "Yahoo Transport"); yahooSession.removeFriend(item.getJid().getNode(), "Yahoo Transport");
} }
catch (IOException e) { catch (IOException e) {
Log.error("Failed to send message to yahoo user."); Log.error("Failed to remove yahoo user.");
} }
} }
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#updateContact(org.jivesoftware.wildfire.roster.RosterItem)
*/
public void updateContact(RosterItem item) {
// TODO: Do something here.
}
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#sendMessage(org.xmpp.packet.JID, String) * @see org.jivesoftware.wildfire.gateway.TransportSession#sendMessage(org.xmpp.packet.JID, String)
*/ */
......
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