Messages = new Meteor.Collection('messages')
irc = Meteor.require 'irc'
clients = {}
Meteor.publish 'channel', (channel, nick) ->
    if channel && nick
        listen channel, nick
        Messages.find(channel : channel)
listen = (channel, nick) ->
    console.log(channel, nick)
    client = clients[nick] = new irc.Client 'chat.freenode.net', nick, {
        channels : [channel]
    }
    client.on 'error', console.log
    client.on 'message', (from, to, message) ->
        console.log(from, to, message)
        Fiber(->
            Messages.insert {
                from,
                message
                channel : to,
            }
        )

Messages = new Meteor.Collection('messages')
irc = Meteor.require 'irc'
clients = {}
Meteor.publish 'channel', (channel, nick) ->
    if channel && nick
        listen channel, nick
        Messages.find(channel : channel)
listen = (channel, nick) ->
    console.log(channel, nick)
    client = clients[nick] = new irc.Client 'chat.freenode.net', nick, {
        port : 6665
        channels : [channel]
    }
    client.on 'error', console.log.bind(console, 'osdf')
    client.on 'message', Meteor.bindEnvironment (from, to, message) ->
        console.log(from, to, message)
        Messages.insert {
            from,
            message
            channel : to,
        }
    console.log(channel, nick, 'fuck')

Fix writing messages to database
Fix writing messages to database
