From 09cb4af8f367b377a5ecac24606d7941711b0b2c Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Wed, 10 Mar 2010 21:34:20 +0100 Subject: [PATCH] Yaaic now handles private queries :) --- src/org/yaaic/irc/IRCConnection.java | 32 ++++++++++++++++++++++---- src/org/yaaic/view/ServerActivity.java | 7 +++--- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/org/yaaic/irc/IRCConnection.java b/src/org/yaaic/irc/IRCConnection.java index 76e0898..009ce50 100644 --- a/src/org/yaaic/irc/IRCConnection.java +++ b/src/org/yaaic/irc/IRCConnection.java @@ -33,7 +33,9 @@ import org.yaaic.R; import org.yaaic.Yaaic; import org.yaaic.model.Broadcast; import org.yaaic.model.Channel; +import org.yaaic.model.Conversation; import org.yaaic.model.Message; +import org.yaaic.model.Query; import org.yaaic.model.Server; import org.yaaic.model.Status; @@ -343,14 +345,36 @@ public class IRCConnection extends PircBot * On Private Message */ @Override - protected void onPrivateMessage(String sender, String login, String hostname, String message) + protected void onPrivateMessage(String sender, String login, String hostname, String text) { - debug("PrivateMessage", sender + " " + message); + debug("PrivateMessage", sender + " " + text); // Strip mIRC colors and formatting - message = Colors.removeFormattingAndColors(message); + text = Colors.removeFormattingAndColors(text); - // XXX: Open a query if there's none yet + Conversation conversation = server.getConversation(sender); + + if (conversation == null) { + // Open a query if there's none yet + conversation = new Query(sender); + server.addConversationl(conversation); + + Message message = new Message("<" + sender + "> " + text); + conversation.addMessage(message); + + Intent intent = new Intent(Broadcast.CHANNEL_NEW); + intent.putExtra(Broadcast.EXTRA_CHANNEL, sender); + intent.putExtra(Broadcast.EXTRA_SERVER, server.getId()); + service.sendBroadcast(intent); + } else { + Message message = new Message("<" + sender + "> " + text); + conversation.addMessage(message); + + Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE); + intent.putExtra(Broadcast.EXTRA_SERVER, server.getId()); + intent.putExtra(Broadcast.EXTRA_CHANNEL, sender); + service.sendBroadcast(intent); + } } /** diff --git a/src/org/yaaic/view/ServerActivity.java b/src/org/yaaic/view/ServerActivity.java index 77b49f3..b7fae8c 100644 --- a/src/org/yaaic/view/ServerActivity.java +++ b/src/org/yaaic/view/ServerActivity.java @@ -56,7 +56,6 @@ import org.yaaic.irc.IRCBinder; import org.yaaic.irc.IRCService; import org.yaaic.listener.ChannelListener; import org.yaaic.model.Broadcast; -import org.yaaic.model.Channel; import org.yaaic.model.Conversation; import org.yaaic.model.Message; import org.yaaic.model.Server; @@ -339,9 +338,9 @@ public class ServerActivity extends Activity implements ServiceConnection, Chann */ public void onItemSelected(AdapterView deck, View view, int position, long id) { - Channel channel = (Channel) deck.getItemAtPosition(position); - if (channel != null) { - ((TextView) findViewById(R.id.title)).setText(server.getTitle() + " - " + channel.getName()); + Conversation conversation = (Conversation) deck.getItemAtPosition(position); + if (conversation != null) { + ((TextView) findViewById(R.id.title)).setText(server.getTitle() + " - " + conversation.getName()); } }