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

Functional is better than just lacking ability to remove buddies......

Functional is better than just lacking ability to remove buddies... backtracking to jml and may reevaluate others later or put more work into jml.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@5377 b35dd754-fafc-0310-a699-88a17e54d16e
parent da912e14
......@@ -10,16 +10,21 @@
package org.jivesoftware.wildfire.gateway.protocols.msn;
import org.jivesoftware.util.Log;
import org.xmpp.packet.Message;
import org.xmpp.packet.Presence;
import net.sf.jml.event.MsnAdapter;
import net.sf.jml.MsnSwitchboard;
import net.sf.jml.MsnContact;
import net.sf.jml.MsnMessenger;
import net.sf.jml.MsnGroup;
import net.sf.jml.message.MsnInstantMessage;
import net.sf.jml.message.MsnControlMessage;
import net.sf.jml.message.MsnDatacastMessage;
import net.sf.jml.message.MsnUnknownMessage;
import java.util.Date;
import rath.msnm.event.MsnAdapter;
import rath.msnm.SwitchboardSession;
import rath.msnm.msg.MimeMessage;
import rath.msnm.entity.MsnFriend;
/**
* MSN Listener Interface.
*
......@@ -47,25 +52,153 @@ public class MSNListener extends MsnAdapter {
/**
* Handles incoming messages from MSN users.
*/
public void instantMessageReceived(SwitchboardSession switchboard, MsnFriend friend, MimeMessage message) {
public void instantMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message, MsnContact friend) {
Message m = new Message();
m.setType(Message.Type.chat);
m.setTo(msnSession.getJIDWithHighestPriority());
m.setFrom(msnSession.getTransport().convertIDToJID(friend.getLoginName()));
m.setBody(message.getMessage());
m.setFrom(msnSession.getTransport().convertIDToJID(friend.getEmail().toString()));
m.setBody(message.getContent());
msnSession.getTransport().sendPacket(m);
}
/**
* Handles incoming system messages from MSN.
*/
public void systemMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message) {
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);
}
/**
* Handles incoming control messages from MSN.
*/
public void controlMessageReceived(MsnSwitchboard switchboard, MsnControlMessage message, MsnContact friend) {
Log.debug("MSN: Received control msg to " + switchboard + " from " + friend + ": " + message);
}
/**
* Handles incoming datacast messages from MSN.
*/
public void datacastMessageReceived(MsnSwitchboard switchboard, MsnDatacastMessage message, MsnContact friend) {
Log.debug("MSN: Received datacast message to " + switchboard + " from " + friend + ": " + message);
}
/**
* Handles incoming unknown messages from MSN.
*/
public void unknownMessageReceived(MsnSwitchboard switchboard, MsnUnknownMessage message, MsnContact friend) {
Log.debug("MSN: Received unknown message to " + switchboard + " from " + friend + ": " + message);
}
/**
* The user's login has completed and was accepted.
*/
public void loginComplete(MsnFriend me) {
public void loginCompleted(MsnMessenger messenger) {
msnSession.getRegistration().setLastLogin(new Date());
msnSession.setLoginStatus(true);
}
/**
* Contact list initialization has completed.
*/
public void contactListInitCompleted(MsnMessenger messenger) {
}
/**
* Contact list has been synced.
*/
public void contactListSyncCompleted(MsnMessenger messenger) {
for (MsnContact msnContact : messenger.getContactList().getContacts()) {
Log.debug("Got contact "+msnContact);
msnSession.storeFriend(msnContact);
}
for (MsnGroup msnGroup : messenger.getContactList().getGroups()) {
msnSession.storeGroup(msnGroup);
}
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);
msnSession.storeFriend(friend);
}
/**
* Owner status has changed.
*/
public void ownerStatusChanged(MsnMessenger messenger) {
Presence p = new Presence();
p.setTo(msnSession.getJID());
p.setFrom(msnSession.getTransport().getJID());
((MSNTransport)msnSession.getTransport()).setUpPresencePacket(p, messenger.getOwner().getStatus());
msnSession.getTransport().sendPacket(p);
}
/**
* Catches MSN exceptions.
*/
public void exceptionCaught(MsnMessenger messenger, Throwable throwable) {
if (throwable.getClass().getName().equals("net.sf.jml.exception.IncorrectPasswordException")) {
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority());
m.setFrom(msnSession.getTransport().getJID());
m.setBody("The password you registered with is incorrect. Please re-register with the correct password.");
msnSession.getTransport().sendPacket(m);
msnSession.logOut();
}
else if (throwable.getClass().getName().equals("net.sf.jml.exception.MsnProtocolException")) {
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority());
m.setFrom(msnSession.getTransport().getJID());
m.setBody("MSN error: "+throwable.toString());
msnSession.getTransport().sendPacket(m);
}
else if (throwable.getClass().getName().equals("net.sf.jml.exception.MsgNotSendException")) {
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority());
m.setFrom(msnSession.getTransport().getJID());
m.setBody("Unable to send MSN message. Reason: "+throwable.toString());
msnSession.getTransport().sendPacket(m);
}
else if (throwable.getClass().getName().equals("net.sf.jml.exception.UnknownMessageException")) {
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority());
m.setFrom(msnSession.getTransport().getJID());
m.setBody("Unknown message from MSN: "+throwable.toString());
msnSession.getTransport().sendPacket(m);
}
else if (throwable.getClass().getName().equals("net.sf.jml.exception.UnsupportedProtocolException")) {
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority());
m.setFrom(msnSession.getTransport().getJID());
m.setBody("MSN protocol error: "+throwable.toString());
msnSession.getTransport().sendPacket(m);
}
else {
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(msnSession.getJIDWithHighestPriority());
m.setFrom(msnSession.getTransport().getJID());
m.setBody("Unknown error from MSN: "+throwable.toString());
throwable.printStackTrace();
msnSession.getTransport().sendPacket(m);
}
}
}
......@@ -18,7 +18,7 @@ import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportSession;
import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
import rath.msnm.UserStatus;
import net.sf.jml.MsnUserStatus;
/**
* MSN Transport Interface.
......@@ -101,27 +101,27 @@ public class MSNTransport extends BaseTransport {
*
* @param jabStatus Jabber presence type.
*/
public String convertJabStatusToMSN(PresenceType jabStatus) {
public MsnUserStatus convertJabStatusToMSN(PresenceType jabStatus) {
if (jabStatus == PresenceType.available) {
return UserStatus.ONLINE;
return MsnUserStatus.ONLINE;
}
else if (jabStatus == PresenceType.away) {
return UserStatus.AWAY_FROM_COMPUTER;
return MsnUserStatus.AWAY;
}
else if (jabStatus == PresenceType.xa) {
return UserStatus.AWAY_FROM_COMPUTER;
return MsnUserStatus.AWAY;
}
else if (jabStatus == PresenceType.dnd) {
return UserStatus.BUSY;
return MsnUserStatus.BUSY;
}
else if (jabStatus == PresenceType.chat) {
return UserStatus.ONLINE;
return MsnUserStatus.ONLINE;
}
else if (jabStatus == PresenceType.unavailable) {
return UserStatus.OFFLINE;
return MsnUserStatus.OFFLINE;
}
else {
return UserStatus.ONLINE;
return MsnUserStatus.ONLINE;
}
}
......@@ -130,29 +130,29 @@ public class MSNTransport extends BaseTransport {
*
* @param msnStatus MSN ContactStatus constant.
*/
public void setUpPresencePacket(Presence packet, String msnStatus) {
if (msnStatus.equals(UserStatus.ONLINE)) {
public void setUpPresencePacket(Presence packet, MsnUserStatus msnStatus) {
if (msnStatus.equals(MsnUserStatus.ONLINE)) {
// We're good, send as is..
}
else if (msnStatus.equals(UserStatus.AWAY_FROM_COMPUTER)) {
else if (msnStatus.equals(MsnUserStatus.AWAY)) {
packet.setShow(Presence.Show.away);
}
else if (msnStatus.equals(UserStatus.BE_RIGHT_BACK)) {
else if (msnStatus.equals(MsnUserStatus.BE_RIGHT_BACK)) {
packet.setShow(Presence.Show.away);
}
else if (msnStatus.equals(UserStatus.BUSY)) {
else if (msnStatus.equals(MsnUserStatus.BUSY)) {
packet.setShow(Presence.Show.dnd);
}
else if (msnStatus.equals(UserStatus.IDLE)) {
else if (msnStatus.equals(MsnUserStatus.IDLE)) {
packet.setShow(Presence.Show.away);
}
else if (msnStatus.equals(UserStatus.OFFLINE)) {
else if (msnStatus.equals(MsnUserStatus.OFFLINE)) {
packet.setType(Presence.Type.unavailable);
}
else if (msnStatus.equals(UserStatus.ON_THE_PHONE)) {
else if (msnStatus.equals(MsnUserStatus.ON_THE_PHONE)) {
packet.setShow(Presence.Show.dnd);
}
else if (msnStatus.equals(UserStatus.ON_THE_LUNCH)) {
else if (msnStatus.equals(MsnUserStatus.OUT_TO_LUNCH)) {
packet.setShow(Presence.Show.xa);
}
}
......
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