2024-01-21 20:04:08 +00:00
|
|
|
open! Import
|
|
|
|
include Router_types
|
|
|
|
|
|
|
|
type t = chan
|
|
|
|
|
|
|
|
let make ~name =
|
|
|
|
{
|
|
|
|
name;
|
|
|
|
name_key = string_ci name;
|
|
|
|
topic = None;
|
|
|
|
members = Dllist.create ();
|
2024-01-30 22:32:00 +00:00
|
|
|
member_count = 0;
|
2024-01-23 19:23:45 +00:00
|
|
|
chan_mode = Mode.Set.empty;
|
2024-01-21 20:04:08 +00:00
|
|
|
chan_limit = None;
|
|
|
|
chan_key = None;
|
|
|
|
}
|
|
|
|
|
|
|
|
let name t = t.name
|
|
|
|
let topic t = t.topic
|
2024-01-24 17:38:20 +00:00
|
|
|
let set_topic t s = t.topic <- s
|
2024-01-21 20:04:08 +00:00
|
|
|
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
|
|
|
|
|
2024-01-23 18:13:41 +00:00
|
|
|
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 []
|
2024-01-21 20:04:08 +00:00
|
|
|
|
2024-01-24 18:17:59 +00:00
|
|
|
let membership t =
|
|
|
|
Dllist.fold_r (fun m xs -> m :: xs) t.members []
|
|
|
|
|
2024-01-27 20:34:30 +00:00
|
|
|
let membership_when f t =
|
|
|
|
Dllist.fold_r (fun m xs -> if f m then m :: xs else xs) t.members []
|
|
|
|
|
2024-01-30 22:32:00 +00:00
|
|
|
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
|