From a88eb81a9ab858e8070a8a9a0a01daf4b1569e41 Mon Sep 17 00:00:00 2001 From: Derek DeMoro Date: Wed, 9 Aug 2006 22:44:08 +0000 Subject: [PATCH] Update ContactList with subtle actions. git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@4868 b35dd754-fafc-0310-a699-88a17e54d16e --- .../org/jivesoftware/spark/ChatManager.java | 83 ++++++++++++++++++- .../spark/ui/rooms/ChatRoomImpl.java | 68 ++------------- 2 files changed, 89 insertions(+), 62 deletions(-) diff --git a/src/java/org/jivesoftware/spark/ChatManager.java b/src/java/org/jivesoftware/spark/ChatManager.java index da275b58..d8e64007 100644 --- a/src/java/org/jivesoftware/spark/ChatManager.java +++ b/src/java/org/jivesoftware/spark/ChatManager.java @@ -10,10 +10,16 @@ package org.jivesoftware.spark; +import org.jivesoftware.resource.SparkRes; +import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.filter.PacketTypeFilter; import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Presence; +import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smackx.Form; +import org.jivesoftware.smackx.MessageEventNotificationListener; import org.jivesoftware.smackx.muc.MultiUserChat; import org.jivesoftware.spark.ui.ChatContainer; import org.jivesoftware.spark.ui.ChatRoom; @@ -31,17 +37,20 @@ import org.jivesoftware.sparkimpl.preference.chat.ChatPreference; import org.jivesoftware.sparkimpl.preference.chat.ChatPreferences; import javax.swing.Icon; +import javax.swing.SwingUtilities; import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; /** * Handles the Chat Management of each individual Workspace. The ChatManager is responsible * for creation and removal of chat rooms, transcripts, and transfers and room invitations. */ -public class ChatManager { +public class ChatManager implements MessageEventNotificationListener { private List messageFilters = new ArrayList(); private List invitationListeners = new ArrayList(); @@ -51,11 +60,26 @@ public class ChatManager { private List contactItemHandlers = new ArrayList(); + private Set customList = new HashSet(); + + /** * Create a new instance of ChatManager. */ public ChatManager() { chatContainer = new ChatContainer(); + + // Add a Message Handler + + SparkManager.getMessageEventManager().addMessageEventNotificationListener(this); + + SparkManager.getConnection().addPacketListener(new PacketListener() { + public void processPacket(final Packet packet) { + if (customList.contains(StringUtils.parseBareAddress(packet.getFrom()))) { + cancelledNotification(packet.getFrom(), ""); + } + } + }, new PacketTypeFilter(Message.class)); } @@ -164,7 +188,6 @@ public class ChatManager { return chatRoom; } - /** * Creates a new public Conference Room. * @@ -305,4 +328,60 @@ public class ChatManager { return null; } + + // Implemenation of MessageEventListener + + public void deliveredNotification(String from, String packetID) { + + } + + public void displayedNotification(String from, String packetID) { + } + + public void composingNotification(final String from, String packetID) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + final ContactList contactList = SparkManager.getWorkspace().getContactList(); + + ChatRoom chatRoom = null; + try { + chatRoom = getChatContainer().getChatRoom(StringUtils.parseBareAddress(from)); + if (chatRoom != null && chatRoom instanceof ChatRoomImpl) { + ((ChatRoomImpl)chatRoom).showTyping(true); + } + } + catch (ChatRoomNotFoundException e) { + } + + contactList.setIconFor(from, SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE)); + customList.add(StringUtils.parseBareAddress(from)); + } + }); + } + + public void offlineNotification(String from, String packetID) { + } + + public void cancelledNotification(final String from, String packetID) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + ContactList contactList = SparkManager.getWorkspace().getContactList(); + + ChatRoom chatRoom = null; + try { + chatRoom = getChatContainer().getChatRoom(StringUtils.parseBareAddress(from)); + if (chatRoom != null && chatRoom instanceof ChatRoomImpl) { + ((ChatRoomImpl)chatRoom).showTyping(false); + } + } + catch (ChatRoomNotFoundException e) { + } + + contactList.useDefaults(from); + customList.remove(StringUtils.parseBareAddress(from)); + } + }); + } + + } \ No newline at end of file diff --git a/src/java/org/jivesoftware/spark/ui/rooms/ChatRoomImpl.java b/src/java/org/jivesoftware/spark/ui/rooms/ChatRoomImpl.java index b8182e81..f91dbb79 100644 --- a/src/java/org/jivesoftware/spark/ui/rooms/ChatRoomImpl.java +++ b/src/java/org/jivesoftware/spark/ui/rooms/ChatRoomImpl.java @@ -23,7 +23,6 @@ import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smackx.MessageEventManager; -import org.jivesoftware.smackx.MessageEventNotificationListener; import org.jivesoftware.smackx.MessageEventRequestListener; import org.jivesoftware.smackx.packet.VCard; import org.jivesoftware.spark.SparkManager; @@ -69,7 +68,6 @@ public class ChatRoomImpl extends ChatRoom { private String tabTitle; private String participantJID; private String participantNickname; - private ChatRoomMessageManager messageManager; private MessageEventRequestListener messageEventRequestListener; boolean isOnline = true; @@ -122,9 +120,6 @@ public class ChatRoomImpl extends ChatRoom { this.getSplitPane().setRightComponent(null); getSplitPane().setDividerSize(0); - messageManager = new ChatRoomMessageManager(); - - SparkManager.getMessageEventManager().addMessageEventNotificationListener(messageManager); roster = SparkManager.getConnection().getRoster(); presence = roster.getPresence(participantJID); @@ -264,8 +259,6 @@ public class ChatRoomImpl extends ChatRoom { SparkManager.getChatManager().removeChat(this); - SparkManager.getMessageEventManager().removeMessageEventNotificationListener(messageManager); - SparkManager.getConnection().removePacketListener(this); } @@ -431,7 +424,6 @@ public class ChatRoomImpl extends ChatRoom { // Do something with the incoming packet here. final Message message = (Message)packet; if (message.getError() != null) { - SparkManager.getMessageEventManager().removeMessageEventNotificationListener(messageManager); return; } @@ -464,7 +456,7 @@ public class ChatRoomImpl extends ChatRoom { participantJID = message.getFrom(); insertMessage(message); - clearTypingNotification(); + showTyping(false); } } } @@ -482,52 +474,6 @@ public class ChatRoomImpl extends ChatRoom { } - /** - * Private implementation of the MessageEventNotificationListener. - */ - private class ChatRoomMessageManager implements MessageEventNotificationListener { - - ChatRoomMessageManager() { - - } - - public void deliveredNotification(String from, String packetID) { - } - - public void displayedNotification(String from, String packetID) { - } - - public void composingNotification(final String from, String packetID) { - if (!from.startsWith(participantJID)) { - return; - } - - SwingUtilities.invokeLater(new Runnable() { - public void run() { - String isTypingText = participantNickname + " is typing a message..."; - getNotificationLabel().setText(isTypingText); - getNotificationLabel().setIcon(SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE)); - showTyping(true); - } - }); - } - - public void offlineNotification(String from, String packetID) { - } - - public void cancelledNotification(String from, String packetID) { - clearTypingNotification(); - } - } - - - private void clearTypingNotification() { - // Remove is typing text. - getNotificationLabel().setText(""); - getNotificationLabel().setIcon(SparkRes.getImageIcon(SparkRes.BLANK_IMAGE)); - showTyping(false); - } - /** * The current SendField has been updated somehow. * @@ -611,14 +557,16 @@ public class ChatRoomImpl extends ChatRoom { } } - private void showTyping(boolean typing) { - final ContactList contactList = SparkManager.getWorkspace().getContactList(); - + public void showTyping(boolean typing) { if (typing) { - contactList.setIconFor(getParticipantJID(), SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE)); + String isTypingText = participantNickname + " is typing a message..."; + getNotificationLabel().setText(isTypingText); + getNotificationLabel().setIcon(SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE)); } else { - contactList.useDefaults(getParticipantJID()); + // Remove is typing text. + getNotificationLabel().setText(""); + getNotificationLabel().setIcon(SparkRes.getImageIcon(SparkRes.BLANK_IMAGE)); } }