Fixes issue #644 (IRC claims chat room members joined right after I joined).

cusax-fix
Lyubomir Marinov 17 years ago
parent 17edf23796
commit 0160a3bf6b

@ -389,11 +389,23 @@ public void memberPresenceChanged(ChatRoomMemberPresenceChangeEvent evt)
sessionRenderer.addChatContact(chatContact);
statusMessage = GuiActivator.getResources().getI18NString(
"service.gui.CHAT_ROOM_USER_JOINED",
new String[] {sourceChatRoom.getName()});
/*
* When the whole list of members of a given chat room is reported,
* it doesn't make sense to see "ChatContact has joined #ChatRoom"
* for all of them one after the other. Such an event occurs not
* because the ChatContact has joined after us but rather she was
* there before us.
*/
if (!evt.isReasonUserList())
{
statusMessage = GuiActivator.getResources().getI18NString(
"service.gui.CHAT_ROOM_USER_JOINED",
new String[] {sourceChatRoom.getName()});
sessionRenderer.updateChatContactStatus(chatContact, statusMessage);
sessionRenderer.updateChatContactStatus(
chatContact,
statusMessage);
}
}
else if (eventType.equals(ChatRoomMemberPresenceChangeEvent.MEMBER_LEFT)
|| eventType.equals(ChatRoomMemberPresenceChangeEvent.MEMBER_KICKED)

@ -936,8 +936,7 @@ public void fireMemberPresenceEvent(ChatRoomMember member,
String eventID,
String eventReason)
{
ChatRoomMemberPresenceChangeEvent evt = null;
ChatRoomMemberPresenceChangeEvent evt;
if(actorMember != null)
evt = new ChatRoomMemberPresenceChangeEvent(
this, member, actorMember, eventID, eventReason);
@ -947,20 +946,14 @@ public void fireMemberPresenceEvent(ChatRoomMember member,
logger.trace("Will dispatch the following ChatRoom event: " + evt);
Iterator<ChatRoomMemberPresenceListener> listeners = null;
List<ChatRoomMemberPresenceListener> listeners;
synchronized (memberListeners)
{
listeners = new ArrayList<ChatRoomMemberPresenceListener>(
memberListeners).iterator();
memberListeners);
}
while (listeners.hasNext())
{
ChatRoomMemberPresenceListener listener
= (ChatRoomMemberPresenceListener) listeners.next();
for (ChatRoomMemberPresenceListener listener : listeners)
listener.memberPresenceChanged(evt);
}
}
/**

@ -41,7 +41,7 @@ public class IrcStack
/**
* A list of the channels on this server
*/
private List serverChatRoomList = new ArrayList();
private final List<String> serverChatRoomList = new ArrayList<String>();
/**
* A list of users that we have info about, it is used to stock "whois"
@ -1524,28 +1524,19 @@ protected void onUserList(String channel, User[] users)
chatRoom.clearChatRoomMemberList();
for (int i = 0; i < users.length; i++)
for (User user : users)
{
User user = users[i];
String userPrefix = user.getPrefix();
ChatRoomMemberRole newMemberRole;
if (user.getPrefix().equalsIgnoreCase("@"))
{
if ("@".equalsIgnoreCase(userPrefix))
newMemberRole = ChatRoomMemberRole.ADMINISTRATOR;
}
else if (user.getPrefix().equalsIgnoreCase("%"))
{
else if ("%".equalsIgnoreCase(userPrefix))
newMemberRole = ChatRoomMemberRole.MODERATOR;
}
else if (user.getPrefix().equalsIgnoreCase("+"))
{
else if ("+".equalsIgnoreCase(userPrefix))
newMemberRole = ChatRoomMemberRole.MEMBER;
}
else
{
newMemberRole = ChatRoomMemberRole.GUEST;
}
ChatRoomMemberIrcImpl newMember
= new ChatRoomMemberIrcImpl(parentProvider,
@ -1557,12 +1548,11 @@ else if (user.getPrefix().equalsIgnoreCase("+"))
chatRoom.addChatRoomMember(user.getNick(), newMember);
//we don't specify a reason
chatRoom.fireMemberPresenceEvent(
newMember,
null,
ChatRoomMemberPresenceChangeEvent.MEMBER_JOINED,
null);
ChatRoomMemberPresenceChangeEvent.REASON_USER_LIST);
}
}
@ -1603,7 +1593,7 @@ protected void onVoice(String channel, String sourceNick,
*
* @return the list of chat rooms on this server
*/
public List getServerChatRoomList()
public List<String> getServerChatRoomList()
{
return serverChatRoomList;
}

@ -10,18 +10,22 @@
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
/**
* Allows creating, configuring, joining and administrating of individual
* Allows creating, configuring, joining and administering of individual
* text-based conference rooms.
*
* @author Stephane Remy
* @author Loic Kempf
* @author Yana Stamcheva
* @author Lubomir Marinov
*/
public class OperationSetMultiUserChatIrcImpl
implements OperationSetMultiUserChat
{
private static final Logger logger
= Logger.getLogger(OperationSetMultiUserChatIrcImpl.class);
/**
* A call back to the IRC provider that created us.
@ -42,14 +46,16 @@ public class OperationSetMultiUserChatIrcImpl
/**
* list of this chat room local user status listener
*/
private ArrayList localUserPresenceListeners = new ArrayList();
private final List<LocalUserChatRoomPresenceListener> localUserPresenceListeners
= new ArrayList<LocalUserChatRoomPresenceListener>();
/**
* A list of the rooms that are currently open by this account. Note that
* we have not necessarily joined these rooms, we might have simply been
* searching through them.
*/
private Hashtable chatRoomCache = new Hashtable();
private final Map<String, ChatRoom> chatRoomCache
= new Hashtable<String, ChatRoom>();
/**
* A list of all private rooms opened by user on this server. These rooms
@ -88,7 +94,7 @@ public OperationSetMultiUserChatIrcImpl(
* @throws OperationFailedException if we failed retrieving this list from
* the server.
*/
public List getExistingChatRooms() throws OperationFailedException
public List<String> getExistingChatRooms() throws OperationFailedException
{
return ircProvider.getIrcStack().getServerChatRoomList();
}
@ -168,18 +174,10 @@ public ChatRoom createChatRoom(String roomName, Hashtable roomProperties)
public ChatRoom findRoom(String roomName)
{
//first check whether we have already initialized the room.
ChatRoom room = (ChatRoom)chatRoomCache.get(roomName);
ChatRoom room = chatRoomCache.get(roomName);
//if yes - we return it
if(room != null)
{
return room;
}
//if not, we create it.
else
{
return createLocalChatRoomInstance(roomName);
}
//if yes - we return it. if not, we create it.
return (room != null) ? room : createLocalChatRoomInstance(roomName);
}
/**
@ -315,20 +313,21 @@ protected void fireLocalUserPresenceEvent( ChatRoom chatRoom,
chatRoom,
eventType,
reason);
Iterator listeners = null;
logger.trace(
"Will dispatch the following OperationSetMultiUserChatIrcImpl event: "
+ evt);
List<LocalUserChatRoomPresenceListener> listeners;
synchronized (localUserPresenceListeners)
{
listeners = new ArrayList(localUserPresenceListeners).iterator();
listeners
= new ArrayList<LocalUserChatRoomPresenceListener>(
localUserPresenceListeners);
}
while (listeners.hasNext())
{
LocalUserChatRoomPresenceListener listener
= (LocalUserChatRoomPresenceListener) listeners.next();
for (LocalUserChatRoomPresenceListener listener : listeners)
listener.localUserPresenceChanged(evt);
}
}
/**

@ -15,6 +15,7 @@
* being kicked, join, left...
*
* @author Emil Ivov
* @author Lubomir Marinov
*/
public class ChatRoomMemberPresenceChangeEvent
extends EventObject
@ -25,7 +26,6 @@ public class ChatRoomMemberPresenceChangeEvent
*/
public static final String MEMBER_JOINED = "MemberJoined";
/**
* Indicates that this event was triggered as a result of the participant
* leaving the source chat room.
@ -37,35 +37,42 @@ public class ChatRoomMemberPresenceChangeEvent
* being "kicked" out of the chat room.
*/
public static final String MEMBER_KICKED = "MemberKicked";
/**
* Indicates that this event was triggered as a result of the participant
* being disconnected from the server brutally, or due to a ping timeout.
*/
public static final String MEMBER_QUIT = "MemberQuit";
public static final String MEMBER_QUIT = "MemberQuit";
/**
* The well-known reason for a
* <code>ChatRoomMemberPresenceChangeEvent</code> to occur as part of an
* operation which lists all users in a <code>ChatRoom</code>.
*/
public static final String REASON_USER_LIST = "ReasonUserList";
/**
* The chat room member that the event relates to.
*/
private ChatRoomMember sourceMember = null;
private final ChatRoomMember sourceMember;
/**
* The chat room member that participated as an actor in this event. In the
* case of MEMBER_KICKED event this would be the moderator that kicked the
* participant.
*/
private ChatRoomMember actorMember = null;
private final ChatRoomMember actorMember;
/**
* The type of this event. Values can be any of the MEMBER_XXX fields.
*/
private String eventType = null;
private final String eventType;
/**
* An optional String indicating a possible reason as to why the event
* might have occurred.
*/
private String reason = null;
private final String reason;
/**
* Creates a <tt>ChatRoomMemberPresenceChangeEvent</tt> representing that
@ -82,10 +89,7 @@ public ChatRoomMemberPresenceChangeEvent( ChatRoom sourceRoom,
String eventType,
String reason )
{
super(sourceRoom);
this.sourceMember = sourceMember;
this.eventType = eventType;
this.reason = reason;
this(sourceRoom, sourceMember, null, eventType, reason);
}
/**
@ -144,6 +148,20 @@ public String getReason()
return reason;
}
/**
* Gets the indicator which determines whether this event has occurred with
* the well-known reason of listing all users in a <code>ChatRoom</code>.
*
* @return <tt>true</tt> if this event has occurred with the well-known
* reason of listing all users in a <code>ChatRoom</code> i.e.
* {@link #getReason()} returns a value of {@link #REASON_USER_LIST};
* otherwise, <tt>false</tt>
*/
public boolean isReasonUserList()
{
return REASON_USER_LIST.equals(getReason());
}
/**
* Returns the type of this event which could be one of the MEMBER_XXX
* member field values.

Loading…
Cancel
Save