Moved nick colors to vala code
authorStiletto <blasux@blasux.ru>
Wed, 24 Oct 2012 14:08:16 +0400
changeset 9 d3260253f0bd
parent 8 dfd274c668f9
child 10 6b0d56b01ba0
Moved nick colors to vala code
logs/script.js
logs/style.css
muc.vala
muc_log.vala
--- a/logs/script.js	Wed Oct 24 01:03:02 2012 +0400
+++ b/logs/script.js	Wed Oct 24 14:08:16 2012 +0400
@@ -2,10 +2,11 @@
     var log = document.getElementById("log");
     var rows = log.getElementsByTagName("tr");
     var rownum = rows.length;
+    var urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
     for (var i = 0; i < rownum; i++) {
         var row = rows[i];
         if (row.getAttribute("class") == "message") {
-            var nicktd = row.getElementsByClassName("nick")[0];
+            /*var nicktd = row.getElementsByClassName("nick")[0];
             if (nicktd) {
                 var nick = nicktd.textContent;
                 var sum = 0;
@@ -13,6 +14,12 @@
                     sum += 0x56 ^ nick.charCodeAt(j);
                 }
                 nicktd.setAttribute("class","nick nick"+(sum % 10));
+            }*/
+            var texttd = row.getElementsByClassName("text")[0];
+            if (texttd) {
+                texttd.innerHTML = texttd.innerHTML.replace(urlRegex, function(url) {
+                            return '<a href="' + url + '">' + url + '</a>';
+                });
             }
         }
     }
--- a/logs/style.css	Wed Oct 24 01:03:02 2012 +0400
+++ b/logs/style.css	Wed Oct 24 14:08:16 2012 +0400
@@ -134,3 +134,6 @@
 tr.part td.nick, tr.part td.text {
     color: #550000;
 }
+tr.action  td.text {
+    font-style: italic;
+}
--- a/muc.vala	Wed Oct 24 01:03:02 2012 +0400
+++ b/muc.vala	Wed Oct 24 14:08:16 2012 +0400
@@ -49,6 +49,7 @@
         public weak Conference conference;
         public string nick;
         public string real_jid;
+        public string status;
         public Affiliation affil;
         public Role role;
         public bool isme;
@@ -64,7 +65,7 @@
 
     public signal void state_changed(Conference conf, State old_state, State new_state, string description);
     public signal void on_join(Conference conf, Occupant occupant);
-    public signal void on_part(Conference conf, Occupant occupant);
+    public signal void on_part(Conference conf, Occupant occupant, string? status);
     public signal void on_role(Conference conf, Occupant occupant, Role prev);
     public signal void on_affil(Conference conf, Occupant occupant, Affiliation prev);
     public signal void on_nick(Conference conf, Occupant occupant, string prev);
@@ -170,8 +171,9 @@
                             if (occupant != null) {
                                 if (role == Role.NONE) {
                                     occupants.unset(from[1]);
+                                    var status_child = node.get_child("status");
                                     log("Muc", LogLevelFlags.LEVEL_INFO, "MUC<%s> %s has parted.", this.jid, from[1]);
-                                    module.on_part(this, occupant);
+                                    module.on_part(this, occupant, (status_child!=null) ? status_child.get_value() : null);
                                     if (occupant.isme) {
                                         _change_state(State.DISCONNECTED, "we became unavailable");
                                     }
@@ -194,19 +196,21 @@
                                     }
                                 }
                             } else {
-                                assert( role!= Role.NONE);
-                                occupant = new Occupant();
-                                occupant.role = role;
-                                occupant.affil = affil;
-                                occupant.nick = from[1];
-                                occupants[from[1]] = occupant;
-                                occupant.isme = statuses.contains(110);
-                                log("Muc", LogLevelFlags.LEVEL_INFO, "MUC<%s> %s has joined as %s/%s.", this.jid, from[1], affil.to_string(), role.to_string());
-                                if (statuses.contains(110)) {
-                                    this.nick = from[1];
-                                    _change_state(State.CONNECTED, "got own presence. we are "+this.nick);
-                                }
-                                module.on_join(this, occupant);
+                                if( role!= Role.NONE) {
+                                    occupant = new Occupant();
+                                    occupant.role = role;
+                                    occupant.affil = affil;
+                                    occupant.nick = from[1];
+                                    occupants[from[1]] = occupant;
+                                    occupant.isme = statuses.contains(110);
+                                    log("Muc", LogLevelFlags.LEVEL_INFO, "MUC<%s> %s has joined as %s/%s.", this.jid, from[1], affil.to_string(), role.to_string());
+                                    if (statuses.contains(110)) {
+                                        this.nick = from[1];
+                                        _change_state(State.CONNECTED, "got own presence. we are "+this.nick);
+                                    }
+                                    module.on_join(this, occupant);
+                                } else
+                                    log("Muc", LogLevelFlags.LEVEL_WARNING, "Got NONE role for new participant. Maybe we are reconnecting.");
                             }
                             
                             stdout.printf("User list: ");
