Added basic workaround support for receiving private messages.

Implemented basic support for receiving private message, by simply
letting every channel fire a received message-event when a private
message from a channel user is received.
Of course you cannot receive messages from users that have no joined
channels in common with the local user. Also, the private message is
only recognizable by 'PRIVATE: ' and the ACTION-style formatting.
Clearly not desirable in the long run.
fix-message-formatting
Danny van Heumen 12 years ago
parent fae05d14dc
commit bda9567a61

@ -476,9 +476,30 @@ public void invite(String memberId, ChatRoomIrcImpl chatroom)
// TODO Implement this.
}
/**
* Send a command to the IRC server.
* @param chatroom the chat room
* @param command the command message
*/
public void command(ChatRoomIrcImpl chatroom, String command)
{
// TODO Implement this.
String target;
if (command.startsWith("/msg "))
{
command = command.substring(5);
int endOfNick = command.indexOf(' ');
if (endOfNick == -1)
{
throw new IllegalArgumentException("Invalid private message format. Message was not sent.");
}
target = command.substring(0, endOfNick);
command = command.substring(endOfNick+1);
}
else
{
target = chatroom.getIdentifier();
}
this.irc.message(target, command);
}
/**
@ -489,7 +510,8 @@ public void command(ChatRoomIrcImpl chatroom, String command)
*/
public void message(ChatRoomIrcImpl chatroom, String message)
{
this.irc.message(chatroom.getIdentifier(), message);
String target = chatroom.getIdentifier();
this.irc.message(target, message);
}
/**
@ -662,6 +684,25 @@ public void onChannelMessage(ChannelPrivMsg msg)
this.chatroom.fireMessageReceivedEvent(message, member, new Date(),
ChatRoomMessageReceivedEvent.CONVERSATION_MESSAGE_RECEIVED);
}
@Override
public void onUserPrivMessage(UserPrivMsg msg)
{
//TODO DEBUG code
System.out.printf("Received private message from: %s", msg
.getSource().getNick());
String sourceNick = msg.getSource().getNick();
ChatRoomMember source = this.chatroom.getChatRoomMember(sourceNick);
if (source != null)
{
MessageIrcImpl message =
new MessageIrcImpl("PRIVATE: " + msg.getText(),
"text/plain", "UTF-8", null);
this.chatroom.fireMessageReceivedEvent(message, source,
new Date(),
ChatRoomMessageReceivedEvent.ACTION_MESSAGE_RECEIVED);
}
}
private void processModeMessage(ChannelModeMessage msg)
{

Loading…
Cancel
Save