2024-01-10 00:35:03 +00:00
|
|
|
open! Import
|
|
|
|
|
|
|
|
type t = {
|
|
|
|
stream : Irc.Msg.t Lwt_stream.t;
|
|
|
|
push : Irc.Msg.t option -> unit;
|
2024-01-10 02:19:22 +00:00
|
|
|
mutable bcc : t Dllist.node option;
|
2024-01-10 00:35:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let make () =
|
|
|
|
let stream, push = Lwt_stream.create () in
|
2024-01-10 02:19:22 +00:00
|
|
|
{ stream; push; bcc = None }
|
2024-01-10 00:35:03 +00:00
|
|
|
|
|
|
|
let stream t = t.stream
|
|
|
|
let send t msg = try t.push (Some msg) with Lwt_stream.Closed -> ()
|
|
|
|
let close t = try t.push None with Lwt_stream.Closed -> ()
|
2024-01-10 02:19:22 +00:00
|
|
|
|
|
|
|
type bcc = { recipients : t Dllist.t }
|
|
|
|
|
|
|
|
let make_bcc () = {
|
|
|
|
recipients = Dllist.create ();
|
|
|
|
}
|
|
|
|
|
|
|
|
let excl obx =
|
|
|
|
Option.iter Dllist.remove obx.bcc;
|
|
|
|
obx.bcc <- None
|
|
|
|
|
|
|
|
let incl bcc obx =
|
|
|
|
Option.iter Dllist.remove obx.bcc;
|
|
|
|
obx.bcc <- Some (Dllist.add_r obx bcc.recipients)
|
|
|
|
|
|
|
|
let rec send_all bcc msg =
|
|
|
|
match Dllist.take_l bcc.recipients with
|
|
|
|
| obx ->
|
|
|
|
obx.bcc <- None;
|
|
|
|
send obx msg;
|
|
|
|
send_all bcc msg
|
|
|
|
| exception Dllist.Empty ->
|
|
|
|
()
|