Include local user in chat room member list operations.

fix-message-formatting
Danny van Heumen 12 years ago
parent 672dcb500d
commit a6b354ce83

@ -20,6 +20,7 @@
* @author Stephane Remy * @author Stephane Remy
* @author Loic Kempf * @author Loic Kempf
* @author Yana Stamcheva * @author Yana Stamcheva
* @author Danny van Heumen
*/ */
public class ChatRoomIrcImpl public class ChatRoomIrcImpl
extends AbstractChatRoom extends AbstractChatRoom

@ -527,8 +527,9 @@ public void onSuccess(IRCChannel channel)
+ "of channel '" + chatroom.getIdentifier() + "of channel '" + chatroom.getIdentifier()
+ "'."); + "'.");
} }
String chatRoomId = chatroom.getIdentifier();
boolean isRequestedChatRoom = channel.getName() boolean isRequestedChatRoom = channel.getName()
.equalsIgnoreCase(chatroom.getIdentifier()); .equalsIgnoreCase(chatRoomId);
synchronized (joinSignal) synchronized (joinSignal)
{ {
if (!isRequestedChatRoom) if (!isRequestedChatRoom)
@ -541,7 +542,7 @@ public void onSuccess(IRCChannel channel)
.trace("Callback for successful join " .trace("Callback for successful join "
+ "finished prematurely since we " + "finished prematurely since we "
+ "got forwarded from '" + "got forwarded from '"
+ chatroom.getIdentifier() + chatRoomId
+ "' to '" + "' to '"
+ channel.getName() + channel.getName()
+ "'. Joining of forwarded channel " + "'. Joining of forwarded channel "
@ -549,8 +550,7 @@ public void onSuccess(IRCChannel channel)
+ "since that channel was not " + "since that channel was not "
+ "announced."); + "announced.");
} }
IrcStack.this.joining.remove(chatroom IrcStack.this.joining.remove(chatRoomId);
.getIdentifier());
IrcStack.this.provider IrcStack.this.provider
.getMUC() .getMUC()
.fireLocalUserPresenceEvent( .fireLocalUserPresenceEvent(
@ -570,10 +570,8 @@ public void onSuccess(IRCChannel channel)
try try
{ {
IrcStack.this.joined.put( IrcStack.this.joined.put(chatRoomId, chatroom);
chatroom.getIdentifier(), chatroom); IrcStack.this.joining.remove(chatRoomId);
IrcStack.this.joining.remove(chatroom
.getIdentifier());
IrcStack.this.irc IrcStack.this.irc
.addListener(new ChatRoomListener( .addListener(new ChatRoomListener(
chatroom)); chatroom));
@ -599,7 +597,7 @@ public void onSuccess(IRCChannel channel)
LOGGER LOGGER
.trace("Finished successful join " .trace("Finished successful join "
+ "callback for channel '" + "callback for channel '"
+ chatroom.getIdentifier() + chatRoomId
+ "'. Waking up original thread."); + "'. Waking up original thread.");
} }
// Notify waiting threads of finished // Notify waiting threads of finished
@ -616,12 +614,12 @@ public void onFailure(Exception e)
LOGGER.trace("Started callback for failed attempt to " LOGGER.trace("Started callback for failed attempt to "
+ "join channel '" + chatroom.getIdentifier() + "join channel '" + chatroom.getIdentifier()
+ "'."); + "'.");
String chatRoomId = chatroom.getIdentifier();
synchronized (joinSignal) synchronized (joinSignal)
{ {
try try
{ {
IrcStack.this.joining.remove(chatroom IrcStack.this.joining.remove(chatRoomId);
.getIdentifier());
IrcStack.this.provider IrcStack.this.provider
.getMUC() .getMUC()
.fireLocalUserPresenceEvent( .fireLocalUserPresenceEvent(
@ -637,7 +635,7 @@ public void onFailure(Exception e)
LOGGER LOGGER
.trace("Finished callback for failed " .trace("Finished callback for failed "
+ "attempt to join channel '" + "attempt to join channel '"
+ chatroom.getIdentifier() + chatRoomId
+ "'. Waking up original thread."); + "'. Waking up original thread.");
} }
// Notify waiting threads of finished // Notify waiting threads of finished
@ -806,15 +804,12 @@ private void prepareChatRoom(final ChatRoomIrcImpl chatRoom,
{ {
chatRoom.prepUserRole(role); chatRoom.prepUserRole(role);
} }
else
{
ChatRoomMemberIrcImpl member = ChatRoomMemberIrcImpl member =
new ChatRoomMemberIrcImpl(this.provider, chatRoom, new ChatRoomMemberIrcImpl(this.provider, chatRoom,
user.getNick(), role); user.getNick(), role);
chatRoom.addChatRoomMember(member.getContactAddress(), member); chatRoom.addChatRoomMember(member.getContactAddress(), member);
} }
} }
}
/** /**
* Convert a member mode character to a ChatRoomMemberRole instance. * Convert a member mode character to a ChatRoomMemberRole instance.
@ -1018,18 +1013,22 @@ private void deliverReceivedMessageToPrivateChat(
/** /**
* Create a private chat room if one does not exist yet. * Create a private chat room if one does not exist yet.
* *
* @param user private chat room for this user * @param userName private chat room for this user
* @return returns the private chat room * @return returns the private chat room
*/ */
private ChatRoomIrcImpl initiatePrivateChatRoom(String user) private ChatRoomIrcImpl initiatePrivateChatRoom(String userName)
{ {
OperationSetMultiUserChatIrcImpl muc = OperationSetMultiUserChatIrcImpl muc =
IrcStack.this.provider.getMUC(); IrcStack.this.provider.getMUC();
ChatRoomIrcImpl chatroom = muc.findOrCreateRoom(user); ChatRoomIrcImpl chatroom = muc.findOrCreateRoom(userName);
IrcStack.this.joined.put(chatroom.getIdentifier(), chatroom); IrcStack.this.joined.put(chatroom.getIdentifier(), chatroom);
ChatRoomMemberIrcImpl member = final ChatRoomMemberIrcImpl user =
new ChatRoomMemberIrcImpl(IrcStack.this.provider, chatroom, new ChatRoomMemberIrcImpl(IrcStack.this.provider, chatroom,
user, ChatRoomMemberRole.MEMBER); IrcStack.this.getNick(), ChatRoomMemberRole.MEMBER);
chatroom.addChatRoomMember(user.getContactAddress(), user);
final ChatRoomMemberIrcImpl member =
new ChatRoomMemberIrcImpl(IrcStack.this.provider, chatroom,
userName, ChatRoomMemberRole.MEMBER);
chatroom.addChatRoomMember(member.getContactAddress(), member); chatroom.addChatRoomMember(member.getContactAddress(), member);
IrcStack.this.provider.getMUC().fireLocalUserPresenceEvent( IrcStack.this.provider.getMUC().fireLocalUserPresenceEvent(
chatroom, chatroom,
@ -1046,13 +1045,17 @@ private ChatRoomIrcImpl initiatePrivateChatRoom(String user)
* chat room listener updates chat room data and fires events based on IRC * chat room listener updates chat room data and fires events based on IRC
* messages that report state changes for the specified channel. * messages that report state changes for the specified channel.
* *
* @author danny * @author Danny van Heumen
* *
*/ */
private class ChatRoomListener private class ChatRoomListener
extends VariousMessageListenerAdapter extends VariousMessageListenerAdapter
{ {
/**
* IRC error code for case where user is not joined to that channel.
*/
private static final int IRC_ERR_NOTONCHANNEL = 442; private static final int IRC_ERR_NOTONCHANNEL = 442;
/** /**
* Chat room for which this listener is working. * Chat room for which this listener is working.
*/ */
@ -1104,12 +1107,6 @@ public void onChannelJoin(ChanJoinMessage msg)
if (!isThisChatRoom(msg.getChannelName())) if (!isThisChatRoom(msg.getChannelName()))
return; return;
if (isMe(msg.getSource()))
{
// I think that this should not happen.
}
else
{
String user = msg.getSource().getNick(); String user = msg.getSource().getNick();
ChatRoomMemberIrcImpl member = ChatRoomMemberIrcImpl member =
new ChatRoomMemberIrcImpl(IrcStack.this.provider, new ChatRoomMemberIrcImpl(IrcStack.this.provider,
@ -1117,7 +1114,6 @@ public void onChannelJoin(ChanJoinMessage msg)
this.chatroom.fireMemberPresenceEvent(member, null, this.chatroom.fireMemberPresenceEvent(member, null,
ChatRoomMemberPresenceChangeEvent.MEMBER_JOINED, null); ChatRoomMemberPresenceChangeEvent.MEMBER_JOINED, null);
} }
}
/** /**
* Event in case of channel part. * Event in case of channel part.
@ -1128,14 +1124,15 @@ public void onChannelPart(ChanPartMessage msg)
if (!isThisChatRoom(msg.getChannelName())) if (!isThisChatRoom(msg.getChannelName()))
return; return;
if (isMe(msg.getSource())) IRCUser user = msg.getSource();
if (isMe(user))
{ {
leaveChatRoom(); leaveChatRoom();
return;
} }
else
{ String userNick = msg.getSource().getNick();
String user = msg.getSource().getNick(); ChatRoomMember member = this.chatroom.getChatRoomMember(userNick);
ChatRoomMember member = this.chatroom.getChatRoomMember(user);
try try
{ {
// Possibility that 'member' is null (should be fixed now // Possibility that 'member' is null (should be fixed now
@ -1151,7 +1148,6 @@ public void onChannelPart(ChanPartMessage msg)
+ "as it is a bug.", e); + "as it is a bug.", e);
} }
} }
}
/** /**
* Some of the generic message are relevant to us, so keep an eye on * Some of the generic message are relevant to us, so keep an eye on
@ -1196,28 +1192,25 @@ public void onChannelKick(ChannelKick msg)
return; return;
String kickedUser = msg.getKickedNickname(); String kickedUser = msg.getKickedNickname();
if (isMe(kickedUser))
{
IrcStack.this.irc.deleteListener(this);
IrcStack.this.joined.remove(this.chatroom.getIdentifier());
IrcStack.this.provider.getMUC().fireLocalUserPresenceEvent(
this.chatroom,
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_KICKED,
msg.getText());
}
else
{
ChatRoomMember kickedMember = ChatRoomMember kickedMember =
this.chatroom.getChatRoomMember(kickedUser); this.chatroom.getChatRoomMember(kickedUser);
String user = msg.getSource().getNick(); String user = msg.getSource().getNick();
if (kickedMember != null) if (kickedMember != null)
{ {
ChatRoomMember kicker = ChatRoomMember kicker = this.chatroom.getChatRoomMember(user);
this.chatroom.getChatRoomMember(user);
this.chatroom.fireMemberPresenceEvent(kickedMember, kicker, this.chatroom.fireMemberPresenceEvent(kickedMember, kicker,
ChatRoomMemberPresenceChangeEvent.MEMBER_KICKED, ChatRoomMemberPresenceChangeEvent.MEMBER_KICKED,
msg.getText()); msg.getText());
} }
if (isMe(kickedUser))
{
IrcStack.this.irc.deleteListener(this);
IrcStack.this.joined.remove(this.chatroom.getIdentifier());
IrcStack.this.provider.getMUC().fireLocalUserPresenceEvent(
this.chatroom,
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_KICKED,
msg.getText());
} }
} }
@ -1333,11 +1326,8 @@ private void processModeMessage(ChannelModeMessage msg)
} }
this.chatroom.fireLocalUserRoleChangedEvent(event); this.chatroom.fireLocalUserRoleChangedEvent(event);
} }
else
{
ChatRoomMember owner = ChatRoomMember owner =
this.chatroom this.chatroom.getChatRoomMember(mode.getParams()[0]);
.getChatRoomMember(mode.getParams()[0]);
if (owner != null) if (owner != null)
{ {
if (mode.isAdded()) if (mode.isAdded())
@ -1351,7 +1341,6 @@ private void processModeMessage(ChannelModeMessage msg)
ChatRoomMemberRole.SILENT_MEMBER); ChatRoomMemberRole.SILENT_MEMBER);
} }
} }
}
break; break;
case OPERATOR: case OPERATOR:
String opUserName = mode.getParams()[0]; String opUserName = mode.getParams()[0];
@ -1376,8 +1365,6 @@ private void processModeMessage(ChannelModeMessage msg)
} }
this.chatroom.fireLocalUserRoleChangedEvent(event); this.chatroom.fireLocalUserRoleChangedEvent(event);
} }
else
{
ChatRoomMember op = ChatRoomMember op =
this.chatroom.getChatRoomMember(opUserName); this.chatroom.getChatRoomMember(opUserName);
if (op != null) if (op != null)
@ -1393,7 +1380,6 @@ private void processModeMessage(ChannelModeMessage msg)
ChatRoomMemberRole.SILENT_MEMBER); ChatRoomMemberRole.SILENT_MEMBER);
} }
} }
}
break; break;
case VOICE: case VOICE:
String voiceUserName = mode.getParams()[0]; String voiceUserName = mode.getParams()[0];
@ -1417,8 +1403,6 @@ private void processModeMessage(ChannelModeMessage msg)
} }
this.chatroom.fireLocalUserRoleChangedEvent(event); this.chatroom.fireLocalUserRoleChangedEvent(event);
} }
else
{
ChatRoomMember voice = ChatRoomMember voice =
this.chatroom.getChatRoomMember(voiceUserName); this.chatroom.getChatRoomMember(voiceUserName);
if (voice != null) if (voice != null)
@ -1434,7 +1418,6 @@ private void processModeMessage(ChannelModeMessage msg)
ChatRoomMemberRole.SILENT_MEMBER); ChatRoomMemberRole.SILENT_MEMBER);
} }
} }
}
break; break;
case LIMIT: case LIMIT:
MessageIrcImpl limitMessage; MessageIrcImpl limitMessage;

Loading…
Cancel
Save