From caf3272f71bbc462c991389d88c00ecdb08b574a Mon Sep 17 00:00:00 2001 From: Steven Luo Date: Sun, 29 May 2011 17:48:47 -0700 Subject: [PATCH] Ensure privmsg with mention of user's nick opens new query when appropriate If a private message that should open a new query window contains a mention of the user's nick, the expected new window fails to open because the isMentioned() path tries to use server.getConversation().setStatus(), and server.getConversation() is null in this case. Fix this by moving the attempt to highlight the window to a point where a conversation is guaranteed to exist. --- .../src/org/yaaic/irc/IRCConnection.java | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/application/src/org/yaaic/irc/IRCConnection.java b/application/src/org/yaaic/irc/IRCConnection.java index 667c329..6b9d0f1 100644 --- a/application/src/org/yaaic/irc/IRCConnection.java +++ b/application/src/org/yaaic/irc/IRCConnection.java @@ -203,24 +203,14 @@ public class IRCConnection extends PircBot @Override protected void onAction(String sender, String login, String hostname, String target, String action) { + Conversation conversation; + Message message = new Message(sender + " " + action); message.setIcon(R.drawable.action); - if (isMentioned(action)) { - // highlight - message.setColor(Message.COLOR_RED); - service.updateNotification( - target + ": " + sender + " " + action, - service.getSettings().isVibrateHighlightEnabled(), - service.getSettings().isSoundHighlightEnabled() - ); - - server.getConversation(target).setStatus(Conversation.STATUS_HIGHLIGHT); - } - if (target.equals(this.getNick())) { // We are the target - this is an action in a query - Conversation conversation = server.getConversation(sender); + conversation = server.getConversation(sender); if (conversation == null) { // Open a query if there's none yet conversation = new Query(sender); @@ -243,7 +233,8 @@ public class IRCConnection extends PircBot } } else { // A action in a channel - server.getConversation(target).addMessage(message); + conversation = server.getConversation(target); + conversation.addMessage(message); Intent intent = Broadcast.createConversationIntent( Broadcast.CONVERSATION_MESSAGE, @@ -252,6 +243,18 @@ public class IRCConnection extends PircBot ); service.sendBroadcast(intent); } + + if (isMentioned(action)) { + // highlight + message.setColor(Message.COLOR_RED); + service.updateNotification( + target + ": " + sender + " " + action, + service.getSettings().isVibrateHighlightEnabled(), + service.getSettings().isSoundHighlightEnabled() + ); + + conversation.setStatus(Conversation.STATUS_HIGHLIGHT); + } } /** @@ -580,17 +583,6 @@ public class IRCConnection extends PircBot { Message message = new Message("<" + sender + "> " + text); - if (isMentioned(text)) { - message.setColor(Message.COLOR_RED); - service.updateNotification( - "<" + sender + "> " + text, - service.getSettings().isVibrateHighlightEnabled(), - service.getSettings().isSoundHighlightEnabled() - ); - - server.getConversation(sender).setStatus(Conversation.STATUS_HIGHLIGHT); - } - Conversation conversation = server.getConversation(sender); if (conversation == null) { @@ -615,6 +607,17 @@ public class IRCConnection extends PircBot ); service.sendBroadcast(intent); } + + if (isMentioned(text)) { + message.setColor(Message.COLOR_RED); + service.updateNotification( + "<" + sender + "> " + text, + service.getSettings().isVibrateHighlightEnabled(), + service.getSettings().isSoundHighlightEnabled() + ); + + conversation.setStatus(Conversation.STATUS_HIGHLIGHT); + } } /**