Browse files

Implement LIST.

  • Loading branch information...
1 parent a490224 commit e44eabd77954c020d76c6aa1cbde1284f6a6b115 @jlouis jlouis committed Jul 9, 2012
Showing with 26 additions and 2 deletions.
  1. +7 −2 src/pony_chan_srv.erl
  2. +10 −0 src/pony_client.erl
  3. +9 −0 src/pony_protocol.erl
View
9 src/pony_chan_srv.erl
@@ -17,6 +17,7 @@
]).
-export([channel_members/1,
+ list_channels/0,
set_topic/3,
topic/1,
part_channel/1,
@@ -32,8 +33,8 @@
-define(SERVER, ?MODULE).
-record(channel,
- { name,
- topic }).
+ { name :: binary(),
+ topic :: binary() | undefined }).
-record(state, {}).
@@ -58,6 +59,10 @@ quits(Pid, Name) ->
channel_members(Channel) ->
[Pid || {Pid, _} <- gproc:lookup_local_properties({channel, Channel})].
+list_channels() ->
+ Channels = ets:match_object(?CHAN_TAB, '_'),
+ [{N, length(channel_members(N)), T} || #channel { topic = T, name = N} <- Channels].
+
part_channel(Channel) ->
gproc:unreg({p, l, {channel, Channel}}).
View
10 src/pony_client.erl
@@ -216,6 +216,16 @@ handle_message(Prefix, Command, Args, #state { nickname = CurNick } = State) ->
|| Pid <- pony_chan_srv:channel_members(Channel)],
pony_chan_srv:part_channel(Channel),
State;
+ {<<>>, list, [<<>>]} ->
+ send_numeric('RPL_LISTSTART', [CurNick]),
+ Channels = pony_chan_srv:list_channels(),
+ [send_numeric('RPL_LIST', [CurNick, Chan, Count, case Topic of
+ undefined -> "";
+ X -> X
+ end])
+ || {Chan, Count, Topic} <- Channels],
+ send_numeric('RPL_LISTEND', [CurNick]),
+ State;
_ ->
handle_nick_user(Prefix, Command, Args, State)
end.
View
9 src/pony_protocol.erl
@@ -95,6 +95,15 @@ render_numeric('RPL_NOTOPIC', [Nick, Channel]) ->
render_numeric('RPL_TOPIC', [Nick, Chan, Topic]) ->
io_lib:format(":~s 332 ~s ~s :~s",
[pony:me(), Nick, Chan, Topic]);
+render_numeric('RPL_LISTSTART', [Nick]) ->
+ io_lib:format(":~s 321 ~s Channel :Users Topic",
+ [pony:me(), Nick]);
+render_numeric('RPL_LIST', [Nick, Chan, Count, Topic]) ->
+ io_lib:format(":~s 322 ~s ~s ~B :~s",
+ [pony:me(), Nick, Chan, Count, Topic]);
+render_numeric('RPL_LISTEND', [Nick]) ->
+ io_lib:format(":~s 323 ~s :End of /LIST",
+ [pony:me(), Nick]);
render_numeric('RPL_NAMREPLY', [Nick, Chan, Names]) ->
io_lib:format(":~s 353 ~s ~s ~s :~s",
[pony:me(), Nick, "=", %% This is a RatBox thing

0 comments on commit e44eabd

Please sign in to comment.