From 1f81abfad23856ed1de9c465c1a3d36987a72b9f Mon Sep 17 00:00:00 2001 From: tali Date: Wed, 10 Jan 2024 23:41:01 -0500 Subject: [PATCH] use global state for Outbox "Bcc" --- lib/server/outbox.ml | 32 +++++++++++++------------------- lib/server/router.ml | 12 +++++------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/lib/server/outbox.ml b/lib/server/outbox.ml index 5b9a40a..ca27782 100644 --- a/lib/server/outbox.ml +++ b/lib/server/outbox.ml @@ -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 diff --git a/lib/server/router.ml b/lib/server/router.ml index 5c1d523..c11decd 100644 --- a/lib/server/router.ml +++ b/lib/server/router.ml @@ -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