refactor quit

This commit is contained in:
tali 2024-01-23 13:31:06 -05:00
parent d6385ab852
commit 4fca26cc8a
1 changed files with 12 additions and 16 deletions

View File

@ -370,26 +370,22 @@ let on_msg_motd t =
motd t; motd t;
Ok () Ok ()
let quit t reason = let quit t me ~reason =
begin begin
Option.iter let msg = Irc.Msg.make "QUIT" [User.nick me; reason] ~always_trailing:true in
(fun user -> Router.relay msg ~from:me [`to_interested];
let msg = Irc.Msg.make "QUIT" [User.nick user; reason] ~always_trailing:true in
Router.relay msg ~from:user [`to_interested];
List.iter List.iter
(part user ~router:t.router ~reason:None) (part me ~router:t.router ~reason:None)
(User.channels user); (User.channels me);
User.unregister user ~router:t.router; User.unregister me ~router:t.router;
t.user <- None) t.user <- None
t.user;
Outbox.close t.outbox;
end end
let close t = let close ?(reason = "Client closed") t =
quit t "Client closed" Option.iter (quit t ~reason) t.user;
Outbox.close t.outbox
let on_msg_quit t reason = let on_msg_quit t reason =
(* TODO: '''When connections are terminated by a client-sent QUIT command, servers (* TODO: '''When connections are terminated by a client-sent QUIT command, servers
@ -399,7 +395,7 @@ let on_msg_quit t reason =
| [] -> "Quit" | [] -> "Quit"
| xs -> String.concat " " ("Quit:" :: xs) | xs -> String.concat " " ("Quit:" :: xs)
in in
quit t reason; close t ~reason;
Ok () Ok ()