|
|
|
@ -14,15 +14,14 @@
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
import net.java.sip.communicator.service.muc.ChatRoomPresenceStatus;
|
|
|
|
import net.java.sip.communicator.impl.protocol.irc.ModeParser.Mode;
|
|
|
|
import net.java.sip.communicator.service.protocol.ChatRoomMember;
|
|
|
|
import net.java.sip.communicator.service.protocol.ChatRoomMember;
|
|
|
|
import net.java.sip.communicator.service.protocol.ChatRoomMemberRole;
|
|
|
|
import net.java.sip.communicator.service.protocol.ChatRoomMemberRole;
|
|
|
|
import net.java.sip.communicator.service.protocol.RegistrationState;
|
|
|
|
import net.java.sip.communicator.service.protocol.RegistrationState;
|
|
|
|
import net.java.sip.communicator.service.protocol.event.ChatRoomMemberPresenceChangeEvent;
|
|
|
|
import net.java.sip.communicator.service.protocol.event.ChatRoomMemberPresenceChangeEvent;
|
|
|
|
import net.java.sip.communicator.service.protocol.event.ChatRoomMessageReceivedEvent;
|
|
|
|
import net.java.sip.communicator.service.protocol.event.ChatRoomMessageReceivedEvent;
|
|
|
|
import net.java.sip.communicator.service.protocol.event.ChatRoomPropertyChangeEvent;
|
|
|
|
|
|
|
|
import net.java.sip.communicator.service.protocol.event.LocalUserChatRoomPresenceChangeEvent;
|
|
|
|
import net.java.sip.communicator.service.protocol.event.LocalUserChatRoomPresenceChangeEvent;
|
|
|
|
import net.java.sip.communicator.service.protocol.event.RegistrationStateChangeEvent;
|
|
|
|
import net.java.sip.communicator.service.protocol.event.MessageReceivedEvent;
|
|
|
|
|
|
|
|
|
|
|
|
import com.ircclouds.irc.api.Callback;
|
|
|
|
import com.ircclouds.irc.api.Callback;
|
|
|
|
import com.ircclouds.irc.api.IRCApi;
|
|
|
|
import com.ircclouds.irc.api.IRCApi;
|
|
|
|
@ -53,8 +52,11 @@ public class IrcStack
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// private static final Logger LOGGER = Logger.getLogger(IrcStack.class);
|
|
|
|
// private static final Logger LOGGER = Logger.getLogger(IrcStack.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO Create an enum for this.
|
|
|
|
private static final char MODE_MEMBER_OWNER = 'O';
|
|
|
|
private static final char MODE_MEMBER_OWNER = 'O';
|
|
|
|
|
|
|
|
|
|
|
|
private static final char MODE_MEMBER_OPERATOR = 'o';
|
|
|
|
private static final char MODE_MEMBER_OPERATOR = 'o';
|
|
|
|
|
|
|
|
|
|
|
|
private static final char MODE_MEMBER_VOICE = 'v';
|
|
|
|
private static final char MODE_MEMBER_VOICE = 'v';
|
|
|
|
|
|
|
|
|
|
|
|
private final ProtocolProviderServiceIrcImpl provider;
|
|
|
|
private final ProtocolProviderServiceIrcImpl provider;
|
|
|
|
@ -86,10 +88,16 @@ public boolean isConnected()
|
|
|
|
.isConnected());
|
|
|
|
.isConnected());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isSecureConnection()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return isConnected() && this.connectionState.getServer().isSSL();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void connect(String host, int port, String password,
|
|
|
|
public void connect(String host, int port, String password,
|
|
|
|
boolean autoNickChange)
|
|
|
|
boolean autoNickChange)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (this.irc != null && this.connectionState != null && this.connectionState.isConnected())
|
|
|
|
if (this.irc != null && this.connectionState != null
|
|
|
|
|
|
|
|
&& this.connectionState.isConnected())
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
this.irc = new IRCApiImpl(true);
|
|
|
|
this.irc = new IRCApiImpl(true);
|
|
|
|
@ -184,7 +192,8 @@ public void disconnect()
|
|
|
|
this.irc.disconnect();
|
|
|
|
this.irc.disconnect();
|
|
|
|
this.irc = null;
|
|
|
|
this.irc = null;
|
|
|
|
this.connectionState = null;
|
|
|
|
this.connectionState = null;
|
|
|
|
this.provider.setCurrentRegistrationState(RegistrationState.UNREGISTERED);
|
|
|
|
this.provider
|
|
|
|
|
|
|
|
.setCurrentRegistrationState(RegistrationState.UNREGISTERED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -213,7 +222,7 @@ public void setUserNickname(String nick)
|
|
|
|
|
|
|
|
|
|
|
|
public void setSubject(ChatRoomIrcImpl chatroom, String subject)
|
|
|
|
public void setSubject(ChatRoomIrcImpl chatroom, String subject)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (this.connectionState == null)
|
|
|
|
if (isConnected() == false)
|
|
|
|
throw new IllegalStateException(
|
|
|
|
throw new IllegalStateException(
|
|
|
|
"Please connect to an IRC server first.");
|
|
|
|
"Please connect to an IRC server first.");
|
|
|
|
if (chatroom == null)
|
|
|
|
if (chatroom == null)
|
|
|
|
@ -241,6 +250,9 @@ public void join(ChatRoomIrcImpl chatroom)
|
|
|
|
|
|
|
|
|
|
|
|
public void join(final ChatRoomIrcImpl chatroom, final String password)
|
|
|
|
public void join(final ChatRoomIrcImpl chatroom, final String password)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (isConnected() == false)
|
|
|
|
|
|
|
|
throw new IllegalStateException(
|
|
|
|
|
|
|
|
"Please connect to an IRC server first");
|
|
|
|
// TODO password as String
|
|
|
|
// TODO password as String
|
|
|
|
if (chatroom == null)
|
|
|
|
if (chatroom == null)
|
|
|
|
throw new IllegalArgumentException("chatroom cannot be null");
|
|
|
|
throw new IllegalArgumentException("chatroom cannot be null");
|
|
|
|
@ -272,7 +284,9 @@ public void onSuccess(IRCChannel channel)
|
|
|
|
ChatRoomMemberRole.SILENT_MEMBER;
|
|
|
|
ChatRoomMemberRole.SILENT_MEMBER;
|
|
|
|
for (IRCUserStatus status : statuses)
|
|
|
|
for (IRCUserStatus status : statuses)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
role = convertMemberMode(status.getChanModeType().charValue());
|
|
|
|
role =
|
|
|
|
|
|
|
|
convertMemberMode(status.getChanModeType()
|
|
|
|
|
|
|
|
.charValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (IrcStack.this.getNick().equals(user.getNick()))
|
|
|
|
if (IrcStack.this.getNick().equals(user.getNick()))
|
|
|
|
@ -282,10 +296,11 @@ public void onSuccess(IRCChannel channel)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ChatRoomMemberIrcImpl member =
|
|
|
|
ChatRoomMemberIrcImpl member =
|
|
|
|
new ChatRoomMemberIrcImpl(IrcStack.this.provider,
|
|
|
|
new ChatRoomMemberIrcImpl(
|
|
|
|
chatroom, user.getNick(), role);
|
|
|
|
IrcStack.this.provider, chatroom, user
|
|
|
|
chatroom.addChatRoomMember(member.getContactAddress(),
|
|
|
|
.getNick(), role);
|
|
|
|
member);
|
|
|
|
chatroom.addChatRoomMember(
|
|
|
|
|
|
|
|
member.getContactAddress(), member);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -296,9 +311,16 @@ public void onSuccess(IRCChannel channel)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onFailure(Exception aExc)
|
|
|
|
public void onFailure(Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
MessageIrcImpl message =
|
|
|
|
|
|
|
|
new MessageIrcImpl("Failed to join channel "
|
|
|
|
|
|
|
|
+ chatroom.getIdentifier(), "text/plain", "UTF-8",
|
|
|
|
|
|
|
|
"Failed to join");
|
|
|
|
|
|
|
|
chatroom.fireMessageReceivedEvent(message, null,
|
|
|
|
|
|
|
|
new Date(),
|
|
|
|
|
|
|
|
MessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -342,7 +364,7 @@ public void message(ChatRoomIrcImpl chatroom, String message)
|
|
|
|
|
|
|
|
|
|
|
|
private static ChatRoomMemberRole convertMemberMode(char mode)
|
|
|
|
private static ChatRoomMemberRole convertMemberMode(char mode)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
switch(mode)
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case MODE_MEMBER_OWNER:
|
|
|
|
case MODE_MEMBER_OWNER:
|
|
|
|
return ChatRoomMemberRole.OWNER;
|
|
|
|
return ChatRoomMemberRole.OWNER;
|
|
|
|
@ -351,7 +373,8 @@ private static ChatRoomMemberRole convertMemberMode(char mode)
|
|
|
|
case MODE_MEMBER_VOICE:
|
|
|
|
case MODE_MEMBER_VOICE:
|
|
|
|
return ChatRoomMemberRole.MEMBER;
|
|
|
|
return ChatRoomMemberRole.MEMBER;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
throw new IllegalArgumentException("Unknown member mode '"+mode+"'.");
|
|
|
|
throw new IllegalArgumentException("Unknown member mode '" + mode
|
|
|
|
|
|
|
|
+ "'.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -368,11 +391,6 @@ private ChatRoomListener(ChatRoomIrcImpl chatroom)
|
|
|
|
this.chatroom = chatroom;
|
|
|
|
this.chatroom = chatroom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isThisChatRoom(String chatRoomName)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return this.chatroom.getIdentifier().equals(chatRoomName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onTopicChange(TopicMessage msg)
|
|
|
|
public void onTopicChange(TopicMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -387,7 +405,7 @@ public void onChannelMode(ChannelModeMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (isThisChatRoom(msg.getChannelName()))
|
|
|
|
if (isThisChatRoom(msg.getChannelName()))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.out.println("MODE: " + msg.getModeStr());
|
|
|
|
processModeMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -398,15 +416,16 @@ public void onChannelJoin(ChanJoinMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
String user = msg.getSource().getNick();
|
|
|
|
String user = msg.getSource().getNick();
|
|
|
|
|
|
|
|
|
|
|
|
if (IrcStack.this.getNick().equals(msg.getSource().getNick()))
|
|
|
|
if (isMe(msg.getSource()))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//I think that this should not happen.
|
|
|
|
// I think that this should not happen.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ChatRoomMemberIrcImpl member =
|
|
|
|
ChatRoomMemberIrcImpl member =
|
|
|
|
new ChatRoomMemberIrcImpl(IrcStack.this.provider,
|
|
|
|
new ChatRoomMemberIrcImpl(IrcStack.this.provider,
|
|
|
|
this.chatroom, user, ChatRoomMemberRole.SILENT_MEMBER);
|
|
|
|
this.chatroom, user,
|
|
|
|
|
|
|
|
ChatRoomMemberRole.SILENT_MEMBER);
|
|
|
|
this.chatroom.fireMemberPresenceEvent(member, null,
|
|
|
|
this.chatroom.fireMemberPresenceEvent(member, null,
|
|
|
|
ChatRoomMemberPresenceChangeEvent.MEMBER_JOINED, null);
|
|
|
|
ChatRoomMemberPresenceChangeEvent.MEMBER_JOINED, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -420,11 +439,12 @@ public void onChannelPart(ChanPartMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
String user = msg.getSource().getNick();
|
|
|
|
String user = msg.getSource().getNick();
|
|
|
|
|
|
|
|
|
|
|
|
if (IrcStack.this.getNick().equals(msg.getSource().getNick()))
|
|
|
|
if (isMe(msg.getSource()))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IrcStack.this.provider.getMUC().fireLocalUserPresenceEvent(
|
|
|
|
IrcStack.this.provider.getMUC().fireLocalUserPresenceEvent(
|
|
|
|
this.chatroom,
|
|
|
|
this.chatroom,
|
|
|
|
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_LEFT, null);
|
|
|
|
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_LEFT,
|
|
|
|
|
|
|
|
null);
|
|
|
|
IrcStack.this.joined.remove(this.chatroom.getIdentifier());
|
|
|
|
IrcStack.this.joined.remove(this.chatroom.getIdentifier());
|
|
|
|
IrcStack.this.irc.deleteListener(this);
|
|
|
|
IrcStack.this.irc.deleteListener(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -469,6 +489,74 @@ public void onChannelMessage(ChannelPrivMsg msg)
|
|
|
|
ChatRoomMessageReceivedEvent.CONVERSATION_MESSAGE_RECEIVED);
|
|
|
|
ChatRoomMessageReceivedEvent.CONVERSATION_MESSAGE_RECEIVED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void processModeMessage(ChannelModeMessage msg)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ModeParser parser = new ModeParser(msg);
|
|
|
|
|
|
|
|
for (Mode mode : parser.getModes())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (mode.getMode())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 'O':
|
|
|
|
|
|
|
|
ChatRoomMember owner =
|
|
|
|
|
|
|
|
this.chatroom.getChatRoomMember(mode.getParams()[0]);
|
|
|
|
|
|
|
|
if (mode.isAdded())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.chatroom.fireMemberRoleEvent(owner,
|
|
|
|
|
|
|
|
ChatRoomMemberRole.OWNER);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.chatroom.fireMemberRoleEvent(owner,
|
|
|
|
|
|
|
|
ChatRoomMemberRole.SILENT_MEMBER);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
|
|
|
|
ChatRoomMember op =
|
|
|
|
|
|
|
|
this.chatroom.getChatRoomMember(mode.getParams()[0]);
|
|
|
|
|
|
|
|
if (mode.isAdded())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.chatroom.fireMemberRoleEvent(op,
|
|
|
|
|
|
|
|
ChatRoomMemberRole.ADMINISTRATOR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.chatroom.fireMemberRoleEvent(op,
|
|
|
|
|
|
|
|
ChatRoomMemberRole.SILENT_MEMBER);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
|
|
|
|
ChatRoomMember voice =
|
|
|
|
|
|
|
|
this.chatroom.getChatRoomMember(mode.getParams()[0]);
|
|
|
|
|
|
|
|
if (mode.isAdded())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.chatroom.fireMemberRoleEvent(voice,
|
|
|
|
|
|
|
|
ChatRoomMemberRole.MEMBER);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.chatroom.fireMemberRoleEvent(voice,
|
|
|
|
|
|
|
|
ChatRoomMemberRole.SILENT_MEMBER);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
System.out.println("Unsupported mode '" + mode.getMode()
|
|
|
|
|
|
|
|
+ "' (from modestring '" + msg.getModeStr() + "')");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isThisChatRoom(String chatRoomName)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return this.chatroom.getIdentifier().equals(chatRoomName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isMe(IRCUser user)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return IrcStack.this.connectionState.getNickname().equals(
|
|
|
|
|
|
|
|
user.getNick());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static class ServerParameters
|
|
|
|
private static class ServerParameters
|
|
|
|
|