open! Import include Router_types type t = chan let make ~name = { name; name_key = string_ci name; topic = None; members = Dllist.create (); member_count = 0; chan_mode = Mode.Set.empty; chan_limit = None; chan_key = None; } let name t = t.name let topic t = t.topic let set_topic t s = t.topic <- s let mode t = t.chan_mode let set_mode t new_mode = t.chan_mode <- new_mode let limit t = t.chan_limit let set_limit t n = t.chan_limit <- n let key t = t.chan_key let set_key t k = t.chan_key <- k let register t ~router = Hashtbl.replace router.channels t.name_key t let unregister t ~router = Hashtbl.remove router.channels t.name_key let is_registered t ~router = Hashtbl.mem router.channels t.name_key let members t = Dllist.fold_r (fun m xs -> m.mem_user :: xs) t.members [] let membership t = Dllist.fold_r (fun m xs -> m :: xs) t.members [] let membership_when f t = Dllist.fold_r (fun m xs -> if f m then m :: xs else xs) t.members [] let is_empty t = t.member_count = 0 let is_full t = match t.chan_limit with | Some n -> t.member_count >= n | None -> false