use global state for Outbox "Bcc"

This commit is contained in:
tali 2024-01-10 23:41:01 -05:00
parent f47a383fa1
commit 1f81abfad2
2 changed files with 18 additions and 26 deletions

View File

@ -14,25 +14,19 @@ 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 -> ()
type bcc = { recipients : t Dllist.t }
module Bcc = struct
let _recipients = Dllist.create ()
let make_bcc () = {
recipients = Dllist.create ();
}
let incl obx =
Option.iter Dllist.remove obx.bcc;
obx.bcc <- Some (Dllist.add_r obx _recipients)
let excl obx =
Option.iter Dllist.remove obx.bcc;
obx.bcc <- None
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 ->
()
let rec send_all msg =
match Dllist.take_l _recipients with
| obx -> obx.bcc <- None; send obx msg; send_all msg
| exception Dllist.Empty -> ()
end

View File

@ -50,19 +50,17 @@ let relay ~(from : user) (msg : Irc.Msg.t) target =
| `to_user dst ->
Outbox.send dst.outbox msg
| `to_chan dst ->
let bcc = Outbox.make_bcc () in
Dllist.iter_l (fun m -> Outbox.incl bcc m.mem_user.outbox) dst.members;
Outbox.excl from.outbox;
Outbox.send_all bcc msg
Dllist.iter_l (fun m -> Outbox.Bcc.incl m.mem_user.outbox) dst.members;
Outbox.Bcc.excl from.outbox;
Outbox.Bcc.send_all msg
| `to_interested user ->
let bcc = Outbox.make_bcc () in
Dllist.iter_l
(fun m ->
Dllist.iter_l
(fun m -> Outbox.incl bcc m.mem_user.outbox)
(fun m -> Outbox.Bcc.incl m.mem_user.outbox)
m.mem_chan.members)
user.membership;
Outbox.send_all bcc msg
Outbox.Bcc.send_all msg
module User = struct
type t = user