muc_log.vala
author Stiletto <blasux@blasux.ru>
Wed, 24 Oct 2012 14:08:16 +0400
changeset 9 d3260253f0bd
parent 8 dfd274c668f9
child 12 d3e36b368fc5
permissions -rw-r--r--
Moved nick colors to vala code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     1
using Gee;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     2
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     3
class ModuleMucLog : Module {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     4
    protected weak ModuleMuc muc;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     5
    protected HashMap<string,RoomLog> rooms;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     6
    class RoomLog : Object {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     7
        public string jid;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     8
        public string logpath;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     9
        public string filename;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    10
        protected weak ModuleMucLog muclog;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    11
        protected FileStream file;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    12
        public string getid(Time time) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    13
            return time.format("%s");
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    14
        }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    15
        protected int lastday;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    16
        protected int lastyear;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    17
        protected int lastmonth;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    18
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    19
        public RoomLog(ModuleMucLog muclog, string jid) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    20
            this.jid = jid;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    21
            this.muclog = muclog;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    22
            logpath = muclog.getconf(jid, "log-path", null);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    23
            filename = null;
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    24
            write(Time.local(time_t()), "logstart", "", "Log started");
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    25
        }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    26
        ~RoomLog() {
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    27
            write(Time.local(time_t()), "logstop", "", "Log stopped");
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    28
        }
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    29
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    30
        public static uint nick_hash(string s) {
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    31
            uint sum = 0;
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    32
            const uint k = 102, m = 54, l = 140;
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    33
            for( var j = 0, iTop = s.length; j < iTop; j++ ) {
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    34
                sum += k ^ s[j];
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    35
            }
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    36
            return ((sum ^ m)+l)%10;
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    37
        }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    38
        public void write(Time time, string _class, string nick, string str) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    39
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    40
            if ((lastday != time.day)||(lastmonth != time.month)||(lastyear!=time.year)) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    41
                var fname = time.format(logpath).replace("<muc>",jid);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    42
                log("muc_log", LogLevelFlags.LEVEL_INFO, "Switching log file '%s' to '%s'", filename, fname);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    43
                if (file!=null) file.flush();
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    44
                //try {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    45
                    file = FileStream.open(fname,"a");
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    46
                if (file==null) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    47
                    int start = 0;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    48
                    int length = fname.length;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    49
                    while (true) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    50
                        var pos = fname.index_of("/", start);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    51
                        if (pos==-1)
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    52
                            break;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    53
                        stderr.printf("--------------------- %s\n", fname[0:pos]);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    54
                        Posix.mkdir(fname[0:pos],0777);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    55
                        start = pos+1;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    56
                    } 
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    57
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    58
                    file = FileStream.open(fname,"a");
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    59
                    if (file == null) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    60
                        log("muc_log", LogLevelFlags.LEVEL_WARNING, "Failed to create log file '%s'", fname);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    61
                        return;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    62
                    }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    63
                }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    64
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    65
                if (file.tell()==0) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    66
                    var loghead = muclog.getconf(jid, "log-head",null);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    67
                    if (loghead!="null") {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    68
                        try {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    69
                            var headfile = new IOChannel.file(loghead,"r");
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    70
                            string head;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    71
                            size_t length;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    72
                            headfile.read_to_end(out head, out length);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    73
                            headfile.shutdown(false);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    74
                            file.printf("%s\n", head.replace("<muc>",jid).replace("<date>",time.format("%d.%m.%Y")));
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    75
                        } catch (FileError fe) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    76
                            log("muc_log", LogLevelFlags.LEVEL_WARNING, "Failed to read head");
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    77
                        }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    78
                    }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    79
                }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    80
                filename = fname;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    81
                lastyear = time.year; lastmonth = time.month; lastday = time.day;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    82
            }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    83
            
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    84
            var id = getid(time);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    85
            var times = time.format("%H:%M:%S");
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    86
            var nicklass = (_class=="message") ? (" nick%u".printf(nick_hash(nick))) : "";
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    87
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    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);
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    89
            file.printf("<td class='nick%s'>%s</td><td class='text'>%s</td></tr>\n", nicklass, nick, str);
