Commit 6f3e3c38 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[JM-761] [JM-769] Buddy list integration is working well now. Buddy statuses...

[JM-761] [JM-769] Buddy list integration is working well now.  Buddy statuses are working.  'my status' is not being sent to legacy service yet.  Other misc bugs.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@4549 b35dd754-fafc-0310-a699-88a17e54d16e
parent ae9e73ec
......@@ -13,6 +13,8 @@ package org.jivesoftware.wildfire.gateway;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.QName;
......@@ -189,7 +191,7 @@ public abstract class BaseTransport implements Component {
try {
if (to.getNode() == null) {
Log.debug("Message to gateway");
Log.debug("Presence to gateway");
Collection<Registration> registrations = registrationManager.getRegistrations(from, this.transportType);
if (!registrations.iterator().hasNext()) {
// User is not registered with us.
......@@ -253,12 +255,17 @@ public abstract class BaseTransport implements Component {
}
}
else {
Log.debug("Message to user at gateway");
Log.debug("Presence to user at gateway");
// This packet is to a user at the transport.
TransportSession session = sessionManager.getSession(from);
if (session == null) {
// We don't have a session, so stop here.
// TODO: maybe return an error?
Log.error("No session for incoming packet: " + packet.toString());
}
else if (packet.getType() == Presence.Type.probe) {
// Presence probe, lets try to tell them.
session.retrieveContactStatus(packet.getTo());
}
else if (packet.getType() == Presence.Type.subscribe) {
// User wants to add someone to their legacy roster.
......@@ -444,7 +451,21 @@ public abstract class BaseTransport implements Component {
result.setChildElement(response);
reply.add(result);
Collection<Registration> registrations = registrationManager.getRegistrations(packet.getFrom(), this.transportType);
Boolean foundReg = false;
for (Registration registration : registrations) {
if (!registration.getUsername().equals(username)) {
registrationManager.deleteRegistration(registration);
}
else {
registration.setPassword(password);
foundReg = true;
}
}
if (!foundReg) {
registrationManager.createRegistration(packet.getFrom(), this.transportType, username, password);
}
try {
addOrUpdateRosterItem(packet.getFrom(), packet.getTo(), this.getDescription(), "Transports");
......@@ -531,6 +552,8 @@ public abstract class BaseTransport implements Component {
/**
* Either updates or adds a JID to a user's roster.
*
* Tries to only edit the roster if it has to.
*
* @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)
......@@ -542,23 +565,35 @@ public abstract class BaseTransport implements Component {
Roster roster = rosterManager.getRoster(userjid.getNode());
try {
RosterItem gwitem = roster.getRosterItem(contactjid);
Boolean changed = false;
if (gwitem.getSubStatus() != RosterItem.SUB_BOTH) {
gwitem.setSubStatus(RosterItem.SUB_BOTH);
changed = true;
}
if (gwitem.getAskStatus() != RosterItem.ASK_NONE) {
gwitem.setAskStatus(RosterItem.ASK_NONE);
changed = true;
}
if (!gwitem.getNickname().equals(nickname)) {
gwitem.setNickname(nickname);
changed = true;
}
List<String> curgroups = gwitem.getGroups();
List<String> groups = new ArrayList<String>();
groups.add(group);
if (curgroups != groups) {
try {
gwitem.setGroups(groups);
changed = true;
}
catch (Exception ee) {
// Oooookay, ignore then.
}
}
if (changed) {
roster.updateRosterItem(gwitem);
}
}
catch (UserNotFoundException e) {
try {
RosterItem gwitem = roster.createRosterItem(contactjid, true);
......@@ -655,6 +690,87 @@ public abstract class BaseTransport implements Component {
}
}
/**
* Sync a user's roster with their legacy contact list.
*
* Given a collection of transport buddies, syncs up the user's
* roster by fixing any nicknames, group assignments, adding and removing
* roster items, and generally trying to make the jabber roster list
* assigned to the transport's JID look at much like the legacy buddy
* list as possible. This is a very extensive operation. You do not
* want to do this very often. Typically once right after the person
* has logged into the legacy service.
*
* @param userjid JID of user who's roster we are syncing with.
* @param legacyitems List of TransportBuddy's to be synced.
* @throws UserNotFoundException if userjid not found.
*/
public void syncLegacyRoster(JID userjid, List<TransportBuddy> legacyitems) throws UserNotFoundException {
try {
Roster roster = rosterManager.getRoster(userjid.getNode());
// First thing first, we want to build ourselves an easy mapping.
Map<JID,TransportBuddy> legacymap = new HashMap<JID,TransportBuddy>();
for (TransportBuddy buddy : legacyitems) {
Log.debug("ROSTERSYNC: Mapping "+buddy.getName());
legacymap.put(new JID(buddy.getName(), this.jid.getDomain(), null), buddy);
}
// Now, lets go through the roster and see what matches up.
for (RosterItem ri : roster.getRosterItems()) {
if (!ri.getJid().getDomain().equals(this.jid.getDomain())) {
// Not our contact to care about.
continue;
}
if (ri.getJid().getNode() == null) {
// This is a transport instance, lets leave it alone.
continue;
}
JID jid = new JID(ri.getJid().toBareJID());
if (legacymap.containsKey(jid)) {
Log.debug("ROSTERSYNC: We found, updating " + jid.toString());
// Ok, matched a legacy to jabber roster item
// Lets update if there are differences
TransportBuddy buddy = legacymap.get(jid);
try {
this.addOrUpdateRosterItem(userjid, buddy.getName(), buddy.getNickname(), buddy.getGroup());
}
catch (UserNotFoundException e) {
// TODO: Something is quite wrong if we see this.
Log.error("Failed updating roster item");
}
legacymap.remove(jid);
}
else {
Log.debug("ROSTERSYNC: We did not find, removing " + jid.toString());
// This person is apparantly no longer in the legacy roster.
try {
this.removeFromRoster(userjid, jid);
}
catch (UserNotFoundException e) {
// TODO: Something is quite wrong if we see this.
Log.error("Failed removing roster item");
}
}
}
// Ok, we should now have only new items from the legacy roster
for (TransportBuddy buddy : legacymap.values()) {
Log.debug("ROSTERSYNC: We have new, adding " + buddy.getName());
try {
this.addOrUpdateRosterItem(userjid, buddy.getName(), buddy.getNickname(), buddy.getGroup());
}
catch (UserNotFoundException e) {
// TODO: Something is quite wrong if we see this.
Log.error("Failed adding new roster item");
}
}
}
catch (UserNotFoundException e) {
throw new UserNotFoundException("Could not find roster for " + userjid.toString());
}
}
/**
* Sends a packet through the component manager as the component.
*
......
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.gateway;
/**
* Transport Buddy.
*
* This is simply a means for providing a collection of information about
* a legacy service (transport) buddy to the underlying system. It collects
* all of the necessary pieces into one object.
*
* @author Daniel Henninger
*/
public class TransportBuddy {
/**
* Creates a TransportBuddy instance.
*
* @param contactname The legacy contact name.
* @param nickname The legacy nickname (can be null).
* @param group The group the legacy contact is in (can be null).
*/
public TransportBuddy(String contactname, String nickname, String group) {
this.contactname = contactname.toLowerCase();
this.nickname = nickname;
this.group = group;
}
/**
* ID, Screenname, name, whatever the contact name is on the legacy system
*/
public String contactname = null;
/**
* A nickname associated with this contact, if it exists.
*/
public String nickname = null;
/**
* A group associated with this contact, if it exists.
*/
public String group = null;
/**
* Retrieves the name of the contact.
*/
public String getName() {
return contactname;
}
/**
* Retrieves the nickname of the contact.
*/
public String getNickname() {
return nickname;
}
/**
* Retrieves the group of the contact.
*/
public String getGroup() {
return group;
}
}
......@@ -116,4 +116,13 @@ public abstract class TransportSession {
*/
public abstract void sendMessage(JID jid, String message);
/**
* Asks the legacy service to send a presence packet for a contact.
*
* This is typically response to a probe.
*
* @param jid JID to be checked.
*/
public abstract void retrieveContactStatus(JID jid);
}
......@@ -130,6 +130,7 @@ public class BOSConnection extends BasicFlapConnection {
Log.debug("done with SSI");
request(new ActivateSsiCmd());
clientReady();
oscarSession.gotCompleteSSI();
}
}
}
......
......@@ -47,11 +47,14 @@ import net.kano.joscar.snaccmd.rooms.*;
import org.jivesoftware.util.Log;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
public abstract class BasicFlapConnection extends BaseFlapConnection {
protected final ByteBlock cookie;
protected boolean sentClientReady = false;
public Map<String,FullUserInfo> buddystore = new HashMap<String,FullUserInfo>();
protected int[] snacFamilies = null;
protected SnacFamilyInfo[] snacFamilyInfos;
protected RateLimitingQueueMgr rateMgr = new RateLimitingQueueMgr();
......@@ -175,69 +178,48 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
+ " warned you up to " + wn.getNewLevel() + "%");
}
} else if (cmd instanceof BuddyStatusCmd) {
BuddyStatusCmd bsc = (BuddyStatusCmd) cmd;
BuddyStatusCmd bsc = (BuddyStatusCmd)cmd;
FullUserInfo info = bsc.getUserInfo();
buddystore.put(info.getScreenname(), info);
Presence p = new Presence();
p.setTo(oscarSession.getJID());
p.setFrom(oscarSession.getTransport().convertIDToJID(info.getScreenname()));
String sn = info.getScreenname();
ExtraInfoBlock[] extraInfos = info.getExtraInfoBlocks();
if (info.getAwayStatus() == true) {
p.setShow(Presence.Show.away);
}
if (extraInfos != null) {
for (int i = 0; i < extraInfos.length; i++) {
ExtraInfoBlock extraInfo = extraInfos[i];
ExtraInfoData data = extraInfo.getExtraData();
ExtraInfoBlock[] extraInfo = info.getExtraInfoBlocks();
if (extraInfo != null) {
for (ExtraInfoBlock i : extraInfo) {
ExtraInfoData data = i.getExtraData();
if (extraInfo.getType() == ExtraInfoBlock.TYPE_AVAILMSG) {
if (i.getType() == ExtraInfoBlock.TYPE_AVAILMSG) {
ByteBlock msgBlock = data.getData();
int len = BinaryTools.getUShort(msgBlock, 0);
byte[] msgBytes = msgBlock.subBlock(2, len).toByteArray();
byte[] msgBytes = msgBlock.subBlock(2, len).toByteArray(
);
String msg;
try {
msg = new String(msgBytes, "UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
return;
}
if (msg.length() > 0) {
Log.debug(info.getScreenname()
+ " availability: " + msg);
}
}
catch (UnsupportedEncodingException e1) {
continue;
}
if (msg.length() > 0) {
p.setStatus(msg);
}
if (info.getCapabilityBlocks() != null) {
List known = Arrays.asList(new CapabilityBlock[] {
CapabilityBlock.BLOCK_ICQCOMPATIBLE,
});
List caps = new ArrayList(Arrays.asList(
info.getCapabilityBlocks()));
caps.removeAll(known);
if (!caps.isEmpty()) {
Log.debug(sn + " has " + caps.size()
+ " unknown caps:");
for (Iterator it = caps.iterator(); it.hasNext();) {
Log.debug("- " + it.next());
}
}
/*
caps = new ArrayList(known);
caps.removeAll(Arrays.asList(info.getCapabilityBlocks()));
if (!caps.isEmpty()) {
Log.debug(sn + " is missing " + caps.size()
+ " caps:");
for (Iterator it = caps.iterator(); it.hasNext();) {
Log.debug("- " + it.next());
}
}
*/
}
oscarSession.getTransport().sendPacket(p);
} else if (cmd instanceof BuddyOfflineCmd) {
BuddyOfflineCmd boc = (BuddyOfflineCmd) cmd;
BuddyOfflineCmd boc = (BuddyOfflineCmd)cmd;
buddystore.remove(boc.getScreenname());
Presence p = new Presence(Presence.Type.unavailable);
p.setTo(oscarSession.getJID());
p.setFrom(oscarSession.getTransport().convertIDToJID(boc.getScreenname()));
oscarSession.getTransport().sendPacket(p);
} else if (cmd instanceof RateChange) {
RateChange rc = (RateChange) cmd;
......@@ -326,4 +308,57 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
}
}
/**
* Retrieves and sends last known status.
*
* This retrieves the last known status of the user and sends it on
* to the JID associated with this session. Meant for probe packets.
*
* @param sn Screen name to check on.
*/
public void getAndSendStatus(String sn) {
if (buddystore.containsKey(sn)) {
FullUserInfo info = buddystore.get(sn);
buddystore.put(info.getScreenname(), info);
Presence p = new Presence();
p.setTo(oscarSession.getJID());
p.setFrom(oscarSession.getTransport().convertIDToJID(info.getScreenname()));
if (info.getAwayStatus() == true) {
p.setShow(Presence.Show.away);
}
ExtraInfoBlock[] extraInfo = info.getExtraInfoBlocks();
if (extraInfo != null) {
for (ExtraInfoBlock i : extraInfo) {
ExtraInfoData data = i.getExtraData();
if (i.getType() == ExtraInfoBlock.TYPE_AVAILMSG) {
ByteBlock msgBlock = data.getData();
int len = BinaryTools.getUShort(msgBlock, 0);
byte[] msgBytes = msgBlock.subBlock(2, len).toByteArray(
);
String msg;
try {
msg = new String(msgBytes, "UTF-8");
}
catch (UnsupportedEncodingException e1) {
continue;
}
if (msg.length() > 0) {
p.setStatus(msg);
}
}
}
}
oscarSession.getTransport().sendPacket(p);
}
else {
Presence p = new Presence(Presence.Type.unavailable);
p.setTo(oscarSession.getJID());
p.setFrom(oscarSession.getTransport().convertIDToJID(sn));
oscarSession.getTransport().sendPacket(p);
}
}
}
......@@ -12,7 +12,9 @@ package org.jivesoftware.wildfire.gateway.protocols.oscar;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.kano.joscar.flapcmd.*;
import net.kano.joscar.snac.*;
......@@ -23,11 +25,13 @@ import net.kano.joscar.ssiitem.*;
import net.kano.joscar.ByteBlock;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportBuddy;
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;
import org.xmpp.packet.Presence;
/**
* Represents an OSCAR session.
......@@ -67,40 +71,46 @@ public class OSCARSession extends TransportSession {
/**
* SSI tracking variables.
*/
private ArrayList<BuddyItem> buddies = new ArrayList<BuddyItem>();
private ArrayList<GroupItem> groups = new ArrayList<GroupItem>();
private Map<Integer,BuddyItem> buddies = new HashMap<Integer,BuddyItem>();
private Map<Integer,GroupItem> groups = new HashMap<Integer,GroupItem>();
private Integer highestBuddyId = -1;
private Integer highestGroupId = -1;
public void logIn() {
Log.debug("Login called");
if (!isLoggedIn()) {
Log.debug("Connecting...");
loginConn = new LoginConnection("login.oscar.aol.com", 5190, this);
loginConn.connect();
loggedIn = true;
Presence p = new Presence();
p.setTo(getJID());
p.setFrom(getTransport().getJID());
Log.debug("Logged in, sending: " + p.toString());
getTransport().sendPacket(p);
} else {
Log.warn(this.jid + " is already logged in");
}
}
public Boolean isLoggedIn() {
Log.debug("isLoggedIn called");
return loggedIn;
}
public synchronized void logOut() {
Log.debug("logout called");
bosConn.disconnect();
loggedIn = false;
Presence p = new Presence(Presence.Type.unavailable);
p.setTo(getJID());
p.setFrom(getTransport().getJID());
getTransport().sendPacket(p);
}
public void addContact(JID jid) {
Log.debug("addContact called");
Integer newBuddyId = highestBuddyId + 1;
Integer groupId = -1;
for (GroupItem g : groups) {
for (GroupItem g : groups.values()) {
if ("Transport Buddies".equals(g.getGroupName())) {
groupId = g.getId();
}
......@@ -118,10 +128,10 @@ public class OSCARSession extends TransportSession {
public void removeContact(JID jid) {
Log.debug("removeContact called");
for (BuddyItem i : buddies) {
for (BuddyItem i : buddies.values()) {
if (i.getScreenname().equals(jid.getNode())) {
request(new DeleteItemsCmd(new SsiItem[] { i.toSsiItem() }));
buddies.remove(buddies.indexOf(i));
buddies.remove(i.getId());
}
}
}
......@@ -206,27 +216,62 @@ public class OSCARSession extends TransportSession {
snacMgr.unregister(conn);
}
/**
* We've been told about a buddy that exists on the buddy list.
*
* @param buddy The buddy we've been told about.
*/
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.");
}
Log.debug("Found buddy item: " + buddy.toString());
buddies.put(buddy.getId(), buddy);
if (buddy.getId() > highestBuddyId) {
highestBuddyId = buddy.getId();
}
}
/**
* We've been told about a group that exists on the buddy list.
*
* @param group The group we've been told about.
*/
void gotGroup(GroupItem group) {
groups.add(group);
Log.debug("Found group item: " + group.toString());
groups.put(group.getId(), group);
if (group.getId() > highestGroupId) {
highestGroupId = group.getId();
}
}
/**
* Apparantly we now have the entire list, lets sync.
*/
void gotCompleteSSI() {
List<TransportBuddy> legacyusers = new ArrayList<TransportBuddy>();
for (BuddyItem buddy : buddies.values()) {
Log.debug("CompleteSSI: adding "+buddy.getScreenname());
String nickname = buddy.getAlias();
if (nickname == null) {
nickname = buddy.getScreenname();
}
int groupid = buddy.getGroupId();
String groupname = groups.get(groupid).getGroupName();
legacyusers.add(new TransportBuddy(buddy.getScreenname(), nickname, groupname));
}
try {
getTransport().syncLegacyRoster(getJID(), legacyusers);
}
catch (UserNotFoundException e) {
Log.error("Unable to sync oscar contact list for " + getJID());
}
}
/**
* Asks for transport to send information about a contact if possible.
*
* @param jid JID of contact to be probed.
*/
public void retrieveContactStatus(JID jid) {
bosConn.getAndSendStatus(jid.getNode());
}
}
......@@ -11,14 +11,21 @@
package org.jivesoftware.wildfire.gateway.protocols.yahoo;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.List;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportBuddy;
import org.jivesoftware.wildfire.gateway.TransportSession;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
import ymsg.network.LoginRefusedException;
import ymsg.network.Session;
import ymsg.network.StatusConstants;
import ymsg.network.YahooGroup;
import ymsg.network.YahooUser;
/**
......@@ -129,13 +136,70 @@ public class YahooSession extends TransportSession {
* Syncs up the yahoo roster with the jabber roster.
*/
public void syncUsers() {
for(YahooUser user : (Collection<YahooUser>)yahooSession.getUsers().values()) {
List<TransportBuddy> legacyusers = new ArrayList<TransportBuddy>();
for (YahooGroup group : yahooSession.getGroups()) {
for (Enumeration e = group.getMembers().elements(); e.hasMoreElements();) {
YahooUser user = (YahooUser)e.nextElement();
legacyusers.add(new TransportBuddy(user.getId(), user.getId(), group.getName()));
}
}
try {
getTransport().addOrUpdateRosterItem(getJID(), user.getId(), user.getId(), null);
getTransport().syncLegacyRoster(getJID(), legacyusers);
}
catch (UserNotFoundException e) {
Log.error("Unable to sync yahoo contact list for " + getJID());
}
// Ok, now lets check presence
for (YahooUser user : (Collection<YahooUser>)yahooSession.getUsers().values()) {
Presence p = new Presence();
p.setTo(getJID());
p.setFrom(getTransport().convertIDToJID(user.getId()));
String custommsg = user.getCustomStatusMessage();
if (custommsg != null) {
p.setStatus(custommsg);
}
long statusid = 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);
}
catch (Exception e) {
// TODO: Failed for some reason.
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);
}
}
......@@ -184,4 +248,61 @@ public class YahooSession extends TransportSession {
}
}
/**
* Asks for transport to send information about a contact if possible.
*
* @param jid JID of contact to be probed.
*/
public void retrieveContactStatus(JID jid) {
YahooUser user = yahooSession.getUser(jid.getNode());
Presence p = new Presence();
p.setTo(getJID());
p.setFrom(getTransport().convertIDToJID(user.getId()));
String custommsg = user.getCustomStatusMessage();
if (custommsg != null) {
p.setStatus(custommsg);
}
long statusid = 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);
}
}
......@@ -12,6 +12,8 @@ package org.jivesoftware.wildfire.gateway.protocols.yahoo;
import org.jivesoftware.util.Log;
import org.xmpp.packet.Message;
import org.xmpp.packet.Presence;
import ymsg.network.YahooUser;
import ymsg.network.event.SessionChatEvent;
import ymsg.network.event.SessionConferenceEvent;
import ymsg.network.event.SessionErrorEvent;
......@@ -22,6 +24,7 @@ import ymsg.network.event.SessionFriendEvent;
import ymsg.network.event.SessionListener;
import ymsg.network.event.SessionNewMailEvent;
import ymsg.network.event.SessionNotifyEvent;
import ymsg.network.StatusConstants;
import ymsg.support.MessageDecoder;
/**
......@@ -57,7 +60,6 @@ public class YahooSessionListener implements SessionListener {
* @see ymsg.network.event.SessionListener#messageReceived(ymsg.network.event.SessionEvent)
*/
public void messageReceived(SessionEvent event) {
Log.debug(event.toString());
Message m = new Message();
m.setType(Message.Type.chat);
m.setTo(yahooSession.getJID());
......@@ -66,6 +68,81 @@ public class YahooSessionListener implements SessionListener {
yahooSession.getTransport().sendPacket(m);
}
/**
* @see ymsg.network.event.SessionListener#friendsUpdateReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendsUpdateReceived(SessionFriendEvent event) {
for (YahooUser user : event.getFriends()) {
Presence p = new Presence();
p.setTo(yahooSession.getJID());
p.setFrom(yahooSession.getTransport().convertIDToJID(event.getFrom()));
String custommsg = user.getCustomStatusMessage();
if (custommsg != null) {
p.setStatus(custommsg);
}
long statusid = 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.
}
yahooSession.getTransport().sendPacket(p);
}
}
/**
* @see ymsg.network.event.SessionListener#friendAddedReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendAddedReceived(SessionFriendEvent event) {
Presence p = new Presence(Presence.Type.subscribed);
p.setTo(yahooSession.getJID());
p.setFrom(yahooSession.getTransport().convertIDToJID(event.getFrom()));
yahooSession.getTransport().sendPacket(p);
}
/**
* @see ymsg.network.event.SessionListener#friendRemovedReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendRemovedReceived(SessionFriendEvent event) {
Presence p = new Presence(Presence.Type.unsubscribed);
p.setTo(yahooSession.getJID());
p.setFrom(yahooSession.getTransport().convertIDToJID(event.getFrom()));
yahooSession.getTransport().sendPacket(p);
}
/**
* @see ymsg.network.event.SessionListener#fileTransferReceived(ymsg.network.event.SessionFileTransferEvent)
......@@ -180,27 +257,6 @@ public class YahooSessionListener implements SessionListener {
Log.debug(event.toString());
}
/**
* @see ymsg.network.event.SessionListener#friendsUpdateReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendsUpdateReceived(SessionFriendEvent event) {
Log.debug(event.toString());
}
/**
* @see ymsg.network.event.SessionListener#friendAddedReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendAddedReceived(SessionFriendEvent event) {
Log.debug(event.toString());
}
/**
* @see ymsg.network.event.SessionListener#friendRemovedReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendRemovedReceived(SessionFriendEvent event) {
Log.debug(event.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatLogonReceived(ymsg.network.event.SessionChatEvent)
*/
......
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