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

[GATE-13] Added typing notification/chat state support (thanks to nikitine for most the work!)

Reworked most of protocol code to use helper/wrapper functions.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6306 b35dd754-fafc-0310-a699-88a17e54d16e
parent 3f067a1d
...@@ -121,6 +121,8 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -121,6 +121,8 @@ public abstract class BaseTransport implements Component, RosterEventListener {
private final String IQ_REGISTER = "jabber:iq:register"; private final String IQ_REGISTER = "jabber:iq:register";
private final String IQ_REGISTERED = "jabber:iq:registered"; private final String IQ_REGISTERED = "jabber:iq:registered";
private final String IQ_VERSION = "jabber:iq:version"; private final String IQ_VERSION = "jabber:iq:version";
private final String CHATSTATES = "http://jabber.org/protocol/chatstates";
private final String XEVENT = "jabber:x:event";
/** /**
* Handles all incoming XMPP stanzas, passing them to individual * Handles all incoming XMPP stanzas, passing them to individual
...@@ -187,6 +189,36 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -187,6 +189,36 @@ public abstract class BaseTransport implements Component, RosterEventListener {
if (packet.getBody() != null) { if (packet.getBody() != null) {
session.sendMessage(to, packet.getBody()); session.sendMessage(to, packet.getBody());
} }
else {
// Checking for XEP-0022 message events
Element eEvent = packet.getChildElement("x", XEVENT);
if (eEvent != null) {
if (eEvent.element("composing") != null) {
session.sendChatState(to, ChatStateType.composing);
}
else {
session.sendChatState(to, ChatStateType.paused);
}
}
else {
// Ok then, lets check for XEP-0085 chat states
if (packet.getChildElement("composing", CHATSTATES) != null) {
session.sendChatState(to, ChatStateType.composing);
}
else if (packet.getChildElement("active", CHATSTATES) != null) {
session.sendChatState(to, ChatStateType.active);
}
else if (packet.getChildElement("inactive", CHATSTATES) != null) {
session.sendChatState(to, ChatStateType.inactive);
}
else if (packet.getChildElement("paused", CHATSTATES) != null) {
session.sendChatState(to, ChatStateType.paused);
}
else if (packet.getChildElement("gone", CHATSTATES) != null) {
session.sendChatState(to, ChatStateType.gone);
}
}
}
} }
} }
catch (NotFoundException e) { catch (NotFoundException e) {
...@@ -1407,6 +1439,12 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -1407,6 +1439,12 @@ public abstract class BaseTransport implements Component, RosterEventListener {
m.setFrom(from); m.setFrom(from);
m.setTo(to); m.setTo(to);
m.setBody(msg); m.setBody(msg);
if (type.equals(Message.Type.chat) || type.equals(Message.Type.normal)) {
Element xEvent = m.addChildElement("x", "jabber:x:event");
xEvent.addElement("id");
xEvent.addElement("composing");
m.addChildElement("active", CHATSTATES);
}
sendPacket(m); sendPacket(m);
} }
...@@ -1425,18 +1463,70 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -1425,18 +1463,70 @@ public abstract class BaseTransport implements Component, RosterEventListener {
* Sends a typing notification the component manager. * Sends a typing notification the component manager.
* *
* This will check whether the person supports typing notifications before sending. * This will check whether the person supports typing notifications before sending.
* TODO: actually check for typing notification support
* *
* @param to Who the notification is for. * @param to Who the notification is for.
* @param from Who the notification is from. * @param from Who the notification is from.
*/ */
public void sendTypingNotification(JID to, JID from) { public void sendComposingNotification(JID to, JID from) {
Message m = new Message(); Message m = new Message();
m.setTo(to); m.setTo(to);
m.setFrom(from); m.setFrom(from);
Element xEvent = m.addChildElement("x", "jabber:x:event"); Element xEvent = m.addChildElement("x", "jabber:x:event");
xEvent.addElement("id"); xEvent.addElement("id");
xEvent.addElement("composing"); xEvent.addElement("composing");
m.addChildElement("composing", CHATSTATES);
sendPacket(m);
}
/**
* Sends a typing paused notification the component manager.
*
* This will check whether the person supports typing notifications before sending.
* TODO: actually check for typing notification support
*
* @param to Who the notification is for.
* @param from Who the notification is from.
*/
public void sendComposingPausedNotification(JID to, JID from) {
Message m = new Message();
m.setTo(to);
m.setFrom(from);
m.addChildElement("paused", CHATSTATES);
sendPacket(m);
}
/**
* Sends an inactive chat session notification the component manager.
*
* This will check whether the person supports typing notifications before sending.
* TODO: actually check for typing notification support
*
* @param to Who the notification is for.
* @param from Who the notification is from.
*/
public void sendChatInactiveNotification(JID to, JID from) {
Message m = new Message();
m.setTo(to);
m.setFrom(from);
m.addChildElement("inactive", CHATSTATES);
sendPacket(m);
}
/**
* Sends a gone chat session notification the component manager.
*
* This will check whether the person supports typing notifications before sending.
* TODO: actually check for typing notification support
*
* @param to Who the notification is for.
* @param from Who the notification is from.
*/
public void sendChatGoneNotification(JID to, JID from) {
Message m = new Message();
m.setTo(to);
m.setFrom(from);
m.addChildElement("gone", CHATSTATES);
sendPacket(m); sendPacket(m);
} }
......
/**
* $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;
/**
* An enumeration for different chat state types.
*
* This class contains a list of all of the possible chat states.
*
* @author Daniel Henninger
*/
public enum ChatStateType {
/**
* Active (user is actively participating in a conversation)
*/
active,
/**
* Composing (user is currently composing a message)
*/
composing,
/**
* Paused (user has paused while composing a message)
*/
paused,
/**
* Inactive (user has not interacted with the chat session for a short period of time)
*/
inactive,
/**
* Gone (user has not interacted with the chat session for a long period of time)
*/
gone
}
...@@ -431,7 +431,7 @@ public abstract class TransportSession implements Runnable { ...@@ -431,7 +431,7 @@ public abstract class TransportSession implements Runnable {
public abstract void updateContact(RosterItem item); public abstract void updateContact(RosterItem item);
/** /**
* Sends an outgoing message through the legacy serivce. * Sends an outgoing message through the legacy service.
* *
* @param jid JID associated with the target contact. * @param jid JID associated with the target contact.
* @param message Message to be sent. * @param message Message to be sent.
...@@ -439,7 +439,7 @@ public abstract class TransportSession implements Runnable { ...@@ -439,7 +439,7 @@ public abstract class TransportSession implements Runnable {
public abstract void sendMessage(JID jid, String message); public abstract void sendMessage(JID jid, String message);
/** /**
* Sends an outgoing message directly to the legacy serivce. * Sends an outgoing message directly to the legacy service.
* *
* Doesn't -have- to do anything. Only occasionally useful. * Doesn't -have- to do anything. Only occasionally useful.
* *
...@@ -447,6 +447,17 @@ public abstract class TransportSession implements Runnable { ...@@ -447,6 +447,17 @@ public abstract class TransportSession implements Runnable {
*/ */
public abstract void sendServerMessage(String message); public abstract void sendServerMessage(String message);
/**
* Sends a chat state message through the legacy service.
*
* Not all chat states have to be handled. Note that composing message event
* is sent through this as well. (XEP-0022) Primarily this is used with XEP-0085.
*
* @param jid JID associated with the target contact.
* @param chatState Chat state to be reflected in the legacy service.
*/
public abstract void sendChatState(JID jid, ChatStateType chatState);
/** /**
* Asks the legacy service to send a presence packet for a contact. * Asks the legacy service to send a presence packet for a contact.
* *
......
...@@ -94,23 +94,23 @@ public class IRCListener implements IRCEventListener { ...@@ -94,23 +94,23 @@ public class IRCListener implements IRCEventListener {
public void onError(String string) { public void onError(String string) {
Log.debug("IRC error: "+string); Log.debug("IRC error: "+string);
if (silenced) { return; } if (silenced) { return; }
Message m = new Message(); getSession().getTransport().sendMessage(
m.setType(Message.Type.error); getSession().getJID(),
m.setFrom(getSession().getTransport().getJID()); getSession().getTransport().getJID(),
m.setTo(getSession().getJID()); "IRC error received: "+string,
m.setBody("IRC error received: "+string); Message.Type.error
getSession().getTransport().sendPacket(m); );
} }
public void onError(int i, String string) { public void onError(int i, String string) {
Log.debug("IRC error: "+i+", "+string); Log.debug("IRC error: "+i+", "+string);
if (silenced) { return; } if (silenced) { return; }
Message m = new Message(); getSession().getTransport().sendMessage(
m.setType(Message.Type.error); getSession().getJID(),
m.setFrom(getSession().getTransport().getJID()); getSession().getTransport().getJID(),
m.setTo(getSession().getJID()); "IRC error received: (code "+i+") "+string,
m.setBody("IRC error received: (code "+i+") "+string); Message.Type.error
getSession().getTransport().sendPacket(m); );
} }
public void onInvite(String string, IRCUser ircUser, String string1) { public void onInvite(String string, IRCUser ircUser, String string1) {
...@@ -151,12 +151,11 @@ public class IRCListener implements IRCEventListener { ...@@ -151,12 +151,11 @@ public class IRCListener implements IRCEventListener {
else { else {
from = getSession().getTransport().convertIDToJID(username); from = getSession().getTransport().convertIDToJID(username);
} }
Message m = new Message(); getSession().getTransport().sendMessage(
m.setType(Message.Type.chat); getSession().getJIDWithHighestPriority(),
m.setFrom(from); from,
m.setTo(getSession().getJIDWithHighestPriority()); string1
m.setBody(string1); );
getSession().getTransport().sendPacket(m);
} }
public void onPart(String string, IRCUser ircUser, String string1) { public void onPart(String string, IRCUser ircUser, String string1) {
...@@ -174,12 +173,11 @@ public class IRCListener implements IRCEventListener { ...@@ -174,12 +173,11 @@ public class IRCListener implements IRCEventListener {
// TODO: Investigate if I should respond to this. What do other clients do? // TODO: Investigate if I should respond to this. What do other clients do?
return; return;
} }
Message m = new Message(); getSession().getTransport().sendMessage(
m.setType(Message.Type.chat); getSession().getJIDWithHighestPriority(),
m.setFrom(getSession().getTransport().convertIDToJID(ircUser.getNick())); getSession().getTransport().convertIDToJID(ircUser.getNick()),
m.setTo(getSession().getJIDWithHighestPriority()); msg
m.setBody(msg); );
getSession().getTransport().sendPacket(m);
} }
public void onQuit(IRCUser ircUser, String string) { public void onQuit(IRCUser ircUser, String string) {
...@@ -211,12 +209,11 @@ public class IRCListener implements IRCEventListener { ...@@ -211,12 +209,11 @@ public class IRCListener implements IRCEventListener {
} }
} }
else { else {
Message m = new Message(); getSession().getTransport().sendMessage(
m.setType(Message.Type.chat); getSession().getJIDWithHighestPriority(),
m.setFrom(getSession().getTransport().getJID()); getSession().getTransport().getJID(),
m.setTo(getSession().getJIDWithHighestPriority()); string1
m.setBody(string1); );
getSession().getTransport().sendPacket(m);
} }
} }
......
...@@ -240,6 +240,13 @@ public class IRCSession extends TransportSession { ...@@ -240,6 +240,13 @@ public class IRCSession extends TransportSession {
conn.send(message); conn.send(message);
} }
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#sendChatState(org.xmpp.packet.JID, org.jivesoftware.wildfire.gateway.ChatStateType)
*/
public void sendChatState(JID jid, ChatStateType chatState) {
// IRC doesn't support this
}
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#retrieveContactStatus(org.xmpp.packet.JID) * @see org.jivesoftware.wildfire.gateway.TransportSession#retrieveContactStatus(org.xmpp.packet.JID)
*/ */
......
...@@ -51,12 +51,11 @@ public class MSNListener extends MsnAdapter { ...@@ -51,12 +51,11 @@ public class MSNListener extends MsnAdapter {
* Handles incoming messages from MSN users. * Handles incoming messages from MSN users.
*/ */
public void instantMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message, MsnContact friend) { public void instantMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message, MsnContact friend) {
Message m = new Message(); msnSession.getTransport().sendMessage(
m.setType(Message.Type.chat); msnSession.getJIDWithHighestPriority(),
m.setTo(msnSession.getJIDWithHighestPriority()); msnSession.getTransport().convertIDToJID(friend.getEmail().toString()),
m.setFrom(msnSession.getTransport().convertIDToJID(friend.getEmail().toString())); message.getContent()
m.setBody(message.getContent()); );
msnSession.getTransport().sendPacket(m);
} }
/** /**
...@@ -66,12 +65,11 @@ public class MSNListener extends MsnAdapter { ...@@ -66,12 +65,11 @@ public class MSNListener extends MsnAdapter {
* @param message MSN message. * @param message MSN message.
*/ */
public void systemMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message) { public void systemMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message) {
Message m = new Message(); msnSession.getTransport().sendMessage(
m.setType(Message.Type.chat); msnSession.getJIDWithHighestPriority(),
m.setTo(msnSession.getJIDWithHighestPriority()); msnSession.getTransport().getJID(),
m.setFrom(msnSession.getTransport().getJID()); message.getContent()
m.setBody(message.getContent()); );
msnSession.getTransport().sendPacket(m);
} }
/** /**
...@@ -227,15 +225,16 @@ public class MSNListener extends MsnAdapter { ...@@ -227,15 +225,16 @@ public class MSNListener extends MsnAdapter {
public void exceptionCaught(MsnMessenger messenger, Throwable throwable) { public void exceptionCaught(MsnMessenger messenger, Throwable throwable) {
Log.debug("MSN: Exception occurred for "+messenger.getOwner().getEmail()+" : "+throwable); Log.debug("MSN: Exception occurred for "+messenger.getOwner().getEmail()+" : "+throwable);
if (throwable.getClass().getName().equals("net.sf.jml.exception.IncorrectPasswordException")) { if (throwable.getClass().getName().equals("net.sf.jml.exception.IncorrectPasswordException")) {
Message m = new Message(); msnSession.getTransport().sendMessage(
m.setType(Message.Type.error); msnSession.getJIDWithHighestPriority(),
m.setTo(msnSession.getJIDWithHighestPriority()); msnSession.getTransport().getJID(),
m.setFrom(msnSession.getTransport().getJID()); "The password you registered with is incorrect. Please re-register with the correct password.",
m.setBody("The password you registered with is incorrect. Please re-register with the correct password."); Message.Type.error
msnSession.getTransport().sendPacket(m); );
msnSession.logOut(); msnSession.logOut();
} }
else if (throwable.getClass().getName().equals("net.sf.jml.exception.MsnProtocolException")) { else if (throwable.getClass().getName().equals("net.sf.jml.exception.MsnProtocolException")) {
Log.debug("MSN: Protocol exception: "+throwable.toString());
// Message m = new Message(); // Message m = new Message();
// m.setType(Message.Type.error); // m.setType(Message.Type.error);
// m.setTo(msnSession.getJIDWithHighestPriority()); // m.setTo(msnSession.getJIDWithHighestPriority());
...@@ -244,22 +243,24 @@ public class MSNListener extends MsnAdapter { ...@@ -244,22 +243,24 @@ public class MSNListener extends MsnAdapter {
// msnSession.getTransport().sendPacket(m); // msnSession.getTransport().sendPacket(m);
} }
else if (throwable.getClass().getName().equals("net.sf.jml.exception.MsgNotSendException")) { else if (throwable.getClass().getName().equals("net.sf.jml.exception.MsgNotSendException")) {
Message m = new Message(); msnSession.getTransport().sendMessage(
m.setType(Message.Type.error); msnSession.getJIDWithHighestPriority(),
m.setTo(msnSession.getJIDWithHighestPriority()); msnSession.getTransport().getJID(),
m.setFrom(msnSession.getTransport().getJID()); "Unable to send MSN message. Reason: "+throwable.toString(),
m.setBody("Unable to send MSN message. Reason: "+throwable.toString()); Message.Type.error
msnSession.getTransport().sendPacket(m); );
} }
else if (throwable.getClass().getName().equals("net.sf.jml.exception.UnknownMessageException")) { else if (throwable.getClass().getName().equals("net.sf.jml.exception.UnknownMessageException")) {
Message m = new Message(); Log.debug("MSN: Unknown message: "+throwable.toString());
m.setType(Message.Type.error); // Message m = new Message();
m.setTo(msnSession.getJIDWithHighestPriority()); // m.setType(Message.Type.error);
m.setFrom(msnSession.getTransport().getJID()); // m.setTo(msnSession.getJIDWithHighestPriority());
m.setBody("Unknown message from MSN: "+throwable.toString()); // m.setFrom(msnSession.getTransport().getJID());
msnSession.getTransport().sendPacket(m); // m.setBody("Unknown message from MSN: "+throwable.toString());
// msnSession.getTransport().sendPacket(m);
} }
else if (throwable.getClass().getName().equals("net.sf.jml.exception.UnsupportedProtocolException")) { else if (throwable.getClass().getName().equals("net.sf.jml.exception.UnsupportedProtocolException")) {
Log.debug("MSN: Protocol error: "+throwable.toString());
// Message m = new Message(); // Message m = new Message();
// m.setType(Message.Type.error); // m.setType(Message.Type.error);
// m.setTo(msnSession.getJIDWithHighestPriority()); // m.setTo(msnSession.getJIDWithHighestPriority());
...@@ -268,13 +269,14 @@ public class MSNListener extends MsnAdapter { ...@@ -268,13 +269,14 @@ public class MSNListener extends MsnAdapter {
// msnSession.getTransport().sendPacket(m); // msnSession.getTransport().sendPacket(m);
} }
else { else {
Message m = new Message(); Log.debug("MSN: Unknown error: "+throwable.toString());
m.setType(Message.Type.error); // Message m = new Message();
m.setTo(msnSession.getJIDWithHighestPriority()); // m.setType(Message.Type.error);
m.setFrom(msnSession.getTransport().getJID()); // m.setTo(msnSession.getJIDWithHighestPriority());
m.setBody("Unknown error from MSN: "+throwable.toString()); // m.setFrom(msnSession.getTransport().getJID());
throwable.printStackTrace(); // m.setBody("Unknown error from MSN: "+throwable.toString());
msnSession.getTransport().sendPacket(m); // throwable.printStackTrace();
// msnSession.getTransport().sendPacket(m);
} }
} }
......
...@@ -389,6 +389,13 @@ public class MSNSession extends TransportSession { ...@@ -389,6 +389,13 @@ public class MSNSession extends TransportSession {
// We don't care. // We don't care.
} }
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#sendChatState(org.xmpp.packet.JID, org.jivesoftware.wildfire.gateway.ChatStateType)
*/
public void sendChatState(JID jid, ChatStateType chatState) {
// TODO: Handle this
}
/** /**
* @see org.jivesoftware.wildfire.gateway.TransportSession#retrieveContactStatus(org.xmpp.packet.JID) * @see org.jivesoftware.wildfire.gateway.TransportSession#retrieveContactStatus(org.xmpp.packet.JID)
*/ */
......
...@@ -22,7 +22,6 @@ import org.xmpp.packet.Message; ...@@ -22,7 +22,6 @@ import org.xmpp.packet.Message;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
import org.dom4j.Element;
import net.kano.joscar.ByteBlock; import net.kano.joscar.ByteBlock;
import net.kano.joscar.OscarTools; import net.kano.joscar.OscarTools;
import net.kano.joscar.BinaryTools; import net.kano.joscar.BinaryTools;
...@@ -105,33 +104,32 @@ public abstract class BasicFlapConnection extends BaseFlapConnection { ...@@ -105,33 +104,32 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
InstantMessage message = icbm.getMessage(); InstantMessage message = icbm.getMessage();
String msg = OscarTools.stripHtml(message.getMessage()); String msg = OscarTools.stripHtml(message.getMessage());
Message m = new Message(); oscarSession.getTransport().sendMessage(
m.setTo(oscarSession.getJIDWithHighestPriority()); oscarSession.getJIDWithHighestPriority(),
m.setBody(msg); oscarSession.getTransport().convertIDToJID(sn),
m.setType(Message.Type.chat); msg
m.setFrom(this.oscarSession.getTransport().convertIDToJID(sn)); );
oscarSession.getTransport().sendPacket(m);
} }
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) {
Message m = new Message(); oscarSession.getTransport().sendMessage(
m.setTo(oscarSession.getJIDWithHighestPriority()); oscarSession.getJIDWithHighestPriority(),
m.setBody("You have received an anonymous AIM warning. Your warning level is now "+wn.getNewLevel()+"%."); oscarSession.getTransport().getJID(),
m.setType(Message.Type.headline); "You have received an anonymous AIM warning. Your warning level is now "+wn.getNewLevel()+"%.",
m.setFrom(this.oscarSession.getTransport().getJID()); Message.Type.headline
oscarSession.getTransport().sendPacket(m); );
} }
else { else {
Log.debug("*** " + warner.getScreenname() Log.debug("*** " + warner.getScreenname()
+ " warned you up to " + wn.getNewLevel() + "%"); + " warned you up to " + wn.getNewLevel() + "%");
Message m = new Message(); oscarSession.getTransport().sendMessage(
m.setTo(oscarSession.getJIDWithHighestPriority()); oscarSession.getJIDWithHighestPriority(),
m.setBody("You have received an AIM warning from "+warner.getScreenname()+". Your warning level is now "+wn.getNewLevel()+"%."); oscarSession.getTransport().getJID(),
m.setType(Message.Type.headline); "You have received an AIM warning from "+warner.getScreenname()+". Your warning level is now "+wn.getNewLevel()+"%.",
m.setFrom(this.oscarSession.getTransport().getJID()); Message.Type.headline
oscarSession.getTransport().sendPacket(m); );
} }
} }
else if (cmd instanceof BuddyStatusCmd) { else if (cmd instanceof BuddyStatusCmd) {
...@@ -172,20 +170,25 @@ public abstract class BasicFlapConnection extends BaseFlapConnection { ...@@ -172,20 +170,25 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
else if (cmd instanceof TypingCmd) { else if (cmd instanceof TypingCmd) {
TypingCmd tc = (TypingCmd) cmd; TypingCmd tc = (TypingCmd) cmd;
String sn = tc.getScreenname(); String sn = tc.getScreenname();
Message mTypingEvent = new Message();
mTypingEvent.setTo(oscarSession.getJIDWithHighestPriority());
mTypingEvent.setFrom(
oscarSession.getTransport().convertIDToJID(sn));
Element eEvent =
mTypingEvent.addChildElement("x", "jabber:x:event");
eEvent.addElement("id");
if (tc.getTypingState() == TypingCmd.STATE_TYPING) { if (tc.getTypingState() == TypingCmd.STATE_TYPING) {
eEvent.addElement("composing"); oscarSession.getTransport().sendComposingNotification(
oscarSession.getJIDWithHighestPriority(),
oscarSession.getTransport().convertIDToJID(sn)
);
}
else if (tc.getTypingState() == TypingCmd.STATE_PAUSED) {
oscarSession.getTransport().sendComposingPausedNotification(
oscarSession.getJIDWithHighestPriority(),
oscarSession.getTransport().convertIDToJID(sn)
);
}
else if (tc.getTypingState() == TypingCmd.STATE_NO_TEXT) {
oscarSession.getTransport().sendChatInactiveNotification(
oscarSession.getJIDWithHighestPriority(),
oscarSession.getTransport().convertIDToJID(sn)
);
} }
oscarSession.getTransport().sendPacket(mTypingEvent);
} }
} }
......
...@@ -23,6 +23,7 @@ import net.kano.joscar.snaccmd.ssi.CreateItemsCmd; ...@@ -23,6 +23,7 @@ import net.kano.joscar.snaccmd.ssi.CreateItemsCmd;
import net.kano.joscar.snaccmd.ssi.DeleteItemsCmd; import net.kano.joscar.snaccmd.ssi.DeleteItemsCmd;
import net.kano.joscar.snaccmd.ssi.ModifyItemsCmd; import net.kano.joscar.snaccmd.ssi.ModifyItemsCmd;
import net.kano.joscar.snaccmd.icbm.SendImIcbm; import net.kano.joscar.snaccmd.icbm.SendImIcbm;
import net.kano.joscar.snaccmd.icbm.SendTypingNotification;
import net.kano.joscar.snaccmd.conn.ServiceRequest; import net.kano.joscar.snaccmd.conn.ServiceRequest;
import net.kano.joscar.snaccmd.loc.SetInfoCmd; import net.kano.joscar.snaccmd.loc.SetInfoCmd;
import net.kano.joscar.snaccmd.InfoData; import net.kano.joscar.snaccmd.InfoData;
...@@ -271,6 +272,30 @@ public class OSCARSession extends TransportSession { ...@@ -271,6 +272,30 @@ public class OSCARSession extends TransportSession {
// We don't care. // We don't care.
} }
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#sendChatState(org.xmpp.packet.JID, org.jivesoftware.wildfire.gateway.ChatStateType)
*/
public void sendChatState(JID jid, ChatStateType chatState) {
if (chatState.equals(ChatStateType.composing)) {
request(new SendTypingNotification(
getTransport().convertJIDToID(jid),
SendTypingNotification.STATE_TYPING
));
}
else if (chatState.equals(ChatStateType.paused)) {
request(new SendTypingNotification(
getTransport().convertJIDToID(jid),
SendTypingNotification.STATE_PAUSED
));
}
else if (chatState.equals(ChatStateType.inactive)) {
request(new SendTypingNotification(
getTransport().convertJIDToID(jid),
SendTypingNotification.STATE_NO_TEXT
));
}
}
/** /**
* Opens/creates a new BOS connection to a specific server and port, given a cookie. * Opens/creates a new BOS connection to a specific server and port, given a cookie.
* *
......
...@@ -119,24 +119,24 @@ public class YahooSession extends TransportSession { ...@@ -119,24 +119,24 @@ public class YahooSession extends TransportSession {
yahooSession.reset(); yahooSession.reset();
Log.warn("Yahoo login failed for " + getJID()); Log.warn("Yahoo login failed for " + getJID());
Message m = new Message(); getTransport().sendMessage(
m.setType(Message.Type.error); getJID(),
m.setTo(getJID()); getTransport().getJID(),
m.setFrom(getTransport().getJID()); "Failed to log into Yahoo! messenger account. (login refused)",
m.setBody("Failed to log into Yahoo! messenger account. (login refused)"); Message.Type.error
getTransport().sendPacket(m); );
setLoginStatus(TransportLoginStatus.LOGGED_OUT); setLoginStatus(TransportLoginStatus.LOGGED_OUT);
} }
catch (IOException e) { catch (IOException e) {
Log.error("Yahoo login caused IO exception:", e); Log.error("Yahoo login caused IO exception:", e);
Message m = new Message(); getTransport().sendMessage(
m.setType(Message.Type.error); getJID(),
m.setTo(getJID()); getTransport().getJID(),
m.setFrom(getTransport().getJID()); "Failed to log into Yahoo! messenger account. (unknown error)",
m.setBody("Failed to log into Yahoo! messenger account. (unknown error)"); Message.Type.error
getTransport().sendPacket(m); );
setLoginStatus(TransportLoginStatus.LOGGED_OUT); setLoginStatus(TransportLoginStatus.LOGGED_OUT);
} }
} }
}.run(); }.run();
...@@ -348,6 +348,13 @@ public class YahooSession extends TransportSession { ...@@ -348,6 +348,13 @@ public class YahooSession extends TransportSession {
// We don't care. // We don't care.
} }
/**
* @see org.jivesoftware.wildfire.gateway.TransportSession#sendChatState(org.xmpp.packet.JID, org.jivesoftware.wildfire.gateway.ChatStateType)
*/
public void sendChatState(JID jid, ChatStateType chatState) {
// TODO: Handle this
}
/** /**
* @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)
*/ */
......
...@@ -60,24 +60,22 @@ public class YahooSessionListener implements SessionListener { ...@@ -60,24 +60,22 @@ public class YahooSessionListener implements SessionListener {
* @see ymsg.network.event.SessionListener#messageReceived(ymsg.network.event.SessionEvent) * @see ymsg.network.event.SessionListener#messageReceived(ymsg.network.event.SessionEvent)
*/ */
public void messageReceived(SessionEvent event) { public void messageReceived(SessionEvent event) {
Message m = new Message(); yahooSession.getTransport().sendMessage(
m.setType(Message.Type.chat); yahooSession.getJIDWithHighestPriority(),
m.setTo(yahooSession.getJIDWithHighestPriority()); yahooSession.getTransport().convertIDToJID(event.getFrom()),
m.setFrom(yahooSession.getTransport().convertIDToJID(event.getFrom())); messageDecoder.decodeToText(event.getMessage())
m.setBody(messageDecoder.decodeToText(event.getMessage())); );
yahooSession.getTransport().sendPacket(m);
} }
/** /**
* @see ymsg.network.event.SessionListener#offlineMessageReceived(ymsg.network.event.SessionEvent) * @see ymsg.network.event.SessionListener#offlineMessageReceived(ymsg.network.event.SessionEvent)
*/ */
public void offlineMessageReceived(SessionEvent event) { public void offlineMessageReceived(SessionEvent event) {
Message m = new Message(); yahooSession.getTransport().sendMessage(
m.setType(Message.Type.chat); yahooSession.getJIDWithHighestPriority(),
m.setTo(yahooSession.getJIDWithHighestPriority()); yahooSession.getTransport().convertIDToJID(event.getFrom()),
m.setFrom(yahooSession.getTransport().convertIDToJID(event.getFrom())); messageDecoder.decodeToText(event.getMessage())
m.setBody(messageDecoder.decodeToText(event.getMessage())); );
yahooSession.getTransport().sendPacket(m);
} }
/** /**
...@@ -85,12 +83,12 @@ public class YahooSessionListener implements SessionListener { ...@@ -85,12 +83,12 @@ public class YahooSessionListener implements SessionListener {
*/ */
public void newMailReceived(SessionNewMailEvent event) { public void newMailReceived(SessionNewMailEvent event) {
if (event.getMailCount() > 0) { if (event.getMailCount() > 0) {
Message m = new Message(); yahooSession.getTransport().sendMessage(
m.setType(Message.Type.headline); yahooSession.getJIDWithHighestPriority(),
m.setTo(yahooSession.getJIDWithHighestPriority()); yahooSession.getTransport().getJID(),
m.setFrom(yahooSession.getTransport().getJID()); "You have "+event.getMailCount()+" message(s) waiting in your Yahoo! mail.",
m.setBody("You have "+event.getMailCount()+" message(s) waiting in your Yahoo! mail."); Message.Type.headline
yahooSession.getTransport().sendPacket(m); );
} }
} }
...@@ -163,12 +161,11 @@ public class YahooSessionListener implements SessionListener { ...@@ -163,12 +161,11 @@ public class YahooSessionListener implements SessionListener {
* @see ymsg.network.event.SessionListener#buzzReceived(ymsg.network.event.SessionEvent) * @see ymsg.network.event.SessionListener#buzzReceived(ymsg.network.event.SessionEvent)
*/ */
public void buzzReceived(SessionEvent event) { public void buzzReceived(SessionEvent event) {
Message m = new Message(); yahooSession.getTransport().sendMessage(
m.setType(Message.Type.chat); yahooSession.getJIDWithHighestPriority(),
m.setTo(yahooSession.getJIDWithHighestPriority()); yahooSession.getTransport().convertIDToJID(event.getFrom()),
m.setFrom(yahooSession.getTransport().convertIDToJID(event.getFrom())); messageDecoder.decodeToText(event.getMessage())
m.setBody(messageDecoder.decodeToText(event.getMessage())); );
yahooSession.getTransport().sendPacket(m);
} }
/** /**
...@@ -176,12 +173,12 @@ public class YahooSessionListener implements SessionListener { ...@@ -176,12 +173,12 @@ public class YahooSessionListener implements SessionListener {
*/ */
public void errorPacketReceived(SessionErrorEvent event) { public void errorPacketReceived(SessionErrorEvent event) {
Log.error("Error from yahoo: "+event.getMessage()+", Code:"+event.getCode()); Log.error("Error from yahoo: "+event.getMessage()+", Code:"+event.getCode());
Message m = new Message(); yahooSession.getTransport().sendMessage(
m.setType(Message.Type.error); yahooSession.getJIDWithHighestPriority(),
m.setTo(yahooSession.getJIDWithHighestPriority()); yahooSession.getTransport().getJID(),
m.setFrom(yahooSession.getTransport().getJID()); "Error from yahoo: "+event.getMessage(),
m.setBody("Error from yahoo: "+event.getMessage()); Message.Type.error
yahooSession.getTransport().sendPacket(m); );
} }
/** /**
...@@ -189,12 +186,12 @@ public class YahooSessionListener implements SessionListener { ...@@ -189,12 +186,12 @@ public class YahooSessionListener implements SessionListener {
*/ */
public void inputExceptionThrown(SessionExceptionEvent event) { public void inputExceptionThrown(SessionExceptionEvent event) {
Log.error("Input error from yahoo: "+event.getMessage(), event.getException()); Log.error("Input error from yahoo: "+event.getMessage(), event.getException());
Message m = new Message(); yahooSession.getTransport().sendMessage(
m.setType(Message.Type.error); yahooSession.getJIDWithHighestPriority(),
m.setTo(yahooSession.getJIDWithHighestPriority()); yahooSession.getTransport().getJID(),
m.setFrom(yahooSession.getTransport().getJID()); "Input error from yahoo: "+event.getMessage(),
m.setBody("Input error from yahoo: "+event.getMessage()); Message.Type.error
yahooSession.getTransport().sendPacket(m); );
} }
/** /**
...@@ -203,7 +200,10 @@ public class YahooSessionListener implements SessionListener { ...@@ -203,7 +200,10 @@ public class YahooSessionListener implements SessionListener {
public void notifyReceived(SessionNotifyEvent event) { public void notifyReceived(SessionNotifyEvent event) {
Log.debug(event.toString()); Log.debug(event.toString());
if (event.getType().equals(StatusConstants.NOTIFY_TYPING)) { if (event.getType().equals(StatusConstants.NOTIFY_TYPING)) {
// Ooh, a typing notification. We'll use this in the future. yahooSession.getTransport().sendComposingNotification(
yahooSession.getJIDWithHighestPriority(),
yahooSession.getTransport().convertIDToJID(event.getFrom())
);
} }
} }
......
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