use ptime for displaying channel/server creation time
This commit is contained in:
parent
45e9fac30a
commit
6fdd47cd12
|
@ -3,10 +3,15 @@ include Router_types
|
||||||
|
|
||||||
type t = chan
|
type t = chan
|
||||||
|
|
||||||
let make ~name =
|
let make ?creation_time name =
|
||||||
|
let creation_time = match creation_time with
|
||||||
|
| None -> Ptime_clock.now ()
|
||||||
|
| Some ts -> ts
|
||||||
|
in
|
||||||
{
|
{
|
||||||
name;
|
name;
|
||||||
name_key = string_ci name;
|
name_key = string_ci name;
|
||||||
|
creation_time;
|
||||||
topic = None;
|
topic = None;
|
||||||
members = Dllist.create ();
|
members = Dllist.create ();
|
||||||
member_count = 0;
|
member_count = 0;
|
||||||
|
@ -16,6 +21,7 @@ let make ~name =
|
||||||
}
|
}
|
||||||
|
|
||||||
let name t = t.name
|
let name t = t.name
|
||||||
|
let creation_time t = t.creation_time
|
||||||
let topic t = t.topic
|
let topic t = t.topic
|
||||||
let set_topic t s = t.topic <- s
|
let set_topic t s = t.topic <- s
|
||||||
let mode t = t.chan_mode
|
let mode t = t.chan_mode
|
||||||
|
|
|
@ -210,7 +210,7 @@ let on_get_chan_mode chan me =
|
||||||
| None -> []
|
| None -> []
|
||||||
end;
|
end;
|
||||||
|
|
||||||
(* TODO: RPL_CREATIONTIME (329) *)
|
["329", [Chan.name chan; Fmt.str "%a" pp_unixtime (Chan.creation_time chan)]];
|
||||||
] in
|
] in
|
||||||
Ok (List.flatten rpls)
|
Ok (List.flatten rpls)
|
||||||
|
|
||||||
|
@ -447,7 +447,7 @@ let on_msg_join t name =
|
||||||
Error (nosuchchannel name)
|
Error (nosuchchannel name)
|
||||||
with Not_found ->
|
with Not_found ->
|
||||||
debug (fun m -> m "making new channel %S" name);
|
debug (fun m -> m "making new channel %S" name);
|
||||||
Ok (Chan.make ~name)
|
Ok (Chan.make name)
|
||||||
in
|
in
|
||||||
match Router.membership chan me with
|
match Router.membership chan me with
|
||||||
| _already_a_member -> Ok ()
|
| _already_a_member -> Ok ()
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
(package talircd)
|
(package talircd)
|
||||||
(name server)
|
(name server)
|
||||||
(libraries
|
(libraries
|
||||||
lwt lwt.unix fmt
|
lwt lwt.unix fmt ptime ptime.clock.os
|
||||||
logging irc data)
|
logging irc data)
|
||||||
(inline_tests)
|
(inline_tests)
|
||||||
(preprocess (pps ppx_expect)))
|
(preprocess (pps ppx_expect)))
|
||||||
|
|
|
@ -8,8 +8,9 @@ let pp_sockaddr ppf = function
|
||||||
| Unix.ADDR_INET (adr, port) -> Fmt.pf ppf "%s:%d" (Unix.string_of_inet_addr adr) port
|
| Unix.ADDR_INET (adr, port) -> Fmt.pf ppf "%s:%d" (Unix.string_of_inet_addr adr) port
|
||||||
| Unix.ADDR_UNIX path -> Fmt.string ppf path
|
| Unix.ADDR_UNIX path -> Fmt.string ppf path
|
||||||
|
|
||||||
let defer f =
|
let pp_unixtime ppf t =
|
||||||
Lwt.on_success (Lwt.pause ()) f
|
let dt = Ptime.diff t Ptime.epoch in
|
||||||
|
Fmt.pf ppf "%.0f" (Ptime.Span.to_float_s dt)
|
||||||
|
|
||||||
module Result_syntax = struct
|
module Result_syntax = struct
|
||||||
let ( let* ) = Result.bind
|
let ( let* ) = Result.bind
|
||||||
|
|
|
@ -16,6 +16,7 @@ type user = {
|
||||||
and chan = {
|
and chan = {
|
||||||
name : name;
|
name : name;
|
||||||
name_key : string_ci;
|
name_key : string_ci;
|
||||||
|
creation_time : Ptime.t;
|
||||||
mutable topic : string option;
|
mutable topic : string option;
|
||||||
mutable members : membership Dllist.t;
|
mutable members : membership Dllist.t;
|
||||||
mutable member_count : int;
|
mutable member_count : int;
|
||||||
|
@ -23,7 +24,6 @@ and chan = {
|
||||||
mutable chan_limit : int option; (* +l *)
|
mutable chan_limit : int option; (* +l *)
|
||||||
mutable chan_key : string option; (* +k *)
|
mutable chan_key : string option; (* +k *)
|
||||||
(* TODO: +b *)
|
(* TODO: +b *)
|
||||||
(* TODO: creation time *)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
and membership = {
|
and membership = {
|
||||||
|
|
|
@ -39,8 +39,12 @@ let make ~hostname = {
|
||||||
(* TODO: generate version string at build time? *)
|
(* TODO: generate version string at build time? *)
|
||||||
"0.0.0";
|
"0.0.0";
|
||||||
created =
|
created =
|
||||||
(* TODO: stringify timestamp *)
|
begin
|
||||||
"Sun Jan 7 09:58:24 PM EST 2024";
|
let ts = Ptime_clock.now () in
|
||||||
|
let tz_offset_s = Ptime_clock.current_tz_offset_s () in
|
||||||
|
let pp = Ptime.pp_human () ?tz_offset_s in
|
||||||
|
Fmt.str "%a" pp ts
|
||||||
|
end;
|
||||||
hostname;
|
hostname;
|
||||||
admin_info =
|
admin_info =
|
||||||
(* TODO: make configurable *)
|
(* TODO: make configurable *)
|
||||||
|
|
|
@ -31,8 +31,8 @@ let%expect_test _ =
|
||||||
~outbox:(Outbox.make ())
|
~outbox:(Outbox.make ())
|
||||||
in
|
in
|
||||||
|
|
||||||
let c1 = Chan.make ~name:"#wire-fraud" in
|
let c1 = Chan.make "#wire-fraud" in
|
||||||
let c2 = Chan.make ~name:"#spiderman" in
|
let c2 = Chan.make "#spiderman" in
|
||||||
|
|
||||||
User.register u1 ~router;
|
User.register u1 ~router;
|
||||||
User.register u2 ~router;
|
User.register u2 ~router;
|
||||||
|
|
Loading…
Reference in New Issue