muc_log.vala
changeset 9 d3260253f0bd
parent 8 dfd274c668f9
child 12 d3e36b368fc5
--- 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);
             }
         });
     }