Skip to content

Commit

Permalink
Implement LIST.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlouis committed Jul 9, 2012
1 parent a490224 commit e44eabd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/pony_chan_srv.erl
Expand Up @@ -17,6 +17,7 @@
]).

-export([channel_members/1,
list_channels/0,
set_topic/3,
topic/1,
part_channel/1,
Expand All @@ -32,8 +33,8 @@
-define(SERVER, ?MODULE).

-record(channel,
{ name,
topic }).
{ name :: binary(),
topic :: binary() | undefined }).

-record(state, {}).

Expand All @@ -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}}).

Expand Down
10 changes: 10 additions & 0 deletions src/pony_client.erl
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions src/pony_protocol.erl
Expand Up @@ -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
Expand Down

0 comments on commit e44eabd

Please sign in to comment.