--- a/muc_log.vala	Wed Oct 24 01:03:02 2012 +0400
+++ b/muc_log.vala	Wed Oct 24 14:08:16 2012 +0400
@@ -21,10 +21,19 @@
             this.muclog = muclog;
             logpath = muclog.getconf(jid, "log-path", null);
             filename = null;
-            write(Time.local(new time_t()), "logstart", "", "Log started");
+            write(Time.local(time_t()), "logstart", "", "Log started");
         }
         ~RoomLog() {
-            write(Time.local(new time_t()), "logstop", "", "Log stopped");
+            write(Time.local(time_t()), "logstop", "", "Log stopped");
+        }
+
+        public static uint nick_hash(string s) {
+            uint sum = 0;
+            const uint k = 102, m = 54, l = 140;
+            for( var j = 0, iTop = s.length; j < iTop; j++ ) {
+                sum += k ^ s[j];
+            }
+            return ((sum ^ m)+l)%10;
         }
         public void write(Time time, string _class, string nick, string str) {
 
@@ -74,8 +83,10 @@
             
             var id = getid(time);
             var times = time.format("%H:%M:%S");
+            var nicklass = (_class=="message") ? (" nick%u".printf(nick_hash(nick))) : "";
+
             file.printf("<tr id='l_%s' class='%s'><td class='time'><a id='i_%s' href='#i_%s'>%s</a></td>", id, _class, id, id, times);
-            file.printf("<td class='nick'>%s</td><td class='text'>%s</td></tr>\n", nick, str);
+            file.printf("<td class='nick%s'>%s</td><td class='text'>%s</td></tr>\n", nicklass, nick, str);
             file.flush();
         }
             
@@ -112,7 +123,7 @@
                                 notfirst=true;
                             sb.append(Markup.escape_text(occupant.nick).replace(" ","&nbsp;"));
                         }
-                        room.write(Time.local(new time_t()), "userlist", "", sb.str);
+                        room.write(Time.local(time_t()), "userlist", "", sb.str);
                     }
                     break;
                 case ModuleMuc.State.DISCONNECTED:
@@ -125,7 +136,10 @@
                 var room = rooms[conf.jid];
                 if (room!=null) {
                     var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
-                    room.write(Time.local(new time_t()), "message", nick, Markup.escape_text(body).replace("\n","<br/>"));
+                    if (body.has_prefix("/me ")) {
+                        room.write(Time.local(time_t()), "action", "*", nick+Markup.escape_text(body[3:body.length]).replace("\n","<br/>"));
+                    } else
+                        room.write(Time.local(time_t()), "message", nick, Markup.escape_text(body).replace("\n","<br/>"));
                 }
             }
         });
@@ -133,14 +147,23 @@
             var room = rooms[conf.jid];
             if (room!=null) {
                 var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
-                room.write(Time.local(new time_t()), "join", "*", nick+" has joined the room");
+                room.write(Time.local(time_t()), "join", "*", nick+" has joined the room");
             }
         });
-        muc.on_part.connect( (conf, user) => {
+        muc.on_part.connect( (conf, user, status) => {
             var room = rooms[conf.jid];
             if (room!=null) {
                 var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
-                room.write(Time.local(new time_t()), "part", "*", nick+" has left the room");
+                room.write(Time.local(time_t()), "part", "*",
+                    nick+" has left the room"+((status!=null) ? (": "+Markup.escape_text(status)) : ""));
+            }
+        });
+        muc.on_nick.connect( (conf, user, prev) => {
+            var room = rooms[conf.jid];
+            if (room!=null) {
+                var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
+                var nickp = Markup.escape_text(prev).replace(" ","&nbsp;"); 
+                room.write(Time.local(time_t()), "nickchange", "*", nickp+" is now known as "+nick);
             }
         });
     }