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

Lots more work on MSN. Mostly funcional. Some contact list issues pending.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@4953 b35dd754-fafc-0310-a699-88a17e54d16e
parent 8c7aee5a
...@@ -329,7 +329,10 @@ public abstract class BaseTransport implements Component { ...@@ -329,7 +329,10 @@ public abstract class BaseTransport implements Component {
reply.addAll(handleIQVersion(packet)); reply.addAll(handleIQVersion(packet));
} }
else { else {
Log.debug("Unabled iq request:" + xmlns); Log.debug("Unable to handle iq request:" + xmlns);
IQ error = IQ.createResultIQ(packet);
error.setError(Condition.bad_request);
reply.add(error);
} }
return reply; return reply;
......
...@@ -19,6 +19,8 @@ import net.sf.jml.MsnContact; ...@@ -19,6 +19,8 @@ import net.sf.jml.MsnContact;
import net.sf.jml.MsnMessenger; import net.sf.jml.MsnMessenger;
import net.sf.jml.message.MsnInstantMessage; import net.sf.jml.message.MsnInstantMessage;
import java.util.Date;
/** /**
* MSN Listener Interface. * MSN Listener Interface.
* *
...@@ -44,7 +46,7 @@ public class MSNListener extends MsnAdapter { ...@@ -44,7 +46,7 @@ public class MSNListener extends MsnAdapter {
public MSNSession msnSession = null; public MSNSession msnSession = null;
/** /**
* Handles incoming messages from MSN. * Handles incoming messages from MSN users.
*/ */
public void instantMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message, MsnContact friend) { public void instantMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message, MsnContact friend) {
Log.debug("MSN: Received im to " + switchboard + " from " + friend + ": " + message.getContent()); Log.debug("MSN: Received im to " + switchboard + " from " + friend + ": " + message.getContent());
...@@ -56,6 +58,18 @@ public class MSNListener extends MsnAdapter { ...@@ -56,6 +58,18 @@ public class MSNListener extends MsnAdapter {
msnSession.getTransport().sendPacket(m); msnSession.getTransport().sendPacket(m);
} }
/**
* Handles incoming system messages from MSN.
*/
public void systemMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message) {
Log.debug("MSN: Received system msg to " + switchboard + " from MSN: " + message.getContent());
Message m = new Message();
m.setType(Message.Type.chat);
m.setTo(msnSession.getJIDWithHighestPriority());
m.setFrom(msnSession.getTransport().getJID());
m.setBody(message.getContent());
msnSession.getTransport().sendPacket(m);
}
/** /**
* The user's login has completed and was accepted. * The user's login has completed and was accepted.
...@@ -66,6 +80,31 @@ public class MSNListener extends MsnAdapter { ...@@ -66,6 +80,31 @@ public class MSNListener extends MsnAdapter {
p.setTo(msnSession.getJID()); p.setTo(msnSession.getJID());
p.setFrom(msnSession.getTransport().getJID()); p.setFrom(msnSession.getTransport().getJID());
msnSession.getTransport().sendPacket(p); msnSession.getTransport().sendPacket(p);
msnSession.getRegistration().setLastLogin(new Date());
msnSession.setLoginStatus(true);
}
/**
* Contact list has been synced.
*/
public void contactListSyncCompleted(MsnMessenger messenger) {
for (MsnContact msnContact : messenger.getContactList().getContacts()) {
msnSession.storeFriend(msnContact);
}
msnSession.syncUsers();
}
/**
* A friend for this user has changed status.
*/
public void contactStatusChanged(MsnMessenger messenger, MsnContact friend) {
Presence p = new Presence();
p.setTo(msnSession.getJID());
p.setFrom(msnSession.getTransport().convertIDToJID(friend.getEmail().toString()));
((MSNTransport)msnSession.getTransport()).setUpPresencePacket(p, friend.getStatus());
msnSession.getTransport().sendPacket(p);
} }
} }
...@@ -10,17 +10,21 @@ ...@@ -10,17 +10,21 @@
package org.jivesoftware.wildfire.gateway.protocols.msn; package org.jivesoftware.wildfire.gateway.protocols.msn;
import java.util.Date; import net.sf.jml.*;
import net.sf.jml.MsnMessenger;
import net.sf.jml.MsnProtocol;
import net.sf.jml.Email;
import net.sf.jml.impl.MsnMessengerFactory; import net.sf.jml.impl.MsnMessengerFactory;
import org.jivesoftware.wildfire.gateway.PresenceType; 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.jivesoftware.wildfire.gateway.TransportBuddy;
import org.jivesoftware.wildfire.user.UserNotFoundException;
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;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
/** /**
* Represents a MSN session. * Represents a MSN session.
* *
...@@ -51,6 +55,11 @@ public class MSNSession extends TransportSession { ...@@ -51,6 +55,11 @@ public class MSNSession extends TransportSession {
*/ */
private MsnMessenger msnMessenger = null; private MsnMessenger msnMessenger = null;
/**
* MSN contacts/friends.
*/
private HashMap<String,MsnContact> msnContacts = new HashMap<String,MsnContact>();
/** /**
* Login status * Login status
*/ */
...@@ -69,15 +78,6 @@ public class MSNSession extends TransportSession { ...@@ -69,15 +78,6 @@ public class MSNSession extends TransportSession {
msnMessenger.setLogOutgoing(true); msnMessenger.setLogOutgoing(true);
msnMessenger.addListener(new MSNListener(this)); msnMessenger.addListener(new MSNListener(this));
msnMessenger.login(); msnMessenger.login();
Presence p = new Presence();
p.setTo(getJID());
p.setFrom(getTransport().getJID());
getTransport().sendPacket(p);
getRegistration().setLastLogin(new Date());
loginStatus = true;
} }
} }
...@@ -109,11 +109,55 @@ public class MSNSession extends TransportSession { ...@@ -109,11 +109,55 @@ public class MSNSession extends TransportSession {
return loginStatus; return loginStatus;
} }
/**
* Sets login status flag (am i logged in or not)
*/
public void setLoginStatus(Boolean status) {
loginStatus = status;
}
/**
* Records information about a person on the user's contact list.
*/
public void storeFriend(MsnContact msnContact) {
msnContacts.put(msnContact.getEmail().toString(), msnContact);
}
/**
* Syncs up the MSN roster with the jabber roster.
*/
public void syncUsers() {
List<TransportBuddy> legacyusers = new ArrayList<TransportBuddy>();
for (MsnContact friend : msnContacts.values()) {
ArrayList<String> friendGroups = new ArrayList<String>();
for (MsnGroup group : friend.getBelongGroups()) {
friendGroups.add(group.getGroupName());
}
legacyusers.add(new TransportBuddy(friend.getEmail().toString(), friend.getDisplayName(), friendGroups.get(0)));
}
try {
getTransport().syncLegacyRoster(getJID(), legacyusers);
}
catch (UserNotFoundException e) {
Log.error("Unable to sync MSN contact list for " + getJID());
}
// Lets send initial presence statuses
for (MsnContact friend : msnContacts.values()) {
Presence p = new Presence();
p.setTo(getJID());
p.setFrom(getTransport().convertIDToJID(friend.getEmail().toString()));
((MSNTransport)getTransport()).setUpPresencePacket(p, friend.getStatus());
getTransport().sendPacket(p);
}
}
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#addContact(org.xmpp.packet.JID) * @see org.jivesoftware.wildfire.gateway.TransportSession#addContact(org.xmpp.packet.JID)
*/ */
public void addContact(JID jid) { public void addContact(JID jid) {
// @todo check jabber group and use it // @todo check jabber group and use it
msnMessenger.addFriend(Email.parseStr(getTransport().convertJIDToID(jid)), getTransport().convertJIDToID(jid));
} }
/** /**
...@@ -121,6 +165,7 @@ public class MSNSession extends TransportSession { ...@@ -121,6 +165,7 @@ public class MSNSession extends TransportSession {
*/ */
public void removeContact(JID jid) { public void removeContact(JID jid) {
// @todo check jabber group and use it // @todo check jabber group and use it
msnMessenger.removeFriend(Email.parseStr(getTransport().convertJIDToID(jid)), false);
} }
/** /**
...@@ -134,21 +179,35 @@ public class MSNSession extends TransportSession { ...@@ -134,21 +179,35 @@ public class MSNSession extends TransportSession {
* @see org.jivesoftware.wildfire.gateway.TransportSession#retrieveContactStatus(org.xmpp.packet.JID) * @see org.jivesoftware.wildfire.gateway.TransportSession#retrieveContactStatus(org.xmpp.packet.JID)
*/ */
public void retrieveContactStatus(JID jid) { public void retrieveContactStatus(JID jid) {
// @todo need to implement this MsnContact msnContact = msnContacts.get(getTransport().convertJIDToID(jid));
if (msnContact == null) {
return;
}
Presence p = new Presence();
p.setTo(getJID());
p.setFrom(getTransport().convertIDToJID(msnContact.getEmail().toString()));
((MSNTransport)getTransport()).setUpPresencePacket(p, msnContact.getStatus());
getTransport().sendPacket(p);
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#updateStatus(org.jivesoftware.wildfire.gateway.PresenceType, String) * @see org.jivesoftware.wildfire.gateway.TransportSession#updateStatus(org.jivesoftware.wildfire.gateway.PresenceType, String)
*/ */
public void updateStatus(PresenceType presenceType, String verboseStatus) { public void updateStatus(PresenceType presenceType, String verboseStatus) {
// @todo need to implement this msnMessenger.getOwner().setStatus(((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType));
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#resendContactStatuses(org.xmpp.packet.JID) * @see org.jivesoftware.wildfire.gateway.TransportSession#resendContactStatuses(org.xmpp.packet.JID)
*/ */
public void resendContactStatuses(JID jid) { public void resendContactStatuses(JID jid) {
// @todo need to implement this for (MsnContact friend : msnContacts.values()) {
Presence p = new Presence();
p.setTo(getJID());
p.setFrom(getTransport().convertIDToJID(friend.getEmail().toString()));
((MSNTransport)getTransport()).setUpPresencePacket(p, friend.getStatus());
getTransport().sendPacket(p);
}
} }
} }
...@@ -91,7 +91,7 @@ public class MSNTransport extends BaseTransport { ...@@ -91,7 +91,7 @@ public class MSNTransport extends BaseTransport {
* *
* @param msnStatus MSN ContactStatus constant. * @param msnStatus MSN ContactStatus constant.
*/ */
public void setUpPresencePacket(Presence packet, String msnStatus) { public void setUpPresencePacket(Presence packet, MsnUserStatus msnStatus) {
if (msnStatus.equals(MsnUserStatus.ONLINE)) { if (msnStatus.equals(MsnUserStatus.ONLINE)) {
// We're good, send as is.. // We're good, send as is..
} }
......
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