From dcee567e1d2d98173df6ec022ec1ed5f66c92b9d Mon Sep 17 00:00:00 2001 From: Jeff Weiss Date: Wed, 30 Mar 2016 23:16:33 -0700 Subject: handle QUIT messages Prior to this commit ExIrc did not know what to do with QUIT messages, which would result in nicks remaining in the `Channels` data structure when they should not. This commit implements handling of the QUIT message and ensures that the new `Channels.user_quit` function is called to flush the departing user from all known channels. Close #40 --- lib/exirc/channels.ex | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/exirc/channels.ex') diff --git a/lib/exirc/channels.ex b/lib/exirc/channels.ex index b7a6d4c..b108de9 100644 --- a/lib/exirc/channels.ex +++ b/lib/exirc/channels.ex @@ -118,6 +118,16 @@ defmodule ExIrc.Channels do users_manip(channel_tree, channel_name, manipfn) end + def user_quit(channel_tree, nick) do + pnick = strip_rank([nick]) + manipfn = fn(channel_nicks) -> :lists.usort(channel_nicks -- pnick) end + foldl = fn(channel_name, new_channel_tree) -> + name = downcase(channel_name) + users_manip(new_channel_tree, name, manipfn) + end + :lists.foldl(foldl, channel_tree, channels(channel_tree)) + end + @doc """ Update the nick of a user in a tracked channel when they change their nick """ -- cgit v1.2.3