Commit 982afadb authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[JM-761] [JM-769] Some work done on roster integration. Needs to be better. ...

[JM-761] [JM-769] Some work done on roster integration.  Needs to be better.  Need to handle status.  Need to figure out if ymsg.support is really worth having.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4536 b35dd754-fafc-0310-a699-88a17e54d16e
parent 9300692a
......@@ -3,3 +3,4 @@ Name | Version
joscar.jar | 0.9.3 (patched)
picocontainer | 1.2.0
ymsg_network.jar | 0.61
ymsg_support.jar | 0.6
......@@ -447,37 +447,7 @@ public abstract class BaseTransport implements Component {
registrationManager.createRegistration(packet.getFrom(), this.transportType, username, password);
try {
Roster roster = rosterManager.getRoster(packet.getFrom().getNode());
try {
RosterItem gwitem = roster.getRosterItem(packet.getTo());
if (gwitem.getSubStatus() != RosterItem.SUB_BOTH) {
gwitem.setSubStatus(RosterItem.SUB_BOTH);
}
if (gwitem.getAskStatus() != RosterItem.ASK_NONE) {
gwitem.setAskStatus(RosterItem.ASK_NONE);
}
roster.updateRosterItem(gwitem);
}
catch (UserNotFoundException e) {
try {
RosterItem gwitem = roster.createRosterItem(packet.getTo(), true);
gwitem.setSubStatus(RosterItem.SUB_BOTH);
gwitem.setAskStatus(RosterItem.ASK_NONE);
roster.updateRosterItem(gwitem);
}
catch (UserAlreadyExistsException ee) {
Log.error("getRosterItem claims user exists, but couldn't find via getRosterItem?");
IQ eresult = IQ.createResultIQ(packet);
eresult.setError(Condition.bad_request);
reply.add(eresult);
}
catch (Exception ee) {
Log.error("createRosterItem caused exception: " + ee.getMessage());
IQ eresult = IQ.createResultIQ(packet);
eresult.setError(Condition.bad_request);
reply.add(eresult);
}
}
addOrUpdateRosterItem(packet.getFrom(), packet.getTo(), this.getDescription(), "Transports");
}
catch (UserNotFoundException e) {
Log.error("Someone attempted to register with the gateway who is not registered with the server: " + packet.getFrom());
......@@ -558,6 +528,133 @@ public abstract class BaseTransport implements Component {
return componentManager;
}
/**
* Either updates or adds a JID to a user's roster.
*
* @param userjid JID of user to have item added to their roster.
* @param contactjid JID to add to roster.
* @param nickname Nickname of item. (can be null)
* @param group Group item is to be placed in. (can be null)
* @throws UserNotFoundException if userjid not found.
*/
public void addOrUpdateRosterItem(JID userjid, JID contactjid, String nickname, String group) throws UserNotFoundException {
try {
Roster roster = rosterManager.getRoster(userjid.getNode());
try {
RosterItem gwitem = roster.getRosterItem(contactjid);
if (gwitem.getSubStatus() != RosterItem.SUB_BOTH) {
gwitem.setSubStatus(RosterItem.SUB_BOTH);
}
if (gwitem.getAskStatus() != RosterItem.ASK_NONE) {
gwitem.setAskStatus(RosterItem.ASK_NONE);
}
gwitem.setNickname(nickname);
List<String> groups = new ArrayList<String>();
groups.add(group);
try {
gwitem.setGroups(groups);
}
catch (Exception ee) {
// Oooookay, ignore then.
}
roster.updateRosterItem(gwitem);
}
catch (UserNotFoundException e) {
try {
RosterItem gwitem = roster.createRosterItem(contactjid, true);
gwitem.setSubStatus(RosterItem.SUB_BOTH);
gwitem.setAskStatus(RosterItem.ASK_NONE);
gwitem.setNickname(nickname);
List<String> groups = new ArrayList<String>();
groups.add(group);
try {
gwitem.setGroups(groups);
}
catch (Exception ee) {
// Oooookay, ignore then.
}
roster.updateRosterItem(gwitem);
}
catch (UserAlreadyExistsException ee) {
Log.error("getRosterItem claims user exists, but couldn't find via getRosterItem?");
// TODO: Should we throw exception or something?
}
catch (Exception ee) {
Log.error("createRosterItem caused exception: " + ee.getMessage());
// TODO: Should we throw exception or something?
}
}
}
catch (UserNotFoundException e) {
throw new UserNotFoundException("Could not find roster for " + userjid.toString());
}
}
/**
* Either updates or adds a contact to a user's roster.
*
* @param userjid JID of user to have item added to their roster.
* @param contactid String contact name, will be translated to JID.
* @param nickname Nickname of item. (can be null)
* @param group Group item is to be placed in. (can be null)
* @throws UserNotFoundException if userjid not found.
*/
public void addOrUpdateRosterItem(JID userjid, String contactid, String nickname, String group) throws UserNotFoundException {
try {
addOrUpdateRosterItem(userjid, new JID(contactid, this.jid.toBareJID(), null), nickname, group);
}
catch (UserNotFoundException e) {
// Pass it on down.
throw e;
}
}
/**
* Removes a roster item from a user's roster.
*
* @param userjid JID of user whose roster we will interact with.
* @param contactjid JID to be removed from roster.
* @throws UserNotFoundException if userjid not found.
*/
void removeFromRoster(JID userjid, JID contactjid) throws UserNotFoundException {
// Clean up the user's contact list.
try {
Roster roster = rosterManager.getRoster(userjid.getNode());
for (RosterItem ri : roster.getRosterItems()) {
if (ri.getJid() == contactjid) {
try {
roster.deleteRosterItem(ri.getJid(), false);
}
catch (Exception e) {
Log.error("Error removing roster item: " + ri.toString());
// TODO: Should we say something?
}
}
}
}
catch (UserNotFoundException e) {
throw new UserNotFoundException("Could not find roster for " + userjid.toString());
}
}
/**
* Removes a roster item from a user's roster based on a legacy contact.
*
* @param userjid JID of user whose roster we will interact with.
* @param contactid Contact to be removed, will be translated to JID.
* @throws UserNotFoundException if userjid not found.
*/
void removeFromRoster(JID userjid, String contactid) throws UserNotFoundException {
// Clean up the user's contact list.
try {
removeFromRoster(userjid, new JID(contactid, this.jid.toBareJID(), null));
}
catch (UserNotFoundException e) {
// Pass it on through.
throw e;
}
}
/**
* Sends a packet through the component manager as the component.
*
......
......@@ -24,6 +24,7 @@ import net.kano.joscar.ByteBlock;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
......@@ -207,6 +208,15 @@ public class OSCARSession extends TransportSession {
void gotBuddy(BuddyItem buddy) {
buddies.add(buddy);
String nickname = buddy.getAlias();
//String group = groups.get(buddy.getGroupId()).getGroupName();
try {
//getTransport().addOrUpdateRosterItem(getJID(), buddy.getScreenname(), nickname, group);
getTransport().addOrUpdateRosterItem(getJID(), buddy.getScreenname(), nickname, null);
}
catch (UserNotFoundException e) {
Log.error("Unable to add " + buddy.getScreenname() + " to roster.");
}
if (buddy.getId() > highestBuddyId) {
highestBuddyId = buddy.getId();
}
......
......@@ -11,6 +11,7 @@
package org.jivesoftware.wildfire.gateway.protocols.yahoo;
import java.io.IOException;
import java.util.Collection;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession;
......@@ -18,6 +19,7 @@ import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
import ymsg.network.LoginRefusedException;
import ymsg.network.Session;
import ymsg.network.YahooUser;
/**
* Represents a Yahoo session.
......@@ -80,6 +82,8 @@ public class YahooSession extends TransportSession {
p.setFrom(getTransport().getJID());
Log.debug("Logged in, sending: " + p.toString());
getTransport().sendPacket(p);
syncUsers();
}
catch (LoginRefusedException e) {
yahooSession.reset();
......@@ -121,6 +125,20 @@ public class YahooSession extends TransportSession {
return loggedIn;
}
/**
* Syncs up the yahoo roster with the jabber roster.
*/
public void syncUsers() {
for(YahooUser user : (Collection<YahooUser>)yahooSession.getUsers().values()) {
try {
getTransport().addOrUpdateRosterItem(getJID(), user.getId(), user.getId(), null);
}
catch (Exception e) {
// TODO: Failed for some reason.
}
}
}
/**
* Adds a contact to the user's Yahoo contact list.
*
......
......@@ -22,6 +22,7 @@ import ymsg.network.event.SessionFriendEvent;
import ymsg.network.event.SessionListener;
import ymsg.network.event.SessionNewMailEvent;
import ymsg.network.event.SessionNotifyEvent;
import ymsg.support.MessageDecoder;
/**
* Handles incoming packets from Yahoo.
......@@ -33,6 +34,11 @@ import ymsg.network.event.SessionNotifyEvent;
*/
public class YahooSessionListener implements SessionListener {
/**
* Handles converting messages between formats.
*/
private MessageDecoder messageDecoder = new MessageDecoder();
/**
* Creates a Yahoo session listener affiliated with a session.
*
......@@ -56,7 +62,7 @@ public class YahooSessionListener implements SessionListener {
m.setType(Message.Type.chat);
m.setTo(yahooSession.getJID());
m.setFrom(yahooSession.getTransport().convertIDToJID(event.getFrom()));
m.setBody(event.getMessage());
m.setBody(messageDecoder.decodeToText(event.getMessage()));
yahooSession.getTransport().sendPacket(m);
}
......
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