4
8785de25b6bd Added flush()
Stiletto <blasux@blasux.ru>
parents: 3
diff changeset
    90
            file.flush();
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    91
        }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    92
            
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    93
    }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    94
    public string getconf(string jid, string key, string? def) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    95
        var res = cfg["muc "+jid, key];
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    96
        if (res==null) res = cfg["muc", key];
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    97
        if (res==null) res = def;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    98
        return res;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    99
    }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   100
    public ModuleMucLog(Config cfg, Connection conn) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   101
        base(cfg, conn);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   102
        rooms = new HashMap<string,RoomLog>();
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   103
        muc = null;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   104
        foreach (var module in conn.modules) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   105
            if (module.name()=="muc")
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   106
                muc = (ModuleMuc)module;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   107
        }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   108
        if (muc==null)
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   109
            log("muc_log", LogLevelFlags.LEVEL_ERROR, "Module 'muc' is not loaded");
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   110
        muc.state_changed.connect( (conf, olds, news, desc) => {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   111
            switch (news) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   112
                case ModuleMuc.State.CONNECTED:
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   113
                    if (getconf(conf.jid, "log", "no")=="yes") {
8
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   114
                        var room = new RoomLog(this, conf.jid); 
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   115
                        rooms[conf.jid] = room;
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   116
                        var sb = new StringBuilder();
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   117
                        var notfirst = false;
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   118
                        sb.append("Participants: ");
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   119
                        foreach (var occupant in conf.occupants.values) {
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   120
                            if (notfirst)
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   121
                                sb.append(", ");
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   122
                            else
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   123
                                notfirst=true;
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   124
                            sb.append(Markup.escape_text(occupant.nick).replace(" ","&nbsp;"));
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   125
                        }
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   126
                        room.write(Time.local(time_t()), "userlist", "", sb.str);
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   127
                    }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   128
                    break;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   129
                case ModuleMuc.State.DISCONNECTED:
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   130
                    rooms.unset(conf.jid);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   131
                    break;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   132
            }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   133
        });
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   134
        muc.on_message.connect( (conf, user, message, body) => {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   135
            if ((user!=null)&&(body!=null)&&(message.get_child("delay")==null)) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   136
                var room = rooms[conf.jid];
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   137
                if (room!=null) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   138
                    var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   139
                    if (body.has_prefix("/me ")) {
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   140
                        room.write(Time.local(time_t()), "action", "*", nick+Markup.escape_text(body[3:body.length]).replace("\n","<br/>"));
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   141
                    } else
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   142
                        room.write(Time.local(time_t()), "message", nick, Markup.escape_text(body).replace("\n","<br/>"));
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   143
                }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   144
            }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   145
        });
8
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   146
        muc.on_join.connect( (conf, user) => {
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   147
            var room = rooms[conf.jid];
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   148
            if (room!=null) {
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   149
                var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   150
                room.write(Time.local(time_t()), "join", "*", nick+" has joined the room");
8
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   151
            }
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   152
        });
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   153
        muc.on_part.connect( (conf, user, status) => {
8
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   154
            var room = rooms[conf.jid];
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   155
            if (room!=null) {
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   156
                var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   157
                room.write(Time.local(time_t()), "part", "*",
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   158
                    nick+" has left the room"+((status!=null) ? (": "+Markup.escape_text(status)) : ""));
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   159
            }
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   160
        });
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   161
        muc.on_nick.connect( (conf, user, prev) => {
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   162
            var room = rooms[conf.jid];
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   163
            if (room!=null) {
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   164
                var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   165
                var nickp = Markup.escape_text(prev).replace(" ","&nbsp;"); 
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   166
                room.write(Time.local(time_t()), "nickchange", "*", nickp+" is now known as "+nick);
8
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   167
            }
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   168
        });
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   169
    }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   170
    public override string name() {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   171
        return "muc_log";
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   172
    }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   173
}