Fixes issue #542 (Notifications for conversations in chat rooms are not) and issue #642 (IRC treats ChatRoomMember as ChatRoom).

cusax-fix
Lyubomir Marinov 17 years ago
parent 02fad7b7ad
commit 8668a569e8

@ -29,7 +29,7 @@
* The <tt>ChatConversationPanel</tt> is the panel, where all sent and received
* messages appear. All data is stored in an HTML document. An external CSS file
* is applied to the document to provide the look&feel. All smilies and link
* strings are processed and finally replaced by corresponding images and html
* strings are processed and finally replaced by corresponding images and HTML
* links.
*
* @author Yana Stamcheva

@ -32,6 +32,7 @@
* invitations.
*
* @author Yana Stamcheva
* @author Lubomir Marinov
*/
public class ConferenceChatManager
implements ChatRoomMessageListener,
@ -152,7 +153,7 @@ else if (evt.getEventType()
/**
* Implements the <tt>ChatRoomMessageListener.messageReceived</tt> method.
* <br>
* Obtains the corresponding <tt>ChatPanel</tt> and proccess the message
* Obtains the corresponding <tt>ChatPanel</tt> and process the message
* there.
*/
public void messageReceived(ChatRoomMessageReceivedEvent evt)
@ -163,20 +164,17 @@ public void messageReceived(ChatRoomMessageReceivedEvent evt)
String messageType = null;
if (evt.getEventType()
== ChatRoomMessageReceivedEvent.CONVERSATION_MESSAGE_RECEIVED)
switch (evt.getEventType())
{
case ChatRoomMessageReceivedEvent.CONVERSATION_MESSAGE_RECEIVED:
messageType = Constants.INCOMING_MESSAGE;
}
else if (evt.getEventType()
== ChatRoomMessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED)
{
break;
case ChatRoomMessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED:
messageType = Constants.SYSTEM_MESSAGE;
}
else if (evt.getEventType()
== ChatRoomMessageReceivedEvent.ACTION_MESSAGE_RECEIVED)
{
break;
case ChatRoomMessageReceivedEvent.ACTION_MESSAGE_RECEIVED:
messageType = Constants.ACTION_MESSAGE;
break;
}
logger.trace("MESSAGE RECEIVED from contact: "
@ -205,26 +203,83 @@ else if (evt.getEventType()
.getMultiChat(sourceChatRoom, message.getMessageUID());
}
String messageContent = message.getContent();
chatPanel.processMessage(
sourceMember.getName(),
evt.getTimestamp(),
messageType,
message.getContent(),
messageContent,
message.getContentType());
chatWindowManager.openChat(chatPanel, false);
// Fire notification
String title
= GuiActivator.getResources().getI18NString(
"service.gui.MSG_RECEIVED",
new String[]{sourceMember.getName()});
NotificationManager.fireChatNotification(
sourceChatRoom,
NotificationManager.INCOMING_MESSAGE,
title,
message.getContent());
boolean fireChatNotification;
/*
* It is uncommon for IRC clients to display popup notifications for
* messages which are sent to public channels and which do not mention
* the nickname of the local user.
*/
if (sourceChatRoom.isSystem()
|| isPrivate(sourceChatRoom)
|| (messageContent == null))
fireChatNotification = true;
else
{
String nickname = sourceChatRoom.getUserNickname();
fireChatNotification =
(nickname == null)
|| messageContent.toLowerCase().contains(
nickname.toLowerCase());
}
if (fireChatNotification)
{
String title
= GuiActivator.getResources().getI18NString(
"service.gui.MSG_RECEIVED",
new String[] { sourceMember.getName() });
NotificationManager.fireChatNotification(
sourceChatRoom,
NotificationManager.INCOMING_MESSAGE,
title,
messageContent);
}
}
/**
* Determines whether a specific <code>ChatRoom</code> is private i.e.
* represents a one-to-one conversation which is not a channel. Since the
* interface {@link ChatRoom} does not expose the private property, an
* heuristic is used as a workaround: (1) a system <code>ChatRoom</code> is
* obviously not private and (2) a <code>ChatRoom</code> is private if it
* has only one <code>ChatRoomMember</code> who is not the local user.
*
* @param chatRoom
* the <code>ChatRoom</code> to be determined as private or not
* @return <tt>true</tt> if the specified <code>ChatRoom</code> is private;
* otherwise, <tt>false</tt>
*/
static boolean isPrivate(ChatRoom chatRoom)
{
if (!chatRoom.isSystem()
&& chatRoom.isJoined()
&& (chatRoom.getMembersCount() == 1))
{
String nickname = chatRoom.getUserNickname();
if (nickname != null)
{
for (ChatRoomMember member : chatRoom.getMembers())
if (nickname.equals(member.getName()))
return false;
return true;
}
}
return false;
}
/**
@ -485,8 +540,7 @@ public ChatRoomWrapper createChatRoom(
ChatRoom chatRoom = null;
try
{
chatRoom = groupChatOpSet
.createChatRoom(chatRoomName, new Hashtable());
chatRoom = groupChatOpSet.createChatRoom(chatRoomName, null);
}
catch (OperationFailedException ex)
{

@ -547,6 +547,10 @@ private void initChatParticipants()
/* Implements ChatSession#isContactListSupported(). */
public boolean isContactListSupported()
{
return !chatRoomWrapper.getChatRoom().isSystem();
ChatRoom chatRoom = chatRoomWrapper.getChatRoom();
return
!chatRoom.isSystem()
&& !ConferenceChatManager.isPrivate(chatRoom);
}
}

