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 send t msg = try t.push (Some msg) with Lwt_stream.Closed -> ()
let close t = try t.push None 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 () = { let incl obx =
recipients = Dllist.create (); Option.iter Dllist.remove obx.bcc;
} obx.bcc <- Some (Dllist.add_r obx _recipients)
let excl obx = let excl obx =
Option.iter Dllist.remove obx.bcc; Option.iter Dllist.remove obx.bcc;
obx.bcc <- None obx.bcc <- None
let incl bcc obx = let rec send_all msg =
Option.iter Dllist.remove obx.bcc; match Dllist.take_l _recipients with
obx.bcc <- Some (Dllist.add_r obx bcc.recipients) | obx -> obx.bcc <- None; send obx msg; send_all msg
| exception Dllist.Empty -> ()
let rec send_all bcc msg = end
match Dllist.take_l bcc.recipients with
| obx ->
obx.bcc <- None;
send obx msg;
send_all bcc msg
| exception Dllist.Empty ->
()

View File

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