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