@ -209,7 +209,7 @@ private ChatRoom createLocalChatRoomInstance(ChatInvitation chatInvitation)
* @return ChatRoom the chat room that we've just created.
*/
public ChatRoom createChatRoom( String roomName,
Hashtable roomProperties)
Map<String, Object> roomProperties)
throws OperationFailedException,
OperationNotSupportedException
{

@ -1059,6 +1059,12 @@ protected void setSubjectFromServer(String subject)
*/
public boolean isPersistent()
{
return true;
/*
* Private ChatRooms are not persistent because they correspond to
* conversations created by sending private messages and such
* conversations are not traditionally persisted by other IRC clients.
*/
return !isPrivate();
}
}

@ -728,18 +728,12 @@ protected void onPart( String channel,
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_LEFT,
"");
Iterator members = chatRoom.getMembers().iterator();
while(members.hasNext())
{
ChatRoomMember member = (ChatRoomMember) members.next();
for (ChatRoomMember member : chatRoom.getMembers())
chatRoom.fireMemberPresenceEvent(
member,
null,
ChatRoomMemberPresenceChangeEvent.MEMBER_LEFT,
"Local user has left the chat room.");
}
// Delete the list of members
chatRoom.clearChatRoomMemberList();
@ -1620,12 +1614,10 @@ protected boolean isJoined(ChatRoomIrcImpl chatRoom)
{
String[] channels = this.getChannels();
for (int i = 0; i < channels.length; i++)
for (String channel : channels)
{
if (chatRoom.getName().equals(channels[i]))
{
if (chatRoom.getName().equals(channel))
return true;
}
}
return false;
}
@ -1888,26 +1880,6 @@ public void run()
}
}
/**
* Parses a <code>String</code> to an <code>int</code> via
* <code>Integer.parseInt</code> but avoids the
* <code>NumberFormatException</code>.
* @param str The <code>String</code> to parse.
* @return The parsed new <code>int</code>. <code>-1</code> if
* <code>NumberFormatException</code> was thrown.
*/
private int parseInt(String str)
{
try
{
return Integer.parseInt(str);
}
catch (NumberFormatException exc)
{
return -1;
}
}
/**
* Locks a chat room operation.
*/

