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 {
private final String IQ_REGISTER = "jabber:iq:register";
private final String IQ_REGISTERED = "jabber:iq:registered";
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
......@@ -187,6 +189,36 @@ public abstract class BaseTransport implements Component, RosterEventListener {
if (packet.getBody() != null) {
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) {
......@@ -1407,6 +1439,12 @@ public abstract class BaseTransport implements Component, RosterEventListener {
m.setFrom(from);
m.setTo(to);
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);
}
......@@ -1425,18 +1463,70 @@ public abstract class BaseTransport implements Component, RosterEventListener {
* Sends a typing 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 sendTypingNotification(JID to, JID from) {
public void sendComposingNotification(JID to, JID from) {
Message m = new Message();
m.setTo(to);
m.setFrom(from);
Element xEvent = m.addChildElement("x", "jabber:x:event");
xEvent.addElement("id");
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);
}
......
/**
* $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 {
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 message Message to be sent.
......@@ -439,7 +439,7 @@ public abstract class TransportSession implements Runnable {
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.
*
......@@ -447,6 +447,17 @@ public abstract class TransportSession implements Runnable {
*/
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.
*
......
......@@ -94,23 +94,23 @@ public class IRCListener implements IRCEventListener {
public void onError(String string) {
Log.debug("IRC error: "+string);
if (silenced) { return; }
Message m = new Message();
m.setType(Message.Type.error);
m.setFrom(getSession().getTransport().getJID());
m.setTo(getSession().getJID());
m.setBody("IRC error received: "+string);
getSession().getTransport().sendPacket(m);
getSession().getTransport().sendMessage(
getSession().getJID(),
getSession().getTransport().getJID(),
"IRC error received: "+string,
Message.Type.error
);
}
public void onError(int i, String string) {
Log.debug("IRC error: "+i+", "+string);
if (silenced) { return; }
Message m = new Message();
m.setType(Message.Type.error);
m.setFrom(getSession().getTransport().getJID());
m.setTo(getSession().getJID());
m.setBody("IRC error received: (code "+i+") "+string);
getSession().getTransport().sendPacket(m);
getSession().getTransport().sendMessage(
getSession().getJID(),
getSession().getTransport().getJID(),
"IRC error received: (code "+i+") "+string,
Message.Type.error
);
}
public void onInvite(String string, IRCUser ircUser, String string1) {
......@@ -151,12 +151,11 @@ public class IRCListener implements IRCEventListener {
else {
from = getSession().getTransport().convertIDToJID(username);
}
Message m = new Message();
m.setType(Message.Type.chat);
m.setFrom(from);
m.setTo(getSession().getJIDWithHighestPriority());
m.setBody(string1);
getSession().getTransport().sendPacket(m);
getSession().getTransport().sendMessage(
getSession().getJIDWithHighestPriority(),
from,
string1
);
}
public void onPart(String string, IRCUser ircUser, String string1) {
......@@ -174,12 +173,11 @@ public class IRCListener implements IRCEventListener {
// TODO: Investigate if I should respond to this. What do other clients do?
return;
}
Message m = new Message();
m.setType(Message.Type.chat);
m.setFrom(getSession().getTransport().convertIDToJID(ircUser.getNick()));
m.setTo(getSession().getJIDWithHighestPriority());
m.setBody(msg);
getSession().getTransport().sendPacket(m);
getSession().getTransport().sendMessage(
getSession().getJIDWithHighestPriority(),
getSession().getTransport().convertIDToJID(ircUser.getNick()),
msg
);
}
public void onQuit(IRCUser ircUser, String string) {
......@@ -211,12 +209,11 @@ public class IRCListener implements IRCEventListener {
}
}
else {
Message m = new Message();
m.setType(Message.Type.chat);
m.setFrom(getSession().getTransport().getJID());
m.setTo(getSession().getJIDWithHighestPriority());
m.setBody(string1);
getSession().getTransport().sendPacket(m);
getSession().getTransport().sendMessage(
getSession().getJIDWithHighestPriority(),
getSession().getTransport().getJID(),
string1
);
}
}
......
......@@ -240,6 +240,13 @@ public class IRCSession extends TransportSession {
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)
*/
......
......@@ -51,12 +51,11 @@ public class MSNListener extends MsnAdapter {
* Handles incoming messages from MSN users.
*/
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.getEmail().toString()));
m.setBody(message.getContent());
msnSession.getTransport().sendPacket(m);
msnSession.getTransport().sendMessage(
msnSession.getJIDWithHighestPriority(),
msnSession.getTransport().convertIDToJID(friend.getEmail().toString()),
message.getContent()
);
}
/**
......@@ -66,12 +65,11 @@ public class MSNListener extends MsnAdapter {
* @param message MSN message.
*/
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);
msnSession.getTransport().sendMessage(
msnSession.getJIDWithHighestPriority(),
msnSession.getTransport().getJID(),
message.getContent()
);
}
/**
......@@ -227,15 +225,16 @@ public class MSNListener extends MsnAdapter {
public void exceptionCaught(MsnMessenger messenger, Throwable throwable) {
Log.debug("MSN: Exception occurred for "+messenger.getOwner().getEmail()+" : "+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.getTransport().sendMessage(
msnSession.getJIDWithHighestPriority(),
msnSession.getTransport().getJID(),
"The password you registered with is incorrect. Please re-register with the correct password.",
Message.Type.error
);
msnSession.logOut();
}
else if (throwable.getClass().getName().equals("net.sf.jml.exception.MsnProtocolException")) {
Log.debug("MSN: Protocol exception: "+throwable.toString());
// Message m = new Message();
// m.setType(Message.Type.error);
// m.setTo(msnSession.getJIDWithHighestPriority());
......@@ -244,22 +243,24 @@ public class MSNListener extends MsnAdapter {
// 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);
msnSession.getTransport().sendMessage(
msnSession.getJIDWithHighestPriority(),
msnSession.getTransport().getJID(),
"Unable to send MSN message. Reason: "+throwable.toString(),
Message.Type.error
);
}
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);
Log.debug("MSN: Unknown message: "+throwable.toString());
// 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")) {
Log.debug("MSN: Protocol error: "+throwable.toString());
// Message m = new Message();
// m.setType(Message.Type.error);
// m.setTo(msnSession.getJIDWithHighestPriority());
......@@ -268,13 +269,14 @@ public class MSNListener extends MsnAdapter {
// 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);
Log.debug("MSN: Unknown error: "+throwable.toString());
// 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);
}
}
......
......@@ -389,6 +389,13 @@ public class MSNSession extends TransportSession {
// 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)
*/
......
......@@ -22,7 +22,6 @@ import org.xmpp.packet.Message;
import org.xmpp.packet.Presence;
import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError;
import org.dom4j.Element;
import net.kano.joscar.ByteBlock;
import net.kano.joscar.OscarTools;
import net.kano.joscar.BinaryTools;
......@@ -105,33 +104,32 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
InstantMessage message = icbm.getMessage();
String msg = OscarTools.stripHtml(message.getMessage());
Message m = new Message();
m.setTo(oscarSession.getJIDWithHighestPriority());
m.setBody(msg);
m.setType(Message.Type.chat);
m.setFrom(this.oscarSession.getTransport().convertIDToJID(sn));
oscarSession.getTransport().sendPacket(m);
oscarSession.getTransport().sendMessage(
oscarSession.getJIDWithHighestPriority(),
oscarSession.getTransport().convertIDToJID(sn),
msg
);
}
else if (cmd instanceof WarningNotification) {
WarningNotification wn = (WarningNotification) cmd;
MiniUserInfo warner = wn.getWarner();
if (warner == null) {
Message m = new Message();
m.setTo(oscarSession.getJIDWithHighestPriority());
m.setBody("You have received an anonymous AIM warning. Your warning level is now "+wn.getNewLevel()+"%.");
m.setType(Message.Type.headline);
m.setFrom(this.oscarSession.getTransport().getJID());
oscarSession.getTransport().sendPacket(m);
oscarSession.getTransport().sendMessage(
oscarSession.getJIDWithHighestPriority(),
oscarSession.getTransport().getJID(),
"You have received an anonymous AIM warning. Your warning level is now "+wn.getNewLevel()+"%.",
Message.Type.headline
);
}
else {
Log.debug("*** " + warner.getScreenname()
+ " warned you up to " + wn.getNewLevel() + "%");
Message m = new Message();
m.setTo(oscarSession.getJIDWithHighestPriority());
m.setBody("You have received an AIM warning from "+warner.getScreenname()+". Your warning level is now "+wn.getNewLevel()+"%.");
m.setType(Message.Type.headline);
m.setFrom(this.oscarSession.getTransport().getJID());
oscarSession.getTransport().sendPacket(m);
oscarSession.getTransport().sendMessage(
oscarSession.getJIDWithHighestPriority(),
oscarSession.getTransport().getJID(),
"You have received an AIM warning from "+warner.getScreenname()+". Your warning level is now "+wn.getNewLevel()+"%.",
Message.Type.headline
);
}
}
else if (cmd instanceof BuddyStatusCmd) {
......@@ -172,20 +170,25 @@ public abstract class BasicFlapConnection extends BaseFlapConnection {
else if (cmd instanceof TypingCmd) {
TypingCmd tc = (TypingCmd) cmd;
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) {
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;
import net.kano.joscar.snaccmd.ssi.DeleteItemsCmd;
import net.kano.joscar.snaccmd.ssi.ModifyItemsCmd;
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.loc.SetInfoCmd;
import net.kano.joscar.snaccmd.InfoData;
......@@ -271,6 +272,30 @@ public class OSCARSession extends TransportSession {
// 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.
*
......
......@@ -119,24 +119,24 @@ public class YahooSession extends TransportSession {
yahooSession.reset();
Log.warn("Yahoo login failed for " + getJID());
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(getJID());
m.setFrom(getTransport().getJID());
m.setBody("Failed to log into Yahoo! messenger account. (login refused)");
getTransport().sendPacket(m);
getTransport().sendMessage(
getJID(),
getTransport().getJID(),
"Failed to log into Yahoo! messenger account. (login refused)",
Message.Type.error
);
setLoginStatus(TransportLoginStatus.LOGGED_OUT);
}
catch (IOException e) {
Log.error("Yahoo login caused IO exception:", e);
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(getJID());
m.setFrom(getTransport().getJID());
m.setBody("Failed to log into Yahoo! messenger account. (unknown error)");
getTransport().sendPacket(m);
setLoginStatus(TransportLoginStatus.LOGGED_OUT);
getTransport().sendMessage(
getJID(),
getTransport().getJID(),
"Failed to log into Yahoo! messenger account. (unknown error)",
Message.Type.error
);
setLoginStatus(TransportLoginStatus.LOGGED_OUT);
}
}
}.run();
......@@ -348,6 +348,13 @@ public class YahooSession extends TransportSession {
// 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)
*/
......
......@@ -60,24 +60,22 @@ public class YahooSessionListener implements SessionListener {
* @see ymsg.network.event.SessionListener#messageReceived(ymsg.network.event.SessionEvent)
*/
public void messageReceived(SessionEvent event) {
Message m = new Message();
m.setType(Message.Type.chat);
m.setTo(yahooSession.getJIDWithHighestPriority());
m.setFrom(yahooSession.getTransport().convertIDToJID(event.getFrom()));
m.setBody(messageDecoder.decodeToText(event.getMessage()));
yahooSession.getTransport().sendPacket(m);
yahooSession.getTransport().sendMessage(
yahooSession.getJIDWithHighestPriority(),
yahooSession.getTransport().convertIDToJID(event.getFrom()),
messageDecoder.decodeToText(event.getMessage())
);
}
/**
* @see ymsg.network.event.SessionListener#offlineMessageReceived(ymsg.network.event.SessionEvent)
*/
public void offlineMessageReceived(SessionEvent event) {
Message m = new Message();
m.setType(Message.Type.chat);
m.setTo(yahooSession.getJIDWithHighestPriority());
m.setFrom(yahooSession.getTransport().convertIDToJID(event.getFrom()));
m.setBody(messageDecoder.decodeToText(event.getMessage()));
yahooSession.getTransport().sendPacket(m);
yahooSession.getTransport().sendMessage(
yahooSession.getJIDWithHighestPriority(),
yahooSession.getTransport().convertIDToJID(event.getFrom()),
messageDecoder.decodeToText(event.getMessage())
);
}
/**
......@@ -85,12 +83,12 @@ public class YahooSessionListener implements SessionListener {
*/
public void newMailReceived(SessionNewMailEvent event) {
if (event.getMailCount() > 0) {
Message m = new Message();
m.setType(Message.Type.headline);
m.setTo(yahooSession.getJIDWithHighestPriority());
m.setFrom(yahooSession.getTransport().getJID());
m.setBody("You have "+event.getMailCount()+" message(s) waiting in your Yahoo! mail.");
yahooSession.getTransport().sendPacket(m);
yahooSession.getTransport().sendMessage(
yahooSession.getJIDWithHighestPriority(),
yahooSession.getTransport().getJID(),
"You have "+event.getMailCount()+" message(s) waiting in your Yahoo! mail.",
Message.Type.headline
);
}
}
......@@ -163,12 +161,11 @@ public class YahooSessionListener implements SessionListener {
* @see ymsg.network.event.SessionListener#buzzReceived(ymsg.network.event.SessionEvent)
*/
public void buzzReceived(SessionEvent event) {
Message m = new Message();
m.setType(Message.Type.chat);
m.setTo(yahooSession.getJIDWithHighestPriority());
m.setFrom(yahooSession.getTransport().convertIDToJID(event.getFrom()));
m.setBody(messageDecoder.decodeToText(event.getMessage()));
yahooSession.getTransport().sendPacket(m);
yahooSession.getTransport().sendMessage(
yahooSession.getJIDWithHighestPriority(),
yahooSession.getTransport().convertIDToJID(event.getFrom()),
messageDecoder.decodeToText(event.getMessage())
);
}
/**
......@@ -176,12 +173,12 @@ public class YahooSessionListener implements SessionListener {
*/
public void errorPacketReceived(SessionErrorEvent event) {
Log.error("Error from yahoo: "+event.getMessage()+", Code:"+event.getCode());
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(yahooSession.getJIDWithHighestPriority());
m.setFrom(yahooSession.getTransport().getJID());
m.setBody("Error from yahoo: "+event.getMessage());
yahooSession.getTransport().sendPacket(m);
yahooSession.getTransport().sendMessage(
yahooSession.getJIDWithHighestPriority(),
yahooSession.getTransport().getJID(),
"Error from yahoo: "+event.getMessage(),
Message.Type.error
);
}
/**
......@@ -189,12 +186,12 @@ public class YahooSessionListener implements SessionListener {
*/
public void inputExceptionThrown(SessionExceptionEvent event) {
Log.error("Input error from yahoo: "+event.getMessage(), event.getException());
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(yahooSession.getJIDWithHighestPriority());
m.setFrom(yahooSession.getTransport().getJID());
m.setBody("Input error from yahoo: "+event.getMessage());
yahooSession.getTransport().sendPacket(m);
yahooSession.getTransport().sendMessage(
yahooSession.getJIDWithHighestPriority(),
yahooSession.getTransport().getJID(),
"Input error from yahoo: "+event.getMessage(),
Message.Type.error
);
}
/**
......@@ -203,7 +200,10 @@ public class YahooSessionListener implements SessionListener {
public void notifyReceived(SessionNotifyEvent event) {
Log.debug(event.toString());
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