]> Pileus Git - ~andy/spades/commitdiff
Show topic and current users
authorAndy Spencer <andy753421@gmail.com>
Sat, 13 Apr 2013 02:37:15 +0000 (02:37 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sat, 13 Apr 2013 02:37:15 +0000 (02:37 +0000)
src/org/pileus/spades/Main.java
src/org/pileus/spades/Message.java

index ebca43920a6ef56b5073d59a8e7e6804c424c1d1..0ca360378b8fca5fe4612dd4347daafa4c861c1c 100644 (file)
@@ -22,13 +22,15 @@ import android.widget.Toast;
 public class Main extends Activity
 {
        /* Static data */
-       private Handler      handler; 
-       private Messenger    messenger; 
+       private Handler      handler;
+       private Messenger    messenger;
 
        /* Private data */
        private Task         task;
        private Toast        toast;
        private boolean      ready;
+       private String       topic;
+       private String       names;
 
        /* Widgets */
        private TabHost      window;
@@ -54,18 +56,33 @@ public class Main extends Activity
        {
                Message msg = (Message)obj;
 
+               // Debug
                this.debug.append("> " + msg.line + "\n");
                this.dscroll.smoothScrollTo(0, this.debug.getBottom());
 
-               if (msg.cmd.equals("PRIVMSG")) {
-                       this.log.append(msg.from + ": " + msg.msg + "\n");
-                       this.lscroll.smoothScrollTo(0, this.log.getBottom());
+               // Chat
+               switch (msg.type) {
+                       case PRIVMSG:
+                               this.log.append(msg.from + ": " + msg.msg + "\n");
+                               break;
+                       case TOPIC:
+                               if (!msg.txt.equals(this.topic))
+                                       this.log.append("** Topic for " + msg.arg + ": " + msg.txt + " **\n");
+                               this.topic = msg.txt;
+                               break;
+                       case NAMES:
+                               if (!msg.txt.equals(this.names))
+                                       this.log.append("** Users in " + msg.arg + ": " + msg.txt + " **\n");
+                               this.names = msg.txt;
+                               break;
                }
+               this.lscroll.smoothScrollTo(0, this.log.getBottom());
        }
 
        private void onNotify(String text)
        {
                Os.debug("Main: onNotify - " + text);
+               this.log.append("** " + text + " **\n");
                this.toast.setText(text);
                this.toast.show();
        }
index 73a8fabdba04ef3a82206c91cdf8296dd6b009e0..331657e890b55ba0550d1e6256a64b587370e0e7 100644 (file)
@@ -5,8 +5,16 @@ import java.util.regex.Matcher;
 
 public class Message
 {
+       /* Enumerations */
+       enum Type {
+               OTHER,
+               PRIVMSG,
+               TOPIC,
+               NAMES,
+       };
+
        /* Constnats */
-       private final  String  reMsg  = "(:([^ ]+) +)?(([A-Z0-9]+) +)(([^ ]+) +)?(([^: ]+) +)?(:(.*))";
+       private final  String  reMsg  = "(:([^ ]+) +)?(([A-Z0-9]+) +)(([^ ]+)[= ]+)?(([^: ]+) +)?(:(.*))";
        private final  String  reFrom = "([^! ]+)!.*";
        private final  String  reTo   = "(([^ :,]*)[:,] *)?(.*)";
 
@@ -23,6 +31,7 @@ public class Message
        public String  arg  = "";
        public String  msg  = "";
 
+       public Type    type = Type.OTHER;
        public String  from = "";
        public String  to   = "";
        public String  txt  = "";
@@ -45,15 +54,18 @@ public class Message
 
        public Message(String line)
        {
+               // Initialize regexes
                if (ptMsg  == null) ptMsg  = Pattern.compile(reMsg);
                if (ptFrom == null) ptFrom = Pattern.compile(reFrom);
                if (ptTo   == null) ptTo   = Pattern.compile(reTo);
 
+               // Cleanup line
                line = line.replaceAll("\\s+",       " ");
                line = line.replaceAll("^ | $",      "");
                line = line.replaceAll("\003[0-9]*", "");
                this.line = line;
 
+               // Split line into parts
                Matcher mrMsg = ptMsg.matcher(line);
                if (mrMsg.matches()) {
                        this.src  = notnull(mrMsg.group(2));
@@ -63,6 +75,7 @@ public class Message
                        this.msg  = notnull(mrMsg.group(10));
                }
 
+               // Determine friendly parts
                Matcher mrFrom = ptFrom.matcher(this.src);
                if (mrFrom.matches())
                        this.from = notnull(mrFrom.group(1));
@@ -75,6 +88,11 @@ public class Message
                        this.txt  = notnull(this.msg);
                else
                        this.txt  = notnull(mrTo.group(3));
+
+               // Parse commands names
+               if (this.cmd.equals("PRIVMSG")) this.type = Type.PRIVMSG;
+               if (this.cmd.equals("332"))     this.type = Type.TOPIC;
+               if (this.cmd.equals("353"))     this.type = Type.NAMES;
        }
 
        public void debug()