muc_log.vala
changeset 8 dfd274c668f9
parent 4 8785de25b6bd
child 9 d3260253f0bd
equal deleted inserted replaced
7:a49fb1ec5e2a 8:dfd274c668f9
    98             log("muc_log", LogLevelFlags.LEVEL_ERROR, "Module 'muc' is not loaded");
    98             log("muc_log", LogLevelFlags.LEVEL_ERROR, "Module 'muc' is not loaded");
    99         muc.state_changed.connect( (conf, olds, news, desc) => {
    99         muc.state_changed.connect( (conf, olds, news, desc) => {
   100             switch (news) {
   100             switch (news) {
   101                 case ModuleMuc.State.CONNECTED:
   101                 case ModuleMuc.State.CONNECTED:
   102                     if (getconf(conf.jid, "log", "no")=="yes") {
   102                     if (getconf(conf.jid, "log", "no")=="yes") {
   103                         rooms[conf.jid] = new RoomLog(this, conf.jid);
   103                         var room = new RoomLog(this, conf.jid); 
       
   104                         rooms[conf.jid] = room;
       
   105                         var sb = new StringBuilder();
       
   106                         var notfirst = false;
       
   107                         sb.append("Participants: ");
       
   108                         foreach (var occupant in conf.occupants.values) {
       
   109                             if (notfirst)
       
   110                                 sb.append(", ");
       
   111                             else
       
   112                                 notfirst=true;
       
   113                             sb.append(Markup.escape_text(occupant.nick).replace(" "," "));
       
   114                         }
       
   115                         room.write(Time.local(new time_t()), "userlist", "", sb.str);
   104                     }
   116                     }
   105                     break;
   117                     break;
   106                 case ModuleMuc.State.DISCONNECTED:
   118                 case ModuleMuc.State.DISCONNECTED:
   107                     rooms.unset(conf.jid);
   119                     rooms.unset(conf.jid);
   108                     break;
   120                     break;
   115                     var nick = Markup.escape_text(user.nick).replace(" "," ");
   127                     var nick = Markup.escape_text(user.nick).replace(" "," ");
   116                     room.write(Time.local(new time_t()), "message", nick, Markup.escape_text(body).replace("\n","<br/>"));
   128                     room.write(Time.local(new time_t()), "message", nick, Markup.escape_text(body).replace("\n","<br/>"));
   117                 }
   129                 }
   118             }
   130             }
   119         });
   131         });
       
   132         muc.on_join.connect( (conf, user) => {
       
   133             var room = rooms[conf.jid];
       
   134             if (room!=null) {
       
   135                 var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
       
   136                 room.write(Time.local(new time_t()), "join", "*", nick+" has joined the room");
       
   137             }
       
   138         });
       
   139         muc.on_part.connect( (conf, user) => {
       
   140             var room = rooms[conf.jid];
       
   141             if (room!=null) {
       
   142                 var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
       
   143                 room.write(Time.local(new time_t()), "part", "*", nick+" has left the room");
       
   144             }
       
   145         });
   120     }
   146     }
   121     public override string name() {
   147     public override string name() {
   122         return "muc_log";
   148         return "muc_log";
   123     }
   149     }
   124 }
   150 }