Move the irc_amqp_listener to be underneath the irc_object_sup
authorMatt Mullins <mmullins@mmlx.us>
Thu, 1 Sep 2011 01:26:42 +0000 (20:26 -0500)
committerMatt Mullins <mmullins@mmlx.us>
Thu, 1 Sep 2011 01:26:42 +0000 (20:26 -0500)
irc/irc_conn.erl

index db68f7d..f7dc563 100644 (file)
@@ -98,7 +98,7 @@ do_line(Line, State) ->
             % end of MOTD, which should normally be sent on connect
             error_logger:info_msg("Joining my channels now.", []),
             {_, _, _, _, Channels} = State#irc_state.config,
-            lists:foreach(fun join_channel/1, Channels),
+            lists:foreach(fun(Channel) -> join_channel(Channel, State) end, Channels),
             State#irc_state{joined = true};
         "PRIVMSG" ->
             do_privmsg(Command),
@@ -130,10 +130,11 @@ code_change(_OldVsn, State, _Extra) ->
 send_command(Command) ->
     gen_server:cast(self(), {send_command, Command}).
 
-join_channel(Channel) ->
+join_channel(Channel, State) ->
     Command = #irc_command{command = "JOIN", middles = [Channel]},
     send_command(Command),
-    irc_amqp_listener:start_link(self(), Channel, "foobar"). %% TODO: fix routing key
+    #irc_state{ object_sup = ObjectSup } = State,
+    {ok, _ChildPid} = irc_object_sup:add_amqp_listener(ObjectSup, self(), Channel).
 
 %% @doc Splits a buffer into full lines, keeping whatever is left over
 %% Returns either {ok, [Line], Remaining} or none.