use ptime for displaying channel/server creation time

This commit is contained in:
tali 2024-01-31 16:47:42 -05:00
parent 45e9fac30a
commit 6fdd47cd12
7 changed files with 22 additions and 11 deletions

View File

@ -3,10 +3,15 @@ include Router_types
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_key = string_ci name;
creation_time;
topic = None;
members = Dllist.create ();
member_count = 0;
@ -16,6 +21,7 @@ let make ~name =
}
let name t = t.name
let creation_time t = t.creation_time
let topic t = t.topic
let set_topic t s = t.topic <- s
let mode t = t.chan_mode

View File

@ -210,7 +210,7 @@ let on_get_chan_mode chan me =
| None -> []
end;
(* TODO: RPL_CREATIONTIME (329) *)
["329", [Chan.name chan; Fmt.str "%a" pp_unixtime (Chan.creation_time chan)]];
] in
Ok (List.flatten rpls)
@ -447,7 +447,7 @@ let on_msg_join t name =
Error (nosuchchannel name)
with Not_found ->
debug (fun m -> m "making new channel %S" name);
Ok (Chan.make ~name)
Ok (Chan.make name)
in
match Router.membership chan me with
| _already_a_member -> Ok ()

View File

@ -2,7 +2,7 @@
(package talircd)
(name server)
(libraries
lwt lwt.unix fmt
lwt lwt.unix fmt ptime ptime.clock.os
logging irc data)
(inline_tests)
(preprocess (pps ppx_expect)))

View File

@ -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_UNIX path -> Fmt.string ppf path
let defer f =
Lwt.on_success (Lwt.pause ()) f
let pp_unixtime ppf t =
let dt = Ptime.diff t Ptime.epoch in
Fmt.pf ppf "%.0f" (Ptime.Span.to_float_s dt)
module Result_syntax = struct
let ( let* ) = Result.bind

View File

@ -16,6 +16,7 @@ type user = {
and chan = {
name : name;
name_key : string_ci;
creation_time : Ptime.t;
mutable topic : string option;
mutable members : membership Dllist.t;
mutable member_count : int;
@ -23,7 +24,6 @@ and chan = {
mutable chan_limit : int option; (* +l *)
mutable chan_key : string option; (* +k *)
(* TODO: +b *)
(* TODO: creation time *)
}
and membership = {

View File

@ -39,8 +39,12 @@ let make ~hostname = {
(* TODO: generate version string at build time? *)
"0.0.0";
created =
(* TODO: stringify timestamp *)
"Sun Jan 7 09:58:24 PM EST 2024";
begin
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;
admin_info =
(* TODO: make configurable *)

View File

@ -31,8 +31,8 @@ let%expect_test _ =
~outbox:(Outbox.make ())
in
let c1 = Chan.make ~name:"#wire-fraud" in
let c2 = Chan.make ~name:"#spiderman" in
let c1 = Chan.make "#wire-fraud" in
let c2 = Chan.make "#spiderman" in
User.register u1 ~router;
User.register u2 ~router;