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.
---
 application/src/org/yaaic/irc/IRCConnection.java |   53 +++++++++++----------
 1 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/application/src/org/yaaic/irc/IRCConnection.java 
b/application/src/org/yaaic/irc/IRCConnection.java
index 7360597..15c67b9 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);
@@ -245,7 +235,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,
@@ -254,6 +245,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);
+        }
     }
 
     /**
@@ -582,17 +585,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) {
@@ -617,6 +609,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);
+        }
     }
 
     /**
-- 
1.7.2.5

Reply via email to