muc_log.vala
changeset 9 d3260253f0bd
parent 8 dfd274c668f9
child 12 d3e36b368fc5
equal deleted inserted replaced
8:dfd274c668f9 9:d3260253f0bd
    19         public RoomLog(ModuleMucLog muclog, string jid) {
    19         public RoomLog(ModuleMucLog muclog, string jid) {
    20             this.jid = jid;
    20             this.jid = jid;
    21             this.muclog = muclog;
    21             this.muclog = muclog;
    22             logpath = muclog.getconf(jid, "log-path", null);
    22             logpath = muclog.getconf(jid, "log-path", null);
    23             filename = null;
    23             filename = null;
    24             write(Time.local(new time_t()), "logstart", "", "Log started");
    24             write(Time.local(time_t()), "logstart", "", "Log started");
    25         }
    25         }
    26         ~RoomLog() {
    26         ~RoomLog() {
    27             write(Time.local(new time_t()), "logstop", "", "Log stopped");
    27             write(Time.local(time_t()), "logstop", "", "Log stopped");
       
    28         }
       
    29 
       
    30         public static uint nick_hash(string s) {
       
    31             uint sum = 0;
       
    32             const uint k = 102, m = 54, l = 140;
       
    33             for( var j = 0, iTop = s.length; j < iTop; j++ ) {
       
    34                 sum += k ^ s[j];
       
    35             }
       
    36             return ((sum ^ m)+l)%10;
    28         }
    37         }
    29         public void write(Time time, string _class, string nick, string str) {
    38         public void write(Time time, string _class, string nick, string str) {
    30 
    39 
    31             if ((lastday != time.day)||(lastmonth != time.month)||(lastyear!=time.year)) {
    40             if ((lastday != time.day)||(lastmonth != time.month)||(lastyear!=time.year)) {
    32                 var fname = time.format(logpath).replace("<muc>",jid);
    41                 var fname = time.format(logpath).replace("<muc>",jid);
    72                 lastyear = time.year; lastmonth = time.month; lastday = time.day;
    81                 lastyear = time.year; lastmonth = time.month; lastday = time.day;
    73             }
    82             }
    74             
    83             
    75             var id = getid(time);
    84             var id = getid(time);
    76             var times = time.format("%H:%M:%S");
    85             var times = time.format("%H:%M:%S");
       
    86             var nicklass = (_class=="message") ? (" nick%u".printf(nick_hash(nick))) : "";
       
    87 
    77             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);
    88             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);
    78             file.printf("<td class='nick'>%s</td><td class='text'>%s</td></tr>\n", nick, str);
    89             file.printf("<td class='nick%s'>%s</td><td class='text'>%s</td></tr>\n", nicklass, nick, str);
    79             file.flush();
    90             file.flush();
    80         }
    91         }
    81             
    92             
    82     }
    93     }
    83     public string getconf(string jid, string key, string? def) {
    94     public string getconf(string jid, string key, string? def) {
   110                                 sb.append(", ");
   121                                 sb.append(", ");
   111                             else
   122                             else
   112                                 notfirst=true;
   123                                 notfirst=true;
   113                             sb.append(Markup.escape_text(occupant.nick).replace(" ","&nbsp;"));
   124                             sb.append(Markup.escape_text(occupant.nick).replace(" ","&nbsp;"));
   114                         }
   125                         }
   115                         room.write(Time.local(new time_t()), "userlist", "", sb.str);
   126                         room.write(Time.local(time_t()), "userlist", "", sb.str);
   116                     }
   127                     }
   117                     break;
   128                     break;
   118                 case ModuleMuc.State.DISCONNECTED:
   129                 case ModuleMuc.State.DISCONNECTED:
   119                     rooms.unset(conf.jid);
   130                     rooms.unset(conf.jid);
   120                     break;
   131                     break;
   123         muc.on_message.connect( (conf, user, message, body) => {
   134         muc.on_message.connect( (conf, user, message, body) => {
   124             if ((user!=null)&&(body!=null)&&(message.get_child("delay")==null)) {
   135             if ((user!=null)&&(body!=null)&&(message.get_child("delay")==null)) {
   125                 var room = rooms[conf.jid];
   136                 var room = rooms[conf.jid];
   126                 if (room!=null) {
   137                 if (room!=null) {
   127                     var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
   138                     var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
   128                     room.write(Time.local(new time_t()), "message", nick, Markup.escape_text(body).replace("\n","<br/>"));
   139                     if (body.has_prefix("/me ")) {
       
   140                         room.write(Time.local(time_t()), "action", "*", nick+Markup.escape_text(body[3:body.length]).replace("\n","<br/>"));
       
   141                     } else
       
   142                         room.write(Time.local(time_t()), "message", nick, Markup.escape_text(body).replace("\n","<br/>"));
   129                 }
   143                 }
   130             }
   144             }
   131         });
   145         });
   132         muc.on_join.connect( (conf, user) => {
   146         muc.on_join.connect( (conf, user) => {
   133             var room = rooms[conf.jid];
   147             var room = rooms[conf.jid];
   134             if (room!=null) {
   148             if (room!=null) {
   135                 var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
   149                 var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
   136                 room.write(Time.local(new time_t()), "join", "*", nick+" has joined the room");
   150                 room.write(Time.local(time_t()), "join", "*", nick+" has joined the room");
   137             }
   151             }
   138         });
   152         });
   139         muc.on_part.connect( (conf, user) => {
   153         muc.on_part.connect( (conf, user, status) => {
   140             var room = rooms[conf.jid];
   154             var room = rooms[conf.jid];
   141             if (room!=null) {
   155             if (room!=null) {
   142                 var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
   156                 var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
   143                 room.write(Time.local(new time_t()), "part", "*", nick+" has left the room");
   157                 room.write(Time.local(time_t()), "part", "*",
       
   158                     nick+" has left the room"+((status!=null) ? (": "+Markup.escape_text(status)) : ""));
       
   159             }
       
   160         });
       
   161         muc.on_nick.connect( (conf, user, prev) => {
       
   162             var room = rooms[conf.jid];
       
   163             if (room!=null) {
       
   164                 var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
       
   165                 var nickp = Markup.escape_text(prev).replace(" ","&nbsp;"); 
       
   166                 room.write(Time.local(time_t()), "nickchange", "*", nickp+" is now known as "+nick);
   144             }
   167             }
   145         });
   168         });
   146     }
   169     }
   147     public override string name() {
   170     public override string name() {
   148         return "muc_log";
   171         return "muc_log";