@ -159,8 +159,11 @@ public List getCurrentlyJoinedChatRooms(ChatRoomMember chatRoomMember)
*
* @return the newly created <tt>ChatRoom</tt> named <tt>roomName</tt>.
*/
public ChatRoom createChatRoom(String roomName, Hashtable roomProperties)
throws OperationFailedException, OperationNotSupportedException
public ChatRoom createChatRoom(
String roomName,
Map<String, Object> roomProperties)
throws OperationFailedException,
OperationNotSupportedException
{
return findRoom(roomName);
}
@ -374,23 +377,32 @@ private ChatRoom createLocalChatRoomInstance(String chatRoomName)
*/
protected ChatRoomIrcImpl findPrivateChatRoom(String nickIdentifier)
{
ChatRoomIrcImpl chatRoom;
synchronized(privateRoomCache)
{
if(privateRoomCache.containsKey(nickIdentifier))
return privateRoomCache.get(nickIdentifier);
ChatRoomIrcImpl chatRoom
= new ChatRoomIrcImpl(nickIdentifier, ircProvider, true, false);
chatRoom =
new ChatRoomIrcImpl(
nickIdentifier,
ircProvider,
true,
false);
privateRoomCache.put(nickIdentifier, chatRoom);
}
fireLocalUserPresenceEvent(
chatRoom,
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_JOINED,
"Private conversation initiated.");
/*
* As a rule of thumb, firing inside synchronized blocks increases the
* chances of creating deadlocks.
*/
fireLocalUserPresenceEvent(
chatRoom,
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_JOINED,
"Private conversation initiated.");
return chatRoom;
}
return chatRoom;
}
/**

@ -193,8 +193,11 @@ public void removeInvitationRejectionListener(
*
* @return ChatRoom the chat room that we've just created.
*/
public ChatRoom createChatRoom(String roomName, Hashtable roomProperties)
throws OperationFailedException, OperationNotSupportedException
public ChatRoom createChatRoom(
String roomName,
Map<String, Object> roomProperties)
throws OperationFailedException,
OperationNotSupportedException
{
//first make sure we are connected and the server supports multichat
assertSupportedAndConnected();

@ -127,14 +127,16 @@ public List getCurrentlyJoinedChatRooms(ChatRoomMember chatRoomMember)
* @param roomProperties properties specifying how the room should be
* created.
* @throws OperationFailedException if the room couldn't be created for some
* reason (e.g. room already exists; user already joined to an existant
* reason (e.g. room already exists; user already joined to an existing
* room or user has no permissions to create a chat room).
* @throws OperationNotSupportedException if chat room creation is not
* supported by this server
*
* @return the newly created <tt>ChatRoom</tt> named <tt>roomName</tt>.
*/
public ChatRoom createChatRoom(String roomName, Hashtable roomProperties)
public ChatRoom createChatRoom(
String roomName,
Map<String, Object> roomProperties)
throws OperationFailedException,
OperationNotSupportedException
{

@ -208,7 +208,7 @@ public boolean isMultiChatSupportedByContact(Contact contact)
* @return ChatRoom the chat room that we've just created.
*/
public ChatRoom createChatRoom( String roomName,
Hashtable roomProperties)
Map<String, Object> roomProperties)
throws OperationFailedException,
OperationNotSupportedException
{

@ -211,8 +211,9 @@ public void removePresenceListener(
* @return ChatRoom the chat room that we've just created.
*/
public ChatRoom createChatRoom(String roomName,
Hashtable<String, Object> roomProperties)
throws OperationFailedException, OperationNotSupportedException
Map<String, Object> roomProperties)
throws OperationFailedException,
OperationNotSupportedException
{
ChatRoom chatRoom = null;
try

@ -7,7 +7,7 @@
package net.java.sip.communicator.service.protocol;
/**
* This interface representes chat room participants. Instances are retrieved
* This interface represents chat room participants. Instances are retrieved
* through implementations of the <tt>ChatRoom</tt> interface and offer methods
* that allow querying member properties, such as, moderation permissions,
* associated chat room and other.

@ -7,10 +7,11 @@
package net.java.sip.communicator.service.protocol;
import java.util.*;
import net.java.sip.communicator.service.protocol.event.*;
/**
* Allows creating, configuring, joining and administrating of individual
* Allows creating, configuring, joining and administering of individual
* text-based conference rooms.
*
* @author Emil Ivov
@ -27,10 +28,10 @@ public interface OperationSetMultiUserChat
* rooms that are currently available on the server that this protocol
* provider is connected to.
*
* @throws OperationFailedException if we faile retrieving this list from
* @throws OperationFailedException if we failed retrieving this list from
* the server.
* @throws OperationNotSupportedException if the server does not support
* multi user chat
* multi-user chat
*/
public List<String> getExistingChatRooms()
throws OperationFailedException, OperationNotSupportedException;
@ -56,7 +57,7 @@ public List<String> getExistingChatRooms()
* @throws OperationFailedException if an error occurs while trying to
* discover the room on the server.
* @throws OperationNotSupportedException if the server does not support
* multi user chat
* multi-user chat
*/
public List<String> getCurrentlyJoinedChatRooms(ChatRoomMember chatRoomMember)
throws OperationFailedException, OperationNotSupportedException;
@ -68,20 +69,26 @@ public List<String> getCurrentlyJoinedChatRooms(ChatRoomMember chatRoomMember)
* local user will not have joined it and thus will not receive messages on
* it until the <tt>ChatRoom.join()</tt> method is called.
* <p>
* @param roomName the name of the <tt>ChatRoom</tt> to create.
* @param roomProperties properties specifying how the room should be
* created.
* @throws OperationFailedException if the room couldn't be created for some
* reason (e.g. room already exists; user already joined to an existent
* room or user has no permissions to create a chat room).
* @throws OperationNotSupportedException if chat room creation is not
* supported by this server
*
*
* @param roomName
* the name of the <tt>ChatRoom</tt> to create.
* @param roomProperties
* properties specifying how the room should be created;
* <tt>null</tt> for no properties just like an empty
* <code>Map</code>
* @throws OperationFailedException
* if the room couldn't be created for some reason (e.g. room
* already exists; user already joined to an existent room or
* user has no permissions to create a chat room).
* @throws OperationNotSupportedException
* if chat room creation is not supported by this server
*
* @return the newly created <tt>ChatRoom</tt> named <tt>roomName</tt>.
*/
public ChatRoom createChatRoom(String roomName,
Hashtable<String, Object> roomProperties)
throws OperationFailedException, OperationNotSupportedException;
Map<String, Object> roomProperties)
throws OperationFailedException,
OperationNotSupportedException;
/**
* Returns a reference to a chatRoom named <tt>roomName</tt> or null
@ -94,7 +101,7 @@ public ChatRoom createChatRoom(String roomName,
* @throws OperationFailedException if an error occurs while trying to
* discover the room on the server.
* @throws OperationNotSupportedException if the server does not support
* multi user chat
* multi-user chat
*/
public ChatRoom findRoom(String roomName)
throws OperationFailedException, OperationNotSupportedException;
@ -143,7 +150,7 @@ public void removeInvitationRejectionListener(
ChatRoomInvitationRejectionListener listener);
/**
* Returns true if <tt>contact</tt> supports multi user chat sessions.
* Returns true if <tt>contact</tt> supports multi-user chat sessions.
*
* @param contact reference to the contact whose support for chat rooms
* we are currently querying.

@ -184,7 +184,7 @@ public void testCreateChatRoom()
{
//create room
ChatRoom testChatRoom = opSetMultiChat1
.createChatRoom(fixture.chatRoomName, new Hashtable());
.createChatRoom(fixture.chatRoomName, null);
//get available rooms
assertNotNull("createChatRoom() returned null", testChatRoom);

Loading…
Cancel
Save