Commit 85afdd29 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[JM-761] [JM-769] [JM-770] There is now support for legacy services seeing...

[JM-761] [JM-769] [JM-770] There is now support for legacy services seeing your status.  Misc other reworkings.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4642 b35dd754-fafc-0310-a699-88a17e54d16e
parent 9e9d9840
...@@ -213,10 +213,12 @@ public abstract class BaseTransport implements Component { ...@@ -213,10 +213,12 @@ public abstract class BaseTransport implements Component {
TransportSession session = null; TransportSession session = null;
try { try {
session = sessionManager.getSession(from); session = sessionManager.getSession(from);
// TODO: This can also represent a status change.
// Well, this could represent a status change.
session.updateStatus(getPresenceType(packet), packet.getStatus());
} }
catch (NotFoundException e) { catch (NotFoundException e) {
session = this.registrationLoggedIn(registration, from); session = this.registrationLoggedIn(registration, from, getPresenceType(packet), packet.getStatus());
//sessionManager.storeSession(registration.getJID(), session); //sessionManager.storeSession(registration.getJID(), session);
sessionManager.storeSession(from, session); sessionManager.storeSession(from, session);
} }
...@@ -635,6 +637,38 @@ public abstract class BaseTransport implements Component { ...@@ -635,6 +637,38 @@ public abstract class BaseTransport implements Component {
return jid.getNode().replace('%', '@'); return jid.getNode().replace('%', '@');
} }
/**
* Gets an easy to use presence type from a presence packet.
*
* @param packet A presence packet from which the type will be pulled.
*/
public PresenceType getPresenceType(Presence packet) {
Presence.Type ptype = packet.getType();
Presence.Show stype = packet.getShow();
if (stype == Presence.Show.chat) {
return PresenceType.chat;
}
else if (stype == Presence.Show.away) {
return PresenceType.away;
}
else if (stype == Presence.Show.xa) {
return PresenceType.xa;
}
else if (stype == Presence.Show.dnd) {
return PresenceType.dnd;
}
else if (ptype == Presence.Type.unavailable) {
return PresenceType.unavailable;
}
else if (packet.isAvailable()) {
return PresenceType.available;
}
else {
return PresenceType.unknown;
}
}
/** /**
* Handles startup of the transport. * Handles startup of the transport.
*/ */
...@@ -935,9 +969,12 @@ public abstract class BaseTransport implements Component { ...@@ -935,9 +969,12 @@ public abstract class BaseTransport implements Component {
* Will handle logging in to the legacy service. * Will handle logging in to the legacy service.
* *
* @param registration Registration used for log in. * @param registration Registration used for log in.
* @param jid JID that is logged into the transport.
* @param presenceType Type of presence.
* @param verboseStatus Longer status description.
* @return A session instance for the new login. * @return A session instance for the new login.
*/ */
public abstract TransportSession registrationLoggedIn(Registration registration, JID jid); public abstract TransportSession registrationLoggedIn(Registration registration, JID jid, PresenceType presenceType, String verboseStatus);
/** /**
* Will handle logging out of the legacy service. * Will handle logging out of the legacy service.
......
...@@ -78,14 +78,12 @@ public abstract class TransportSession { ...@@ -78,14 +78,12 @@ public abstract class TransportSession {
} }
/** /**
* Logs in to the legacy service. * Updates status on legacy service.
*/ *
public abstract void logIn(); * @param presenceType Type of presence.
* @param verboseStatus Longer status description.
/**
* Log out of the legacy service.
*/ */
public abstract void logOut(); public abstract void updateStatus(PresenceType presenceType, String verboseStatus);
/** /**
* Is the legacy service account logged in? * Is the legacy service account logged in?
......
...@@ -18,6 +18,7 @@ import org.hn.sleek.jmml.ContactStatus; ...@@ -18,6 +18,7 @@ import org.hn.sleek.jmml.ContactStatus;
import org.hn.sleek.jmml.MessengerServerManager; import org.hn.sleek.jmml.MessengerServerManager;
import org.hn.sleek.jmml.MSNException; import org.hn.sleek.jmml.MSNException;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.PresenceType;
import org.jivesoftware.wildfire.gateway.Registration; 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;
...@@ -54,10 +55,14 @@ public class MSNSession extends TransportSession { ...@@ -54,10 +55,14 @@ public class MSNSession extends TransportSession {
/** /**
* Log in to MSN. * Log in to MSN.
*
* @param presenceType Type of presence.
* @param verboseStatus Long representation of status.
*/ */
public void logIn() { public void logIn(PresenceType presenceType, String verboseStatus) {
if (!this.isLoggedIn()) {
try { try {
msnManager.signIn(registration.getUsername(), registration.getPassword(), ContactStatus.ONLINE); msnManager.signIn(registration.getUsername(), registration.getPassword(), ((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType));
Presence p = new Presence(); Presence p = new Presence();
p.setTo(getJID()); p.setTo(getJID());
...@@ -72,11 +77,13 @@ public class MSNSession extends TransportSession { ...@@ -72,11 +77,13 @@ public class MSNSession extends TransportSession {
Log.error("MSN exception thrown while logging in:", e); Log.error("MSN exception thrown while logging in:", e);
} }
} }
}
/** /**
* Log out of MSN. * Log out of MSN.
*/ */
public void logOut() { public void logOut() {
if (this.isLoggedIn()) {
try { try {
msnManager.signOut(); msnManager.signOut();
Presence p = new Presence(Presence.Type.unavailable); Presence p = new Presence(Presence.Type.unavailable);
...@@ -88,6 +95,7 @@ public class MSNSession extends TransportSession { ...@@ -88,6 +95,7 @@ public class MSNSession extends TransportSession {
Log.error("MSN exception thrown while logging out:", e); Log.error("MSN exception thrown while logging out:", e);
} }
} }
}
/** /**
* Have we successfully logged in to MSN? * Have we successfully logged in to MSN?
...@@ -138,6 +146,18 @@ public class MSNSession extends TransportSession { ...@@ -138,6 +146,18 @@ public class MSNSession extends TransportSession {
// TODO: yeah // TODO: yeah
} }
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#updateStatus
*/
public void updateStatus(PresenceType presenceType, String verboseStatus) {
try {
msnManager.setStatus(((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType));
}
catch (MSNException e) {
Log.error("MSN exception while setting status:", e);
}
}
/** /**
* Retrieves the manager for this session. * Retrieves the manager for this session.
*/ */
......
...@@ -10,11 +10,14 @@ ...@@ -10,11 +10,14 @@
package org.jivesoftware.wildfire.gateway.protocols.msn; package org.jivesoftware.wildfire.gateway.protocols.msn;
import org.hn.sleek.jmml.ContactStatus;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.BaseTransport; import org.jivesoftware.wildfire.gateway.BaseTransport;
import org.jivesoftware.wildfire.gateway.PresenceType;
import org.jivesoftware.wildfire.gateway.Registration; import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession; import org.jivesoftware.wildfire.gateway.TransportSession;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
/** /**
* MSN Transport Interface. * MSN Transport Interface.
...@@ -30,11 +33,14 @@ public class MSNTransport extends BaseTransport { ...@@ -30,11 +33,14 @@ public class MSNTransport extends BaseTransport {
* Handles creating a MSN session and triggering a login. * Handles creating a MSN session and triggering a login.
* *
* @param registration Registration information to be used to log in. * @param registration Registration information to be used to log in.
* @param jid JID that is logged into the transport.
* @param presenceType Type of presence.
* @param verboseStatus Longer status description.
*/ */
public TransportSession registrationLoggedIn(Registration registration, JID jid) { public TransportSession registrationLoggedIn(Registration registration, JID jid, PresenceType presenceType, String verboseStatus) {
Log.debug("Logging in to MSN gateway."); Log.debug("Logging in to MSN gateway.");
TransportSession session = new MSNSession(registration, jid, this); TransportSession session = new MSNSession(registration, jid, this);
session.logIn(); ((MSNSession)session).logIn(presenceType, verboseStatus);
return session; return session;
} }
...@@ -45,7 +51,68 @@ public class MSNTransport extends BaseTransport { ...@@ -45,7 +51,68 @@ public class MSNTransport extends BaseTransport {
*/ */
public void registrationLoggedOut(TransportSession session) { public void registrationLoggedOut(TransportSession session) {
Log.debug("Logging out of MSN gateway."); Log.debug("Logging out of MSN gateway.");
session.logOut(); ((MSNSession)session).logOut();
}
/**
* Converts a jabber status to an MSN status.
*
* @param jabStatus Jabber presence type.
*/
public String convertJabStatusToMSN(PresenceType jabStatus) {
if (jabStatus == PresenceType.available) {
return ContactStatus.ONLINE;
}
else if (jabStatus == PresenceType.away) {
return ContactStatus.AWAY;
}
else if (jabStatus == PresenceType.xa) {
return ContactStatus.AWAY;
}
else if (jabStatus == PresenceType.dnd) {
return ContactStatus.BUSY;
}
else if (jabStatus == PresenceType.chat) {
return ContactStatus.ONLINE;
}
else if (jabStatus == PresenceType.unavailable) {
return ContactStatus.OFFLINE;
}
else {
return ContactStatus.ONLINE;
}
}
/**
* Sets up a presence packet according to MSN status.
*
* @param msnStatus MSN ContactStatus constant.
*/
public void setUpPresencePacket(Presence packet, String msnStatus) {
if (msnStatus.equals(ContactStatus.ONLINE)) {
// We're good, send as is..
}
else if (msnStatus.equals(ContactStatus.AWAY)) {
packet.setShow(Presence.Show.away);
}
else if (msnStatus.equals(ContactStatus.BE_RIGHT_BACK)) {
packet.setShow(Presence.Show.away);
}
else if (msnStatus.equals(ContactStatus.BUSY)) {
packet.setShow(Presence.Show.dnd);
}
else if (msnStatus.equals(ContactStatus.IDLE)) {
packet.setShow(Presence.Show.away);
}
else if (msnStatus.equals(ContactStatus.OFFLINE)) {
packet.setType(Presence.Type.unavailable);
}
else if (msnStatus.equals(ContactStatus.ON_THE_PHONE)) {
packet.setShow(Presence.Show.dnd);
}
else if (msnStatus.equals(ContactStatus.OUT_TO_LUNCH)) {
packet.setShow(Presence.Show.xa);
}
} }
} }
...@@ -146,7 +146,8 @@ public abstract class BasicFlapConnection extends BaseFlapConnection { ...@@ -146,7 +146,8 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
request(new ClientVersionsCmd(familyInfos)); request(new ClientVersionsCmd(familyInfos));
request(new RateInfoRequest()); request(new RateInfoRequest());
} else if (cmd instanceof RecvImIcbm) { }
else if (cmd instanceof RecvImIcbm) {
RecvImIcbm icbm = (RecvImIcbm) cmd; RecvImIcbm icbm = (RecvImIcbm) cmd;
String sn = icbm.getSenderInfo().getScreenname(); String sn = icbm.getSenderInfo().getScreenname();
...@@ -167,17 +168,20 @@ public abstract class BasicFlapConnection extends BaseFlapConnection { ...@@ -167,17 +168,20 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
+ sn + ": " + msg; + sn + ": " + msg;
Log.debug(str); Log.debug(str);
} else if (cmd instanceof WarningNotification) { }
else if (cmd instanceof WarningNotification) {
WarningNotification wn = (WarningNotification) cmd; WarningNotification wn = (WarningNotification) cmd;
MiniUserInfo warner = wn.getWarner(); MiniUserInfo warner = wn.getWarner();
if (warner == null) { if (warner == null) {
Log.debug("*** You were warned anonymously to " Log.debug("*** You were warned anonymously to "
+ wn.getNewLevel() + "%"); + wn.getNewLevel() + "%");
} else { }
else {
Log.debug("*** " + warner.getScreenname() Log.debug("*** " + warner.getScreenname()
+ " warned you up to " + wn.getNewLevel() + "%"); + " warned you up to " + wn.getNewLevel() + "%");
} }
} else if (cmd instanceof BuddyStatusCmd) { }
else if (cmd instanceof BuddyStatusCmd) {
BuddyStatusCmd bsc = (BuddyStatusCmd)cmd; BuddyStatusCmd bsc = (BuddyStatusCmd)cmd;
FullUserInfo info = bsc.getUserInfo(); FullUserInfo info = bsc.getUserInfo();
buddystore.put(info.getScreenname(), info); buddystore.put(info.getScreenname(), info);
...@@ -213,14 +217,16 @@ public abstract class BasicFlapConnection extends BaseFlapConnection { ...@@ -213,14 +217,16 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
} }
} }
oscarSession.getTransport().sendPacket(p); oscarSession.getTransport().sendPacket(p);
} else if (cmd instanceof BuddyOfflineCmd) { }
else if (cmd instanceof BuddyOfflineCmd) {
BuddyOfflineCmd boc = (BuddyOfflineCmd)cmd; BuddyOfflineCmd boc = (BuddyOfflineCmd)cmd;
buddystore.remove(boc.getScreenname()); buddystore.remove(boc.getScreenname());
Presence p = new Presence(Presence.Type.unavailable); Presence p = new Presence(Presence.Type.unavailable);
p.setTo(oscarSession.getJID()); p.setTo(oscarSession.getJID());
p.setFrom(oscarSession.getTransport().convertIDToJID(boc.getScreenname())); p.setFrom(oscarSession.getTransport().convertIDToJID(boc.getScreenname()));
oscarSession.getTransport().sendPacket(p); oscarSession.getTransport().sendPacket(p);
} else if (cmd instanceof RateChange) { }
else if (cmd instanceof RateChange) {
RateChange rc = (RateChange) cmd; RateChange rc = (RateChange) cmd;
//Log.debug("rate change: current avg is " //Log.debug("rate change: current avg is "
......
...@@ -77,7 +77,8 @@ public class LoginConnection extends BaseFlapConnection { ...@@ -77,7 +77,8 @@ public class LoginConnection extends BaseFlapConnection {
request(new AuthRequest(oscarSession.getRegistration().getUsername(), oscarSession.getRegistration().getPassword(), version, authkey)); request(new AuthRequest(oscarSession.getRegistration().getUsername(), oscarSession.getRegistration().getPassword(), version, authkey));
} else if (cmd instanceof AuthResponse) { }
else if (cmd instanceof AuthResponse) {
AuthResponse ar = (AuthResponse) cmd; AuthResponse ar = (AuthResponse) cmd;
int error = ar.getErrorCode(); int error = ar.getErrorCode();
......
...@@ -18,12 +18,15 @@ import java.util.Map; ...@@ -18,12 +18,15 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import net.kano.joscar.flapcmd.*; import net.kano.joscar.flapcmd.*;
import net.kano.joscar.snac.*; import net.kano.joscar.snac.*;
import net.kano.joscar.snaccmd.*;
import net.kano.joscar.snaccmd.conn.*; import net.kano.joscar.snaccmd.conn.*;
import net.kano.joscar.snaccmd.icbm.*; import net.kano.joscar.snaccmd.icbm.*;
import net.kano.joscar.snaccmd.loc.*;
import net.kano.joscar.snaccmd.ssi.*; import net.kano.joscar.snaccmd.ssi.*;
import net.kano.joscar.ssiitem.*; import net.kano.joscar.ssiitem.*;
import net.kano.joscar.ByteBlock; import net.kano.joscar.ByteBlock;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.PresenceType;
import org.jivesoftware.wildfire.gateway.Registration; 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;
...@@ -39,6 +42,9 @@ import org.xmpp.packet.Presence; ...@@ -39,6 +42,9 @@ import org.xmpp.packet.Presence;
* This is the interface with which the base transport functionality will * This is the interface with which the base transport functionality will
* communicate with OSCAR (AIM/ICQ). * communicate with OSCAR (AIM/ICQ).
* *
* Yeesh, this is the one I'm most familiar with and yet it's the ugliest.
* This needs some housecleaning.
*
* @author Daniel Henninger * @author Daniel Henninger
*/ */
public class OSCARSession extends TransportSession { public class OSCARSession extends TransportSession {
...@@ -76,7 +82,7 @@ public class OSCARSession extends TransportSession { ...@@ -76,7 +82,7 @@ public class OSCARSession extends TransportSession {
private Integer highestBuddyId = -1; private Integer highestBuddyId = -1;
private Integer highestGroupId = -1; private Integer highestGroupId = -1;
public void logIn() { public void logIn(PresenceType presenceType, String verboseStatus) {
if (!isLoggedIn()) { if (!isLoggedIn()) {
loginConn = new LoginConnection("login.oscar.aol.com", 5190, this); loginConn = new LoginConnection("login.oscar.aol.com", 5190, this);
loginConn.connect(); loginConn.connect();
...@@ -87,6 +93,8 @@ public class OSCARSession extends TransportSession { ...@@ -87,6 +93,8 @@ public class OSCARSession extends TransportSession {
p.setTo(getJID()); p.setTo(getJID());
p.setFrom(getTransport().getJID()); p.setFrom(getTransport().getJID());
getTransport().sendPacket(p); getTransport().sendPacket(p);
updateStatus(presenceType, verboseStatus);
} else { } else {
Log.warn(this.jid + " is already logged in"); Log.warn(this.jid + " is already logged in");
} }
...@@ -270,4 +278,20 @@ public class OSCARSession extends TransportSession { ...@@ -270,4 +278,20 @@ public class OSCARSession extends TransportSession {
bosConn.getAndSendStatus(jid.getNode()); bosConn.getAndSendStatus(jid.getNode());
} }
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#updateStatus
*/
public void updateStatus(PresenceType presenceType, String verboseStatus) {
if (presenceType != PresenceType.available && presenceType != PresenceType.chat) {
String awayMsg = "Away";
if (verboseStatus != null) {
awayMsg = verboseStatus;
}
request(new SetInfoCmd(new InfoData(awayMsg)));
}
else {
request(new SetInfoCmd(new InfoData("")));
}
}
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
package org.jivesoftware.wildfire.gateway.protocols.oscar; package org.jivesoftware.wildfire.gateway.protocols.oscar;
import org.jivesoftware.wildfire.gateway.BaseTransport; import org.jivesoftware.wildfire.gateway.BaseTransport;
import org.jivesoftware.wildfire.gateway.PresenceType;
import org.jivesoftware.wildfire.gateway.Registration; import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession; import org.jivesoftware.wildfire.gateway.TransportSession;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
...@@ -29,10 +30,13 @@ public class OSCARTransport extends BaseTransport { ...@@ -29,10 +30,13 @@ public class OSCARTransport extends BaseTransport {
* Handles creating an OSCAR session and triggering a login. * Handles creating an OSCAR session and triggering a login.
* *
* @param registration Registration information to be used to log in. * @param registration Registration information to be used to log in.
* @param jid JID that is logged into the transport.
* @param presenceType Type of presence.
* @param verboseStatus Longer status description.
*/ */
public TransportSession registrationLoggedIn(Registration registration, JID jid) { public TransportSession registrationLoggedIn(Registration registration, JID jid, PresenceType presenceType, String verboseStatus) {
TransportSession session = new OSCARSession(registration, jid, this); TransportSession session = new OSCARSession(registration, jid, this);
session.logIn(); ((OSCARSession)session).logIn(presenceType, verboseStatus);
return session; return session;
} }
...@@ -42,7 +46,7 @@ public class OSCARTransport extends BaseTransport { ...@@ -42,7 +46,7 @@ public class OSCARTransport extends BaseTransport {
* @param session The session to be disconnected. * @param session The session to be disconnected.
*/ */
public void registrationLoggedOut(TransportSession session) { public void registrationLoggedOut(TransportSession session) {
session.logOut(); ((OSCARSession)session).logOut();
} }
} }
...@@ -16,6 +16,7 @@ import java.util.Collection; ...@@ -16,6 +16,7 @@ import java.util.Collection;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.PresenceType;
import org.jivesoftware.wildfire.gateway.Registration; 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;
...@@ -73,8 +74,12 @@ public class YahooSession extends TransportSession { ...@@ -73,8 +74,12 @@ public class YahooSession extends TransportSession {
/** /**
* Log in to Yahoo. * Log in to Yahoo.
*
* @param presenceType Type of presence.
* @param verboseStatus Long representation of status.
*/ */
public void logIn() { public void logIn(PresenceType presenceType, String verboseStatus) {
final PresenceType pType = presenceType;
if (!isLoggedIn() && !loggingIn && loginAttempts <= 3) { if (!isLoggedIn() && !loggingIn && loginAttempts <= 3) {
loggingIn = true; loggingIn = true;
new Thread() { new Thread() {
...@@ -90,6 +95,8 @@ public class YahooSession extends TransportSession { ...@@ -90,6 +95,8 @@ public class YahooSession extends TransportSession {
Log.debug("Logged in, sending: " + p.toString()); Log.debug("Logged in, sending: " + p.toString());
getTransport().sendPacket(p); getTransport().sendPacket(p);
yahooSession.setStatus(((YahooTransport)getTransport()).convertJabStatusToYahoo(pType));
syncUsers(); syncUsers();
} }
catch (LoginRefusedException e) { catch (LoginRefusedException e) {
...@@ -161,44 +168,7 @@ public class YahooSession extends TransportSession { ...@@ -161,44 +168,7 @@ public class YahooSession extends TransportSession {
p.setStatus(custommsg); p.setStatus(custommsg);
} }
long statusid = user.getStatus(); ((YahooTransport)getTransport()).setUpPresencePacket(p, user.getStatus());
if (statusid == StatusConstants.STATUS_AVAILABLE) {
// We're good, leave the type as blank for available.
}
else if (statusid == StatusConstants.STATUS_BRB) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_BUSY) {
p.setShow(Presence.Show.dnd);
}
else if (statusid == StatusConstants.STATUS_IDLE) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_OFFLINE) {
p.setType(Presence.Type.unavailable);
}
else if (statusid == StatusConstants.STATUS_NOTATDESK) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_NOTINOFFICE) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_ONPHONE) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_ONVACATION) {
p.setShow(Presence.Show.xa);
}
else if (statusid == StatusConstants.STATUS_OUTTOLUNCH) {
p.setShow(Presence.Show.xa);
}
else if (statusid == StatusConstants.STATUS_STEPPEDOUT) {
p.setShow(Presence.Show.away);
}
else {
// Not something we handle, we're going to ignore it.
}
getTransport().sendPacket(p); getTransport().sendPacket(p);
} }
} }
...@@ -248,6 +218,18 @@ public class YahooSession extends TransportSession { ...@@ -248,6 +218,18 @@ public class YahooSession extends TransportSession {
} }
} }
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#updateStatus
*/
public void updateStatus(PresenceType presenceType, String verboseStatus) {
try {
yahooSession.setStatus(((YahooTransport)getTransport()).convertJabStatusToYahoo(presenceType));
}
catch (Exception e) {
Log.error("Unable to set Yahoo Status:", e);
}
}
/** /**
* Asks for transport to send information about a contact if possible. * Asks for transport to send information about a contact if possible.
* *
...@@ -264,44 +246,7 @@ public class YahooSession extends TransportSession { ...@@ -264,44 +246,7 @@ public class YahooSession extends TransportSession {
p.setStatus(custommsg); p.setStatus(custommsg);
} }
long statusid = user.getStatus(); ((YahooTransport)getTransport()).setUpPresencePacket(p, user.getStatus());
if (statusid == StatusConstants.STATUS_AVAILABLE) {
// We're good, leave the type as blank for available.
}
else if (statusid == StatusConstants.STATUS_BRB) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_BUSY) {
p.setShow(Presence.Show.dnd);
}
else if (statusid == StatusConstants.STATUS_IDLE) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_OFFLINE) {
p.setType(Presence.Type.unavailable);
}
else if (statusid == StatusConstants.STATUS_NOTATDESK) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_NOTINOFFICE) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_ONPHONE) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_ONVACATION) {
p.setShow(Presence.Show.xa);
}
else if (statusid == StatusConstants.STATUS_OUTTOLUNCH) {
p.setShow(Presence.Show.xa);
}
else if (statusid == StatusConstants.STATUS_STEPPEDOUT) {
p.setShow(Presence.Show.away);
}
else {
// Not something we handle, we're going to ignore it.
}
getTransport().sendPacket(p); getTransport().sendPacket(p);
} }
......
...@@ -83,43 +83,7 @@ public class YahooSessionListener implements SessionListener { ...@@ -83,43 +83,7 @@ public class YahooSessionListener implements SessionListener {
} }
long statusid = user.getStatus(); long statusid = user.getStatus();
if (statusid == StatusConstants.STATUS_AVAILABLE) { ((YahooTransport)yahooSession.getTransport()).setUpPresencePacket(p, user.getStatus());
// We're good, leave the type as blank for available.
}
else if (statusid == StatusConstants.STATUS_BRB) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_BUSY) {
p.setShow(Presence.Show.dnd);
}
else if (statusid == StatusConstants.STATUS_IDLE) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_OFFLINE) {
p.setType(Presence.Type.unavailable);
}
else if (statusid == StatusConstants.STATUS_NOTATDESK) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_NOTINOFFICE) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_ONPHONE) {
p.setShow(Presence.Show.away);
}
else if (statusid == StatusConstants.STATUS_ONVACATION) {
p.setShow(Presence.Show.xa);
}
else if (statusid == StatusConstants.STATUS_OUTTOLUNCH) {
p.setShow(Presence.Show.xa);
}
else if (statusid == StatusConstants.STATUS_STEPPEDOUT) {
p.setShow(Presence.Show.away);
}
else {
// Not something we handle, we're going to ignore it.
}
yahooSession.getTransport().sendPacket(p); yahooSession.getTransport().sendPacket(p);
} }
} }
......
...@@ -12,9 +12,12 @@ package org.jivesoftware.wildfire.gateway.protocols.yahoo; ...@@ -12,9 +12,12 @@ package org.jivesoftware.wildfire.gateway.protocols.yahoo;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.BaseTransport; import org.jivesoftware.wildfire.gateway.BaseTransport;
import org.jivesoftware.wildfire.gateway.PresenceType;
import org.jivesoftware.wildfire.gateway.Registration; import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession; import org.jivesoftware.wildfire.gateway.TransportSession;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
import ymsg.network.StatusConstants;
/** /**
* Yahoo Transport Interface. * Yahoo Transport Interface.
...@@ -30,11 +33,14 @@ public class YahooTransport extends BaseTransport { ...@@ -30,11 +33,14 @@ public class YahooTransport extends BaseTransport {
* Handles creating a Yahoo session and triggering a login. * Handles creating a Yahoo session and triggering a login.
* *
* @param registration Registration information to be used to log in. * @param registration Registration information to be used to log in.
* @param jid JID that is logged into the transport.
* @param presenceType Type of presence.
* @param verboseStatus Longer status description.
*/ */
public TransportSession registrationLoggedIn(Registration registration, JID jid) { public TransportSession registrationLoggedIn(Registration registration, JID jid, PresenceType presenceType, String verboseStatus) {
Log.debug("Logging in to Yahoo gateway."); Log.debug("Logging in to Yahoo gateway.");
TransportSession session = new YahooSession(registration, jid, this); TransportSession session = new YahooSession(registration, jid, this);
session.logIn(); ((YahooSession)session).logIn(presenceType, verboseStatus);
return session; return session;
} }
...@@ -45,7 +51,79 @@ public class YahooTransport extends BaseTransport { ...@@ -45,7 +51,79 @@ public class YahooTransport extends BaseTransport {
*/ */
public void registrationLoggedOut(TransportSession session) { public void registrationLoggedOut(TransportSession session) {
Log.debug("Logging out of Yahoo gateway."); Log.debug("Logging out of Yahoo gateway.");
session.logOut(); ((YahooSession)session).logOut();
} }
/**
* Converts a jabber status to an Yahoo status.
*
* @param jabStatus Jabber presence type.
*/
public long convertJabStatusToYahoo(PresenceType jabStatus) {
if (jabStatus == PresenceType.available) {
return StatusConstants.STATUS_AVAILABLE;
}
else if (jabStatus == PresenceType.away) {
return StatusConstants.STATUS_BRB;
}
else if (jabStatus == PresenceType.xa) {
return StatusConstants.STATUS_STEPPEDOUT;
}
else if (jabStatus == PresenceType.dnd) {
return StatusConstants.STATUS_BUSY;
}
else if (jabStatus == PresenceType.chat) {
return StatusConstants.STATUS_AVAILABLE;
}
else if (jabStatus == PresenceType.unavailable) {
return StatusConstants.STATUS_OFFLINE;
}
else {
return StatusConstants.STATUS_AVAILABLE;
}
}
/**
* Sets up a presence packet according to Yahoo status.
*
* @param yahooStatus Yahoo StatusConstants constant.
*/
public void setUpPresencePacket(Presence packet, long yahooStatus) {
if (yahooStatus == StatusConstants.STATUS_AVAILABLE) {
// We're good, leave the type as blank for available.
}
else if (yahooStatus == StatusConstants.STATUS_BRB) {
packet.setShow(Presence.Show.away);
}
else if (yahooStatus == StatusConstants.STATUS_BUSY) {
packet.setShow(Presence.Show.dnd);
}
else if (yahooStatus == StatusConstants.STATUS_IDLE) {
packet.setShow(Presence.Show.away);
}
else if (yahooStatus == StatusConstants.STATUS_OFFLINE) {
packet.setType(Presence.Type.unavailable);
}
else if (yahooStatus == StatusConstants.STATUS_NOTATDESK) {
packet.setShow(Presence.Show.away);
}
else if (yahooStatus == StatusConstants.STATUS_NOTINOFFICE) {
packet.setShow(Presence.Show.away);
}
else if (yahooStatus == StatusConstants.STATUS_ONPHONE) {
packet.setShow(Presence.Show.away);
}
else if (yahooStatus == StatusConstants.STATUS_ONVACATION) {
packet.setShow(Presence.Show.xa);
}
else if (yahooStatus == StatusConstants.STATUS_OUTTOLUNCH) {
packet.setShow(Presence.Show.xa);
}
else if (yahooStatus == StatusConstants.STATUS_STEPPEDOUT) {
packet.setShow(Presence.Show.away);
}
else {
// Not something we handle, we're going to ignore it.
}
}
} }
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